child window, new icon size set

git-svn-id: svn://kolibrios.org@7274 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-05-07 16:17:53 +00:00
parent 2f45ac2c8a
commit c2149afa96
12 changed files with 215 additions and 73 deletions

View File

@ -1,4 +1,3 @@
// Actions history
#define MAX_ACTIONS_COUNT 15 #define MAX_ACTIONS_COUNT 15
@ -24,8 +23,10 @@ void _ActionsHistory::init() {
head = tail = 0; head = tail = 0;
currentIndex = -1; currentIndex = -1;
for (i = 0; i < MAX_ACTIONS_COUNT; i++) for (i = 0; i < MAX_ACTIONS_COUNT; i++) {
stack[i] = free(stack[i]);
stack[i] = malloc(image.columns * image.rows * 4); stack[i] = malloc(image.columns * image.rows * 4);
}
saveCurrentState(); saveCurrentState();
} }

View File

@ -0,0 +1,96 @@
child_window Window_CanvasReSize = {#CanvasReSize_Thread};
//===================================================//
// //
// CODE //
// //
//===================================================//
char text_columns[4];
char text_rows[4];
edit_box edit_columns = {60,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(text_columns)-1,#text_columns,0, 1000000000000010b};
edit_box edit_rows = {60,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(text_rows)-1,#text_rows,0, 1000000000000000b};
#define BTN_APPLY 10
void CanvasReSize_Thread()
{
int id, butw;
sprintf(#text_columns, "%i", image.columns);
sprintf(#text_rows, "%i", image.rows);
edit_columns.size = edit_columns.pos = edit_columns.shift = edit_columns.shift_old = strlen(#text_columns);
edit_rows.size = edit_rows.pos = edit_rows.shift = edit_rows.shift_old = strlen(#text_rows);
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
loop() switch(WaitEvent())
{
case evMouse:
edit_box_mouse stdcall (#edit_columns);
edit_box_mouse stdcall (#edit_rows);
break;
case evKey:
GetKeys();
if (SCAN_CODE_ESC == key_scancode) ExitProcess();
if (SCAN_CODE_ENTER == key_scancode) EventApplyClick();
if (SCAN_CODE_TAB == key_scancode) EventTabClick();
EAX= key_ascii << 8;
edit_box_key stdcall (#edit_columns);
edit_box_key stdcall (#edit_rows);
break;
case evButton:
id = GetButtonID();
if (CLOSE_BTN == id) ExitProcess();
if (BTN_APPLY == id) EventApplyClick();
break;
case evReDraw:
DefineAndDrawWindow(Form.left+canvas.x + 100, Form.top+skin_height+canvas.y+40,
200, 170, 0x34, system.color.work, "Canvas", 0);
WriteText(20, 20, 0x90, system.color.work_text, "Width");
WriteText(20, 60, 0x90, system.color.work_text, "Height");
DrawStandartCaptButton(20, 100, BTN_APPLY, "OK");
DrawEditBoxes();
}
}
void DrawEditBoxes()
{
DrawEditBoxPos(20+70, 20-4, #edit_columns);
DrawEditBoxPos(20+70, 60-4, #edit_rows);
}
//===================================================//
// //
// EVENTS //
// //
//===================================================//
void EventApplyClick()
{
int new_rows = atoi(#text_rows);
int new_columns = atoi(#text_columns);
if (new_columns>MAX_CELL_SIZE) || (new_rows>MAX_CELL_SIZE) {
notify("'Maximum icon size exceeded!\nPlease, try something less or equal to 256x256.' -E");
return;
}
image.create(new_rows, new_columns);
actionsHistory.init();
ActivateWindow(GetProcessSlot(Form.ID));
ExitProcess();
}
void EventTabClick()
{
if (edit_columns.flags & 0b10) { edit_columns.flags -= 0b10; edit_rows.flags += 0b10; }
else { edit_columns.flags += 0b10; edit_rows.flags -= 0b10; }
DrawEditBoxes();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 326 B

View File

@ -32,7 +32,7 @@ pipet aside color view
// // // //
//===================================================// //===================================================//
#define T_TITLE "Icon Editor 0.54.2 Alpha" #define T_TITLE "Icon Editor 0.55 Alpha"
#define TOPBAR_H 24+8 #define TOPBAR_H 24+8
#define LEFTBAR_W 16+5+5+3+3 #define LEFTBAR_W 16+5+5+3+3
@ -86,6 +86,7 @@ enum {
BTN_SCREEN_COPY, BTN_SCREEN_COPY,
BTN_ZOOM_IN, BTN_ZOOM_IN,
BTN_ZOOM_OUT, BTN_ZOOM_OUT,
BTN_CANVAS_RESIZE,
BTNS_PALETTE_COLOR_MAS = 100, BTNS_PALETTE_COLOR_MAS = 100,
BTNS_LAST_USED_COLORS = 400 BTNS_LAST_USED_COLORS = 400
}; };
@ -131,6 +132,7 @@ _image image;
_ActionsHistory actionsHistory; _ActionsHistory actionsHistory;
#include "tools.h" #include "tools.h"
#include "canvas_resize.h"
//===================================================// //===================================================//
// // // //
@ -188,6 +190,7 @@ void main()
loop() switch(WaitEvent()) loop() switch(WaitEvent())
{ {
case evMouse: case evMouse:
if (Window_CanvasReSize.thread_exists()) break;
mouse.get(); mouse.get();
if (mouse.lkm) tool_color = color1; if (mouse.lkm) tool_color = color1;
@ -233,6 +236,7 @@ void main()
break; break;
case evButton: case evButton:
if (Window_CanvasReSize.thread_exists()) break;
btn = GetButtonID(); btn = GetButtonID();
if (zoom.click(btn)) DrawEditArea(); if (zoom.click(btn)) DrawEditArea();
@ -240,7 +244,7 @@ void main()
switch(btn) switch(btn)
{ {
case BTN_NEW: case BTN_NEW:
EventCleanCanvas(); EventCreateNewIcon();
break; break;
case BTN_OPEN: case BTN_OPEN:
RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path)); RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
@ -293,6 +297,9 @@ void main()
case BTN_SCREEN_COPY: case BTN_SCREEN_COPY:
setCurrentTool(TOOL_SCREEN_COPY); setCurrentTool(TOOL_SCREEN_COPY);
break; break;
case BTN_CANVAS_RESIZE:
notify("Sorry, not implemented yet.");
break;
case CLOSE_BTN: case CLOSE_BTN:
EventExitIconEdit(); EventExitIconEdit();
break; break;
@ -305,6 +312,8 @@ void main()
if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0) if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0)
tools[currentTool].onKeyEvent(key_scancode); tools[currentTool].onKeyEvent(key_scancode);
if (key_scancode == SCAN_CODE_DEL) EventCleanCanvas();
if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL); if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL);
if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE); if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE);
if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL); if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL);
@ -319,11 +328,12 @@ void main()
if (key_scancode == SCAN_CODE_KEY_Y) actionsHistory.redoLastAction(); if (key_scancode == SCAN_CODE_KEY_Y) actionsHistory.redoLastAction();
if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();} if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();}
if (key_scancode == SCAN_CODE_PLUS) {zoom.inc(); DrawEditArea();} if (key_scancode == SCAN_CODE_PLUS) {zoom.inc(); DrawEditArea();}
break; break;
case evReDraw: case evReDraw:
Window_CanvasReSize.thread_exists();
draw_window(); draw_window();
break; break;
} }
@ -352,8 +362,16 @@ void DrawStatusBar()
{ {
zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6); zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6);
sprintf(#param,"Canvas: %ix%i", image.rows, image.columns); DrawCaptButton(
WriteText(wrapper.x+wrapper.w-calc(strlen(#param)*8), zoom.y+2, 0x90, system.color.work_text, #param); wrapper.x+wrapper.w-calc(strlen(#param)*8) +6 - 1,
zoom.y,
calc(strlen(#param)*8)-6,
18,
BTN_CANVAS_RESIZE,
system.color.work_button,
system.color.work_button_text,
sprintf(#param,"%i x %i", image.rows, image.columns)
);
} }
void draw_window() void draw_window()
@ -391,20 +409,18 @@ void draw_window()
DrawEditArea(); DrawEditArea();
//BG under LeftBar
DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work); DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work);
//BG under RightBar DrawLeftPanel();
DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w, DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w,
Form.cheight - TOPBAR_H, system.color.work); Form.cheight - TOPBAR_H, system.color.work);
//BG under StatusBar
DrawBar(LEFTBAR_W-1, wrapper.y + wrapper.h, wrapper.w+1,
Form.cheight - wrapper.y - wrapper.h, system.color.work);
DrawLeftPanel();
DrawActiveColor(right_bar.y); DrawActiveColor(right_bar.y);
DrawColorPallets(); DrawColorPallets();
DrawStatusBar();
DrawPreview(); DrawPreview();
DrawBar(LEFTBAR_W-1, wrapper.y + wrapper.h, wrapper.w+1,
Form.cheight - wrapper.y - wrapper.h, system.color.work);
DrawStatusBar();
} }
void DrawLeftPanel() void DrawLeftPanel()
@ -608,6 +624,12 @@ void ShowWindow_TestIcon()
// // // //
//===================================================// //===================================================//
void EventCreateNewIcon()
{
EventSaveIconToFile();
Window_CanvasReSize.create();
}
void EventSaveIconToFile() void EventSaveIconToFile()
{ {
int i=0; int i=0;
@ -623,8 +645,8 @@ void EventSaveIconToFile()
void EventCleanCanvas() void EventCleanCanvas()
{ {
EventSaveIconToFile(); image.create(image.rows, image.columns);
image.create(32, 32); actionsHistory.saveCurrentState();
DrawCanvas(); DrawCanvas();
} }

View File

@ -20,6 +20,8 @@
#include "../lib/gui/tabs.h" #include "../lib/gui/tabs.h"
#include "../lib/gui/more_less_box.h" #include "../lib/gui/more_less_box.h"
#include "../lib/gui/checkbox.h" #include "../lib/gui/checkbox.h"
#include "../lib/gui/child_window.h"
#include "../lib/gui/text_view_area.h"
:int last_free_button_id = 1000; :int last_free_button_id = 1000;
:int GetFreeButtonId() :int GetFreeButtonId()
@ -229,62 +231,6 @@
ESBYTE[next_word_pointer] = '\n'; ESBYTE[next_word_pointer] = '\n';
} }
/*
We have a long text and need to show it in block.
Normal line break '\n' must be applied.
Long lines should be breaked by word.
TODO: scroll
*/
:int DrawTextViewArea(int x,y,w,h, dword buf_start, bg_col, text_col)
{
dword write_start;
dword buf_end;
int line_h = 15;
int label_length_max;
int write_length;
bool end_found;
write_start = buf_start;
buf_end = strlen(buf_start) + buf_start;
label_length_max = w / 8; // 8 big font char width
loop()
{
if (bg_col!=-1) DrawBar(x, y, w+1, line_h, bg_col);
end_found = false;
write_length = strchr(write_start, '\n') - write_start; //search normal line break
if (write_length > label_length_max) || (write_length<=0) //check its position: exceeds maximum line length or not found
{
if (buf_end - write_start < label_length_max) //check does current line the last
{
write_length = buf_end - write_start;
end_found = true;
}
else
{
for (write_length=label_length_max; write_length>0; write_length--) { //search for white space to make the line break
if (ESBYTE[write_start+write_length] == ' ') {
end_found = true;
break;
}
}
}
if (end_found != true) write_length = label_length_max; //no white space, so we write label_length_max
}
ESI = write_length; //set text length attribute for WriteText()
WriteText(x, y, 0x10, text_col, write_start);
// if (editpos >= write_start-buf_start) && (editpos <= write_start-buf_start + write_length) {
// WriteTextB(-write_start+buf_start+editpos * 8 + x - 5 +1, y, 0x90, 0xFF0000, "|");
// }
write_start += write_length + 1;
y += line_h;
if (write_start >= buf_end) break;
}
if (bg_col!=-1) DrawBar(x,y,w+1,h-y+line_h-4,bg_col);
return y+line_h;
}
//this function increase falue and return it //this function increase falue and return it
//useful for list of controls which goes one after one //useful for list of controls which goes one after one
:struct incn :struct incn

View File

@ -0,0 +1,23 @@
:struct child_window
{
dword window_loop_pointer;
dword id;
char stak[4096];
void create();
bool thread_exists();
};
:void child_window::create()
{
id = CreateThread(window_loop_pointer, #stak+4092);
}
:bool child_window::thread_exists()
{
dword proc_slot = GetProcessSlot(id);
if (proc_slot) {
ActivateWindow(proc_slot);
return true;
}
return false;
}

View File

@ -0,0 +1,54 @@
/*
We have a long text and need to show it in block.
Normal line break '\n' must be applied.
Long lines should be breaked by word.
TODO: scroll
*/
:int DrawTextViewArea(int x,y,w,h, dword buf_start, bg_col, text_col)
{
dword write_start;
dword buf_end;
int line_h = 15;
int label_length_max;
int write_length;
bool end_found;
write_start = buf_start;
buf_end = strlen(buf_start) + buf_start;
label_length_max = w / 8; // 8 big font char width
loop()
{
if (bg_col!=-1) DrawBar(x, y, w+1, line_h, bg_col);
end_found = false;
write_length = strchr(write_start, '\n') - write_start; //search normal line break
if (write_length > label_length_max) || (write_length<=0) //check its position: exceeds maximum line length or not found
{
if (buf_end - write_start < label_length_max) //check does current line the last
{
write_length = buf_end - write_start;
end_found = true;
}
else
{
for (write_length=label_length_max; write_length>0; write_length--) { //search for white space to make the line break
if (ESBYTE[write_start+write_length] == ' ') {
end_found = true;
break;
}
}
}
if (end_found != true) write_length = label_length_max; //no white space, so we write label_length_max
}
ESI = write_length; //set text length attribute for WriteText()
WriteText(x, y, 0x10, text_col, write_start);
// if (editpos >= write_start-buf_start) && (editpos <= write_start-buf_start + write_length) {
// WriteTextB(-write_start+buf_start+editpos * 8 + x - 5 +1, y, 0x90, 0xFF0000, "|");
// }
write_start += write_length + 1;
y += line_h;
if (write_start >= buf_end) break;
}
if (bg_col!=-1) DrawBar(x,y,w+1,h-y+line_h-4,bg_col);
return y+line_h;
}