Add Appearance: add standard edit;

IconEdit: ability to open image size up to 256*256, add to IMG


git-svn-id: svn://kolibrios.org@7254 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-04-22 13:33:01 +00:00
parent 97443811f3
commit 82d3fec9f1
9 changed files with 743 additions and 663 deletions

View File

@ -584,6 +584,7 @@ tup.append_table(img_files, {
{"GAMES/FLOOD-IT", PROGS .. "/games/flood-it/trunk/flood-it.com"},
{"GAMES/MINE", PROGS .. "/games/mine/trunk/mine"},
{"MEDIA/PIXIE/PIXIE", PROGS .. "/cmm/pixie2/pixie.com"},
{"MEDIA/ICONEDIT", PROGS .. "/cmm/iconedit/iconedit.com"},
{"MOUSECFG", PROGS .. "/cmm/mousecfg/mousecfg.com"},
{"NETWORK/WEBVIEW", PROGS .. "/cmm/browser/WebView.com"},
{"PANELS_CFG", PROGS .. "/cmm/panels_cfg/panels_cfg.com"},

View File

@ -54,9 +54,14 @@ _tabs tabs = { LP, LP, NULL, NULL, SKINS };
checkbox checkbox1 = { "Checkbox", true };
more_less_box spinbox1 = { 23, 0, 999, "SpinBox" };
edit_box edit1 = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
edit_box edit_cmm = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(param),#param,0, 0b};
char st_str[16];
edit_box edit_st = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(st_str),#st_str,0, 0b};
#define MENU_LIST "Open file Enter\nDelete Del"
//===================================================//
@ -77,7 +82,8 @@ void main()
case evMouse:
if (!CheckActiveProcess(Form.ID)) break;
SelectList_ProcessMouse();
edit_box_mouse stdcall (#edit1);
edit_box_mouse stdcall (#edit_cmm);
edit_box_mouse stdcall (#edit_st);
if (mouse.pkm)&&(select_list.MouseOver(mouse.x, mouse.y)) {
select_list.ProcessMouse(mouse.x, mouse.y);
@ -115,7 +121,8 @@ void main()
}
}
EAX= key_ascii << 8;
edit_box_key stdcall (#edit1);
edit_box_key stdcall (#edit_cmm);
edit_box_key stdcall (#edit_st);
break;
case evReDraw:
@ -175,13 +182,27 @@ void DrawWindowContent()
DrawFrame(skp.x, skp.y, skp.w, skp.h, " Components Preview ");
checkbox1.draw(skp.x+20, y.inc(30));
spinbox1.draw(skp.x+20, y.inc(30));
WriteText(skp.x+20, y.inc(30), 0x90, system.color.work_text, "Edit box");
DrawEditBoxPos(skp.x+20, y.inc(20), #edit1);
WriteText(skp.x+20, y.inc(30), 0x90, system.color.work_text, "C-- Edit");
DrawEditBoxPos(skp.x+20, y.inc(20), #edit_cmm);
WriteText(skp.x+20, y.inc(35), 0x90, system.color.work_text, "Strandard Edit");
DrawStEditBoxPos(skp.x+20, y.inc(20), #edit_st);
DrawStandartCaptButton(skp.x+20, skp.y+skp.h-40, GetFreeButtonId(), "Button1");
DrawStandartCaptButton(skp.x+120, skp.y+skp.h-40, GetFreeButtonId(), "Button2");
}
}
:void DrawStEditBoxPos(dword x,y, edit_box_pointer)
{
dword c_inactive = MixColors(system.color.work_graph, system.color.work, 128);
dword c_active = MixColors(system.color.work_graph, 0, 128);
ESI = edit_box_pointer;
ESI.edit_box.left = x;
ESI.edit_box.top = y;
ESI.edit_box.blur_border_color = c_inactive;
ESI.edit_box.focus_border_color = c_active;
edit_box_draw stdcall (edit_box_pointer);
}
void Open_Dir()

View File

@ -50,6 +50,7 @@ checkbox two_panels = { USE_TWO_PANELS };
void settings_dialog()
{
proc_info Settings;
int id;
active_settings=1;
font_size.value = kfont.size.pt;
@ -97,6 +98,7 @@ void settings_dialog()
if (line_height.click(id)) files.item_h = line_height.value;
if (big_icons.click(id)) BigIconsSwitch();
EventRedrawWindow(Form.left,Form.top);
//RefreshWindow(Form.num_slot, Settings.num_slot);
break;
case evKey:
@ -109,6 +111,7 @@ void settings_dialog()
case evReDraw:
DefineAndDrawWindow(Form.cwidth-300/2+Form.left, Form.cheight-292/2+Form.top, 400,
410+skin_height,0x34,system.color.work,TITLE_SETT,0);
GetProcessInfo(#Settings, SelfInfo);
DrawSettingsCheckBoxes();
}
}

View File

@ -1,10 +1,14 @@
#define MAX_CELL_SIZE 256
struct _image
{
unsigned rows, columns;
dword mas[32*32];
dword mas[MAX_CELL_SIZE*MAX_CELL_SIZE];
dword img;
void create();
void set_pixel();
void draw_line();
void fill();
void set_image();
dword get_pixel();
dword get_image();
@ -24,6 +28,82 @@ void _image::set_pixel(int _r, _c, _color)
mas[columns*_r + _c] = _color;
}
void _image::draw_line(int x1, int y1, int x2, int y2, dword color) {
int dx, dy, signX, signY, error, error2;
dx = x2 - x1;
if (dx < 0)
dx = -dx;
dy = y2 - y1;
if (dy < 0)
dy = -dy;
if (x1 < x2)
signX = 1;
else
signX = -1;
if (y1 < y2)
signY = 1;
else
signY = -1;
error = dx - dy;
set_pixel(y2, x2, color);
while((x1 != x2) || (y1 != y2))
{
set_pixel(y1, x1, color);
error2 = error * 2;
if(error2 > calc(-dy))
{
error -= dy;
x1 += signX;
}
if(error2 < dx)
{
error += dx;
y1 += signY;
}
}
}
void _image::fill(int _r, _c, _color)
{
#define MARKED 6
int r, c, i, restart;
dword old_color = get_pixel(_r, _c);
set_pixel(_r, _c, MARKED);
do {
restart=false;
for (r = 0; r < rows; r++)
for (c = 0; c < columns; c++)
{
IF (get_pixel(r,c) != old_color) continue;
IF (get_pixel(r,c) == MARKED) continue;
IF (c>0) && (get_pixel(r,c-1) == MARKED) set_pixel(r,c,MARKED);
IF (r>0) && (get_pixel(r-1,c) == MARKED) set_pixel(r,c,MARKED);
IF (c<columns-1) && (get_pixel(r,c+1) == MARKED) set_pixel(r,c,MARKED);
IF (r<rows-1) && (get_pixel(r+1,c) == MARKED) set_pixel(r,c,MARKED);
IF (get_pixel(r,c)==MARKED) restart=true;
}
}while(restart);
for (i=0; i<columns*rows; i++)
IF (mas[i]==MARKED) mas[i] = _color;
}
dword _image::get_pixel(int _r, _c)
{
return mas[columns*_r + _c];

View File

@ -11,7 +11,7 @@ enhance icon
pipet aside color view
*/
#define MEMSIZE 4096*40
#define MEMSIZE 4096*100
#include "../lib/gui.h"
#include "../lib/random.h"
@ -28,7 +28,7 @@ pipet aside color view
// //
//===================================================//
#define T_TITLE "Icon Editor 0.45"
#define T_TITLE "Icon Editor 0.46 Alpha"
#define TOOLBAR_H 24+8
#define PANEL_LEFT_W 16+5+5+3+3
@ -109,48 +109,7 @@ _image image;
libimg_image open_image;
_ActionsHistory actionsHistory;
enum {
TOOL_NONE = -1,
TOOL_PENCIL,
TOOL_PIPETTE,
TOOL_FILL,
TOOL_LINE,
TOOL_RECT,
TOOL_SELECT
};
struct Tool {
int id;
void (*activate)();
void (*deactivate)();
void (*onMouseEvent)(int x, int y, int lkm, int pkm);
void (*onKeyEvent)(dword keycode);
void (*onCanvasDraw)();
};
Tool tools[6];
int currentTool = -1;
void resetCurrentTool() {
if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) {
tools[currentTool].deactivate();
}
currentTool = TOOL_NONE;
}
void setCurrentTool(int index) {
resetCurrentTool();
currentTool = index;
if ((index != TOOL_NONE) && (tools[index].activate != 0))
tools[index].activate();
DrawLeftPanel();
DrawCanvas();
}
#include "tools.h"
//===================================================//
// //
@ -158,428 +117,6 @@ void setCurrentTool(int index) {
// //
//===================================================//
void FillTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (canvas.hovered()) && (currentTool==TOOL_FILL) && (mouse.up)
{
EventFill(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, tool_color);
actionsHistory.saveCurrentState();
DrawCanvas();
}
}
void PipetteTool_activate() {
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE);
}
void PipetteTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
tool_color = GetPixelUnderMouse();
DrawBar(Form.cwidth-30, 5, 20, 20, tool_color);
if (mouse.down) {
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, tool_color);
if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, tool_color);
setCurrentTool(TOOL_PENCIL);
}
}
bool PencilTool_Drawing = false;
void PencilTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (canvas.hovered())
{
if ((PencilTool_Drawing == true) && (!mouse.key)) {
actionsHistory.saveCurrentState();
PencilTool_Drawing = false;
}
if (mouse.key) {
image.set_pixel(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, tool_color);
PencilTool_Drawing = true;
}
DrawCanvas();
}
}
void PencilTool_reset() {
PencilTool_Drawing = false;
}
// Line tool
struct SimpleFigureTool_State {
int startX, startY;
int lastTempPosX, lastTempPosY;
};
enum {
TOOL_LINE_STATE,
TOOL_RECT_STATE
};
dword currentFigToolState = -1;
SimpleFigureTool_State figTool_States[2];
void SimpleFigureTool_Reset() {
if (currentTool == TOOL_LINE)
currentFigToolState = TOOL_LINE_STATE;
else if (currentTool == TOOL_RECT)
currentFigToolState = TOOL_RECT_STATE;
figTool_States[currentFigToolState].startX = -1;
figTool_States[currentFigToolState].startY = -1;
figTool_States[currentFigToolState].lastTempPosX = -1;
figTool_States[currentFigToolState].lastTempPosY = -1;
}
int mouseX_last;
int mouseY_last;
bool first_click_in_canvas = false;
void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (mouse.down) && (canvas.hovered()) first_click_in_canvas = true;
if (first_click_in_canvas)
{
if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value;
if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value;
if (mouseX<canvas.x) mouseX = canvas.x;
if (mouseY<canvas.y) mouseY = canvas.y;
if (mouse.key) {
if ((figTool_States[currentFigToolState].startX < 0) || (figTool_States[currentFigToolState].startY < 0)) {
figTool_States[currentFigToolState].startX = mouseX;
figTool_States[currentFigToolState].startY = mouseY;
}
else {
if ((calc(mouseX - canvas.x/zoom.value) != figTool_States[currentFigToolState].lastTempPosX)
|| (calc(mouseY - canvas.y/zoom.value) != figTool_States[currentFigToolState].lastTempPosY))
{
DrawCanvas();
}
}
mouseX_last = mouseX;
mouseY_last = mouseY;
}
if (mouse.up) {
if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0)) {
// Draw line from start position to current position
if (currentTool == TOOL_LINE) {
DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX - canvas.x/zoom.value,
mouseY - canvas.y/zoom.value,
tool_color,
1);
}
else if (currentTool == TOOL_RECT) {
DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX - canvas.x/zoom.value,
mouseY - canvas.y/zoom.value, tool_color, 1);
}
DrawCanvas();
actionsHistory.saveCurrentState();
// Reset start position
figTool_States[currentFigToolState].startX = -1;
figTool_States[currentFigToolState].startY = -1;
first_click_in_canvas = false;
}
}
}
}
void SimpleFigureTool_onCanvasDraw() {
if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0) && (mouse.key)) {
if (currentTool == TOOL_LINE) {
DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX_last - canvas.x/zoom.value,
mouseY_last - canvas.y/zoom.value,
tool_color,
2);
}
else if (currentTool == TOOL_RECT) {
DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX_last - canvas.x/zoom.value,
mouseY_last - canvas.y/zoom.value,
tool_color,
2);
}
figTool_States[currentFigToolState].lastTempPosX = mouseX_last - canvas.x/zoom.value;
figTool_States[currentFigToolState].lastTempPosY = mouseY_last - canvas.y/zoom.value;
}
}
// Selection
int selection_start_x = -1;
int selection_start_y = -1;
int selection_end_x = -1;
int selection_end_y = -1;
bool selection_active = false;
dword SelectionTool_buffer = 0;
dword SelectionTool_buffer_r = 0;
dword SelectionTool_buffer_c = 0;
bool selection_moving_started = false;
int selection_pivot_x = -1;
int selection_pivot_y = -1;
void SelectTool_normalizeSelection() {
int t;
// Restructuring of the selection coordinates
if (selection_end_x < selection_start_x) {
t = selection_start_x;
selection_start_x = selection_end_x;
selection_end_x = t;
}
if (selection_end_y < selection_start_y) {
t = selection_end_y;
selection_end_y = selection_start_y;
selection_start_y = t;
}
}
void reset_selection_moving() {
if (selection_moving_started) {
SelectTool_drawBuffer(selection_start_x, selection_start_y, 1);
selection_pivot_x = -1;
selection_pivot_y = -1;
selection_moving_started = false;
actionsHistory.saveCurrentState();
DrawCanvas();
}
}
bool is_selection_moving() {
return selection_moving_started;
}
void reset_selection() {
reset_selection_moving();
selection_start_x = -1;
selection_start_y = -1;
selection_end_x = -1;
selection_end_y = -1;
}
void SelectTool_activate() {
reset_selection();
selection_active = false;
}
void SelectTool_deactivate() {
reset_selection_moving();
}
bool SelectTool_pointInSelection(int x, int y) {
if (x >= selection_start_x) && (x <= selection_end_x) && (y >= selection_start_y) && (y <= selection_end_y)
return true;
else
return false;
}
void SelectTool_copyToBuffer() {
dword offset, r, c;
if (SelectionTool_buffer != 0)
free(SelectionTool_buffer);
SelectionTool_buffer_r = selection_end_y - selection_start_y + 1;
SelectionTool_buffer_c = selection_end_x - selection_start_x + 1;
SelectionTool_buffer = malloc(SelectionTool_buffer_r * SelectionTool_buffer_c * 4);
for (r = selection_start_y; r <= selection_end_y; r++) {
for (c = selection_start_x; c <= selection_end_x; c++) {
offset = calc(SelectionTool_buffer_c * calc(r - selection_start_y) + calc(c - selection_start_x)) * 4;
ESDWORD[SelectionTool_buffer + offset] = image.get_pixel(r, c);
}
}
}
void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
int click_x, click_y, dx, dy, m_x, m_y, r, c, color;
dword pixel;
m_x = TO_CANVAS_X(mouseX);
m_y = TO_CANVAS_Y(mouseY);
if (mouse.down) && (canvas.hovered()) && (!selection_active) {
if (selection_start_x != -1) && (SelectTool_pointInSelection(m_x, m_y)) {
if (selection_pivot_x == -1) {
selection_pivot_x = m_x;
selection_pivot_y = m_y;
GetKeys();
if (!selection_moving_started) && ( !(key_modifier&KEY_LSHIFT) ) {
for (r = selection_start_y; r <= selection_end_y; r++)
for (c = selection_start_x; c <= selection_end_x; c++) {
image.set_pixel(r, c, color2);
}
}
selection_moving_started = true;
}
}
else {
reset_selection();
selection_active = true;
}
}
if (selection_pivot_x != -1) {
dx = m_x - selection_pivot_x;
dy = m_y - selection_pivot_y;
if (selection_start_x + dx < 0)
dx = selection_start_x;
if (selection_end_x + dx >= 32)
dx = 31 - selection_end_x;
if (selection_start_y + dy < 0)
dy = selection_start_y;
if (selection_end_y + dy >= 32)
dy = 31 - selection_end_y;
selection_start_x += dx;
selection_end_x += dx;
selection_start_y += dy;
selection_end_y += dy;
selection_pivot_x += dx;
selection_pivot_y += dy;
DrawCanvas();
}
if (selection_active)
{
if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value;
if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value;
if (mouseX<canvas.x) mouseX = canvas.x;
if (mouseY<canvas.y) mouseY = canvas.y;
if (mouse.key) {
selection_end_x = TO_CANVAS_X(mouseX);
selection_end_y = TO_CANVAS_Y(mouseY);
if ((selection_start_x < 0) || (selection_start_y < 0)) {
selection_start_x = TO_CANVAS_X(mouseX);
selection_start_y = TO_CANVAS_Y(mouseY);
}
else {
DrawCanvas();
/**if ((calc(TO_CANVAS_X(mouseX)) != selection_end_x)
|| (calc(TO_CANVAS_Y(mouseY)) != selection_end_y))
{
DrawCanvas();
}*/
}
}
if (mouse.up) {
selection_active = false;
SelectTool_normalizeSelection();
SelectTool_copyToBuffer();
}
}
if (mouse.up) {
if (selection_pivot_x != -1) {
selection_pivot_x = -1;
selection_pivot_y = -1;
}
}
}
void SelectTool_onCanvasDraw() {
if (selection_moving_started)
SelectTool_drawBuffer(selection_start_x, selection_start_y, 2);
if ((selection_start_x >= 0) && (selection_start_y >= 0) && (selection_end_x >= 0) && (selection_end_y >= 0)) {
DrawSelection(selection_start_x, selection_start_y, selection_end_x, selection_end_y);
}
}
void SelectTool_drawBuffer(int insert_x, int insert_y, int target) {
dword color;
dword offset, r, c;
dword insert_to_x, insert_to_y;
if (SelectionTool_buffer != 0) {
insert_to_x = insert_x + SelectionTool_buffer_c - 1;
if (insert_to_x >= image.columns)
insert_to_x = image.columns-1;
insert_to_y = insert_y + SelectionTool_buffer_r - 1;
if (insert_to_y >= image.rows)
insert_to_y = image.rows-1;
for (r = insert_y; r <= insert_to_y; r++) {
for (c = insert_x; c <= insert_to_x; c++) {
offset = calc(SelectionTool_buffer_c * calc(r - insert_y) + calc(c - insert_x)) * 4;
color = ESDWORD[SelectionTool_buffer + offset];
if (target == 1)
image.set_pixel(r, c, color);
else
DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y,
zoom.value, zoom.value, color);
}
}
}
}
void SelectTool_onKeyEvent(dword keycode) {
dword offset, r, c;
dword insert_x, insert_y, insert_to_x, insert_to_y;
if (keycode == SCAN_CODE_KEY_V) {
if (SelectionTool_buffer != 0) {
reset_selection();
selection_moving_started = true;
selection_start_x = 0;
selection_end_x = SelectionTool_buffer_c - 1;
selection_start_y = 0;
selection_end_y = SelectionTool_buffer_r - 1;
DrawCanvas();
}
}
}
void initTools()
{
@ -624,15 +161,20 @@ void main()
//system.color.get();
//Libimg_ReplaceColor(tools_img.image, tools_img.w, tools_img.h, 0xFFF8C0D0, system.color.work);
if (!param[0]) {
image.create(32, 32);
if (param[0]) {
}
else
{
Libimg_LoadImage(#open_image, #param);
if (open_image.w==32) && (open_image.h==32) {
image.set_image(open_image.imgsrc);
if (open_image.w*open_image.h>MAX_CELL_SIZE*MAX_CELL_SIZE) {
notify("'Hey, this is just an icon editor,\nselected image is too big to open!' -E");
ExitProcess();
}
else {
notify("'Error: image format is unacceptable (PNG, 32x32x16b expected)' -E");
image.create(open_image.w, open_image.h);
image.set_image(open_image.imgsrc);
}
}
@ -858,7 +400,7 @@ void DrawEditArea()
canvas.w = image.columns * zoom.value;
canvas.h = image.rows * zoom.value;
if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) {
zoom.dec();
zoom.value--;
DrawEditArea();
return;
}
@ -980,35 +522,7 @@ dword GetPixelUnderMouse()
void EventSave()
{
dword encoded_data=0;
dword encoded_size=0;
dword image_ptr = 0;
image_ptr = create_image(Image_bpp24, 32, 32);
if (image_ptr == 0) {
notify("'Error saving file, probably not enought memory!' -E");
}
else {
EDI = image_ptr;
memmov(EDI._Image.Data, image.get_image(), image.rows * image.columns * 3);
encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size);
img_destroy stdcall(image_ptr);
if(encoded_data == 0) {
notify("'Error saving file, incorrect data!' -E");
}
else {
if (CreateFile(encoded_size, encoded_data, "/rd/1/saved_image.png") == 0) {
notify("'File saved as /rd/1/saved_image.png' -O");
}
else {
notify("'Error saving file, probably not enought space on ramdisk!' -E");
}
}
}
save_image(image.get_image(), image.columns, image.rows, "/rd/1/saved_image.png");
}
void EventSetActiveColor(int _number, _color)
@ -1025,140 +539,3 @@ void EventSetActiveColor(int _number, _color)
DrawActiveColor(NULL);
DrawColorPallets();
}
void EventFill(dword _r, _c, _color)
{
#define MARKED 6
int r, c, i, restart;
dword old_color = image.get_pixel(_r, _c);
image.set_pixel(_r, _c, MARKED);
do {
restart=false;
for (r = 0; r < image.rows; r++)
for (c = 0; c < image.columns; c++)
{
IF (image.get_pixel(r,c) != old_color) continue;
IF (image.get_pixel(r,c) == MARKED) continue;
IF (c>0) && (image.get_pixel(r,c-1) == MARKED) image.set_pixel(r,c,MARKED);
IF (r>0) && (image.get_pixel(r-1,c) == MARKED) image.set_pixel(r,c,MARKED);
IF (c<image.columns-1) && (image.get_pixel(r,c+1) == MARKED) image.set_pixel(r,c,MARKED);
IF (r<image.rows-1) && (image.get_pixel(r+1,c) == MARKED) image.set_pixel(r,c,MARKED);
IF (image.get_pixel(r,c)==MARKED) restart=true;
}
}while(restart);
for (i=0; i<image.columns*image.rows; i++)
IF (image.mas[i]==MARKED) image.mas[i] = _color;
}
// target - image (1) or canvas (2)
void DrawLine(int x1, int y1, int x2, int y2, dword color, int target) {
int dx, dy, signX, signY, error, error2;
dx = x2 - x1;
if (dx < 0)
dx = -dx;
dy = y2 - y1;
if (dy < 0)
dy = -dy;
if (x1 < x2)
signX = 1;
else
signX = -1;
if (y1 < y2)
signY = 1;
else
signY = -1;
error = dx - dy;
if (target == 1)
image.set_pixel(y2, x2, color);
else
DrawBar(x2*zoom.value + canvas.x, y2*zoom.value + canvas.y,
zoom.value, zoom.value, color);
while((x1 != x2) || (y1 != y2))
{
if (target == 1)
image.set_pixel(y1, x1, color);
else
DrawBar(x1*zoom.value + canvas.x, y1*zoom.value + canvas.y,
zoom.value, zoom.value, color);
error2 = error * 2;
if(error2 > calc(-dy))
{
error -= dy;
x1 += signX;
}
if(error2 < dx)
{
error += dx;
y1 += signY;
}
}
}
void DrawRectangleInCanvas(int x1, int y1, int x2, int y2, dword color, int target) {
DrawLine(x1, y1, x2, y1, color, target);
DrawLine(x2, y1, x2, y2, color, target);
DrawLine(x2, y2, x1, y2, color, target);
DrawLine(x1, y2, x1, y1, color, target);
}
#define SELECTION_COLOR 0xAAE5EF
void DrawSelection(int x1, int y1, int x2, int y2) {
int p1x, p1y, p2x, p2y, r, c, old_color, new_color;
dword offset;
if (x1 <= x2) {
p1x = x1;
p2x = x2;
}
else {
p1x = x2;
p2x = x1;
}
if (y1 <= y2) {
p2y = y1;
p1y = y2;
}
else {
p2y = y2;
p1y = y1;
}
for (r = p1y; r >= p2y; r--) {
for (c = p1x; c <= p2x; c++) {
if (selection_moving_started) && (SelectTool_pointInSelection(c, r)) {
offset = calc(SelectionTool_buffer_c * calc(r - selection_start_y) + calc(c - selection_start_x)) * 4;
old_color = ESDWORD[SelectionTool_buffer + offset];
}
else {
old_color = image.get_pixel(r, c);
}
new_color = MixColors(old_color, SELECTION_COLOR, 64);
DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y,
zoom.value, zoom.value, new_color);
}
}
}

View File

@ -0,0 +1,590 @@
enum {
TOOL_NONE = -1,
TOOL_PENCIL,
TOOL_PIPETTE,
TOOL_FILL,
TOOL_LINE,
TOOL_RECT,
TOOL_SELECT
};
struct Tool {
int id;
void (*activate)();
void (*deactivate)();
void (*onMouseEvent)(int x, int y, int lkm, int pkm);
void (*onKeyEvent)(dword keycode);
void (*onCanvasDraw)();
};
int currentTool = -1;
Tool tools[6];
void resetCurrentTool() {
if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) {
tools[currentTool].deactivate();
}
currentTool = TOOL_NONE;
}
void setCurrentTool(int index) {
resetCurrentTool();
currentTool = index;
if ((index != TOOL_NONE) && (tools[index].activate != 0))
tools[index].activate();
DrawLeftPanel();
DrawCanvas();
}
//===================================================//
// //
// FUNTIONS //
// //
//===================================================//
void FillTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (canvas.hovered()) && (currentTool==TOOL_FILL) && (mouse.up)
{
image.fill(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, tool_color);
actionsHistory.saveCurrentState();
DrawCanvas();
}
}
void PipetteTool_activate() {
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE);
}
void PipetteTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
tool_color = GetPixelUnderMouse();
DrawBar(Form.cwidth-30, 5, 20, 20, tool_color);
if (mouse.down) {
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, tool_color);
if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, tool_color);
setCurrentTool(TOOL_PENCIL);
}
}
bool PencilTool_Drawing = false;
void PencilTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (canvas.hovered())
{
if ((PencilTool_Drawing == true) && (!mouse.key)) {
actionsHistory.saveCurrentState();
PencilTool_Drawing = false;
}
if (mouse.key) {
image.set_pixel(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, tool_color);
PencilTool_Drawing = true;
}
DrawCanvas();
}
}
void PencilTool_reset() {
PencilTool_Drawing = false;
}
// Line tool
struct SimpleFigureTool_State {
int startX, startY;
int lastTempPosX, lastTempPosY;
};
enum {
TOOL_LINE_STATE,
TOOL_RECT_STATE
};
dword currentFigToolState = -1;
SimpleFigureTool_State figTool_States[2];
void SimpleFigureTool_Reset() {
if (currentTool == TOOL_LINE)
currentFigToolState = TOOL_LINE_STATE;
else if (currentTool == TOOL_RECT)
currentFigToolState = TOOL_RECT_STATE;
figTool_States[currentFigToolState].startX = -1;
figTool_States[currentFigToolState].startY = -1;
figTool_States[currentFigToolState].lastTempPosX = -1;
figTool_States[currentFigToolState].lastTempPosY = -1;
}
int mouseX_last;
int mouseY_last;
bool first_click_in_canvas = false;
void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (mouse.down) && (canvas.hovered()) first_click_in_canvas = true;
if (first_click_in_canvas)
{
if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value;
if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value;
if (mouseX<canvas.x) mouseX = canvas.x;
if (mouseY<canvas.y) mouseY = canvas.y;
if (mouse.key) {
if ((figTool_States[currentFigToolState].startX < 0)
|| (figTool_States[currentFigToolState].startY < 0)) {
figTool_States[currentFigToolState].startX = mouseX;
figTool_States[currentFigToolState].startY = mouseY;
}
else {
if ((calc(mouseX - canvas.x/zoom.value) != figTool_States[currentFigToolState].lastTempPosX)
|| (calc(mouseY - canvas.y/zoom.value) != figTool_States[currentFigToolState].lastTempPosY))
{
DrawCanvas();
}
}
mouseX_last = mouseX;
mouseY_last = mouseY;
}
if (mouse.up) {
if ((figTool_States[currentFigToolState].startX >= 0)
&& (figTool_States[currentFigToolState].startY >= 0)) {
// Draw line from start position to current position
if (currentTool == TOOL_LINE) {
DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX - canvas.x/zoom.value,
mouseY - canvas.y/zoom.value,
tool_color,
1);
}
else if (currentTool == TOOL_RECT) {
DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX - canvas.x/zoom.value,
mouseY - canvas.y/zoom.value, tool_color, 1);
}
DrawCanvas();
actionsHistory.saveCurrentState();
// Reset start position
figTool_States[currentFigToolState].startX = -1;
figTool_States[currentFigToolState].startY = -1;
first_click_in_canvas = false;
}
}
}
}
void SimpleFigureTool_onCanvasDraw() {
if ((figTool_States[currentFigToolState].startX >= 0)
&& (figTool_States[currentFigToolState].startY >= 0) && (mouse.key)) {
if (currentTool == TOOL_LINE) {
DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX_last - canvas.x/zoom.value,
mouseY_last - canvas.y/zoom.value,
tool_color,
2);
}
else if (currentTool == TOOL_RECT) {
DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX_last - canvas.x/zoom.value,
mouseY_last - canvas.y/zoom.value,
tool_color,
2);
}
figTool_States[currentFigToolState].lastTempPosX = mouseX_last - canvas.x/zoom.value;
figTool_States[currentFigToolState].lastTempPosY = mouseY_last - canvas.y/zoom.value;
}
}
// Selection
int selection_start_x = -1;
int selection_start_y = -1;
int selection_end_x = -1;
int selection_end_y = -1;
bool selection_active = false;
dword SelectionTool_buffer = 0;
dword SelectionTool_buffer_r = 0;
dword SelectionTool_buffer_c = 0;
bool selection_moving_started = false;
int selection_pivot_x = -1;
int selection_pivot_y = -1;
void SelectTool_normalizeSelection() {
int t;
// Restructuring of the selection coordinates
if (selection_end_x < selection_start_x) {
t = selection_start_x;
selection_start_x = selection_end_x;
selection_end_x = t;
}
if (selection_end_y < selection_start_y) {
t = selection_end_y;
selection_end_y = selection_start_y;
selection_start_y = t;
}
}
void reset_selection_moving() {
if (selection_moving_started) {
SelectTool_drawBuffer(selection_start_x, selection_start_y, 1);
selection_pivot_x = -1;
selection_pivot_y = -1;
selection_moving_started = false;
actionsHistory.saveCurrentState();
DrawCanvas();
}
}
bool is_selection_moving() {
return selection_moving_started;
}
void reset_selection() {
reset_selection_moving();
selection_start_x = -1;
selection_start_y = -1;
selection_end_x = -1;
selection_end_y = -1;
}
void SelectTool_activate() {
reset_selection();
selection_active = false;
}
void SelectTool_deactivate() {
reset_selection_moving();
}
bool SelectTool_pointInSelection(int x, int y) {
if (x >= selection_start_x) && (x <= selection_end_x) && (y >= selection_start_y) && (y <= selection_end_y)
return true;
else
return false;
}
void SelectTool_copyToBuffer() {
dword offset, r, c;
if (SelectionTool_buffer != 0)
free(SelectionTool_buffer);
SelectionTool_buffer_r = selection_end_y - selection_start_y + 1;
SelectionTool_buffer_c = selection_end_x - selection_start_x + 1;
SelectionTool_buffer = malloc(SelectionTool_buffer_r * SelectionTool_buffer_c * 4);
for (r = selection_start_y; r <= selection_end_y; r++) {
for (c = selection_start_x; c <= selection_end_x; c++) {
offset = calc(SelectionTool_buffer_c * calc(r - selection_start_y) + calc(c - selection_start_x)) * 4;
ESDWORD[SelectionTool_buffer + offset] = image.get_pixel(r, c);
}
}
}
void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
int click_x, click_y, dx, dy, m_x, m_y, r, c, color;
dword pixel;
m_x = TO_CANVAS_X(mouseX);
m_y = TO_CANVAS_Y(mouseY);
if (mouse.down) && (canvas.hovered()) && (!selection_active) {
if (selection_start_x != -1) && (SelectTool_pointInSelection(m_x, m_y)) {
if (selection_pivot_x == -1) {
selection_pivot_x = m_x;
selection_pivot_y = m_y;
GetKeys();
if (!selection_moving_started) && ( !(key_modifier&KEY_LSHIFT) ) {
for (r = selection_start_y; r <= selection_end_y; r++)
for (c = selection_start_x; c <= selection_end_x; c++) {
image.set_pixel(r, c, color2);
}
}
selection_moving_started = true;
}
}
else {
reset_selection();
selection_active = true;
}
}
if (selection_pivot_x != -1) {
dx = m_x - selection_pivot_x;
dy = m_y - selection_pivot_y;
if (selection_start_x + dx < 0)
dx = selection_start_x;
if (selection_end_x + dx >= image.columns)
dx = image.columns-1 - selection_end_x;
if (selection_start_y + dy < 0)
dy = selection_start_y;
if (selection_end_y + dy >= image.rows)
dy = image.rows-1 - selection_end_y;
selection_start_x += dx;
selection_end_x += dx;
selection_start_y += dy;
selection_end_y += dy;
selection_pivot_x += dx;
selection_pivot_y += dy;
DrawCanvas();
}
if (selection_active)
{
if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value;
if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value;
if (mouseX<canvas.x) mouseX = canvas.x;
if (mouseY<canvas.y) mouseY = canvas.y;
if (mouse.key) {
selection_end_x = TO_CANVAS_X(mouseX);
selection_end_y = TO_CANVAS_Y(mouseY);
if ((selection_start_x < 0) || (selection_start_y < 0)) {
selection_start_x = TO_CANVAS_X(mouseX);
selection_start_y = TO_CANVAS_Y(mouseY);
}
else {
DrawCanvas();
/**if ((calc(TO_CANVAS_X(mouseX)) != selection_end_x)
|| (calc(TO_CANVAS_Y(mouseY)) != selection_end_y))
{
DrawCanvas();
}*/
}
}
if (mouse.up) {
selection_active = false;
SelectTool_normalizeSelection();
SelectTool_copyToBuffer();
}
}
if (mouse.up) {
if (selection_pivot_x != -1) {
selection_pivot_x = -1;
selection_pivot_y = -1;
}
}
}
void SelectTool_onCanvasDraw() {
if (selection_moving_started)
SelectTool_drawBuffer(selection_start_x, selection_start_y, 2);
if ((selection_start_x >= 0) && (selection_start_y >= 0) && (selection_end_x >= 0) && (selection_end_y >= 0)) {
DrawSelection(selection_start_x, selection_start_y, selection_end_x, selection_end_y);
}
}
void SelectTool_drawBuffer(int insert_x, int insert_y, int target) {
dword color;
dword offset, r, c;
dword insert_to_x, insert_to_y;
if (SelectionTool_buffer != 0) {
insert_to_x = insert_x + SelectionTool_buffer_c - 1;
if (insert_to_x >= image.columns)
insert_to_x = image.columns-1;
insert_to_y = insert_y + SelectionTool_buffer_r - 1;
if (insert_to_y >= image.rows)
insert_to_y = image.rows-1;
for (r = insert_y; r <= insert_to_y; r++) {
for (c = insert_x; c <= insert_to_x; c++) {
offset = calc(SelectionTool_buffer_c * calc(r - insert_y) + calc(c - insert_x)) * 4;
color = ESDWORD[SelectionTool_buffer + offset];
if (target == 1)
image.set_pixel(r, c, color);
else
DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y,
zoom.value, zoom.value, color);
}
}
}
}
void SelectTool_onKeyEvent(dword keycode) {
dword offset, r, c;
dword insert_x, insert_y, insert_to_x, insert_to_y;
if (keycode == SCAN_CODE_KEY_V) {
if (SelectionTool_buffer != 0) {
reset_selection();
selection_moving_started = true;
selection_start_x = 0;
selection_end_x = SelectionTool_buffer_c - 1;
selection_start_y = 0;
selection_end_y = SelectionTool_buffer_r - 1;
DrawCanvas();
}
}
}
//===================================================//
// //
// DRAWs //
// //
//===================================================//
// target - image (1) or canvas (2)
void DrawLine(int x1, int y1, int x2, int y2, dword color, int target) {
int dx, dy, signX, signY, error, error2;
if (1==target) {
image.draw_line(x1, y1, x2, y2, color);
return;
}
dx = x2 - x1;
if (dx < 0)
dx = -dx;
dy = y2 - y1;
if (dy < 0)
dy = -dy;
if (x1 < x2)
signX = 1;
else
signX = -1;
if (y1 < y2)
signY = 1;
else
signY = -1;
error = dx - dy;
DrawBar(x2*zoom.value + canvas.x, y2*zoom.value + canvas.y,
zoom.value, zoom.value, color);
while((x1 != x2) || (y1 != y2))
{
DrawBar(x1*zoom.value + canvas.x, y1*zoom.value + canvas.y,
zoom.value, zoom.value, color);
error2 = error * 2;
if(error2 > calc(-dy))
{
error -= dy;
x1 += signX;
}
if(error2 < dx)
{
error += dx;
y1 += signY;
}
}
}
void DrawRectangleInCanvas(int x1, int y1, int x2, int y2, dword color, int target) {
DrawLine(x1, y1, x2, y1, color, target);
DrawLine(x2, y1, x2, y2, color, target);
DrawLine(x2, y2, x1, y2, color, target);
DrawLine(x1, y2, x1, y1, color, target);
}
#define SELECTION_COLOR 0xAAE5EF
void DrawSelection(int x1, int y1, int x2, int y2) {
int p1x, p1y, p2x, p2y, r, c, old_color, new_color;
dword offset;
if (x1 <= x2) {
p1x = x1;
p2x = x2;
}
else {
p1x = x2;
p2x = x1;
}
if (y1 <= y2) {
p2y = y1;
p1y = y2;
}
else {
p2y = y2;
p1y = y1;
}
for (r = p1y; r >= p2y; r--) {
for (c = p1x; c <= p2x; c++) {
if (selection_moving_started) && (SelectTool_pointInSelection(c, r)) {
offset = calc(SelectionTool_buffer_c * calc(r - selection_start_y) + calc(c - selection_start_x)) * 4;
old_color = ESDWORD[SelectionTool_buffer + offset];
}
else {
old_color = image.get_pixel(r, c);
}
new_color = MixColors(old_color, SELECTION_COLOR, 64);
DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y,
zoom.value, zoom.value, new_color);
}
}
}

View File

@ -203,6 +203,12 @@ inline fastcall void ActivateWindow( ECX)
$int 0x40
}
:void RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
{
ActivateWindow(ID_REFRESH);
ActivateWindow(ID_ACTIVE);
}
inline fastcall int MinimizeWindow()
{
EAX = 18;
@ -537,19 +543,6 @@ inline fastcall void PutPixel( EBX,ECX,EDX)
$int 0x40
}
inline RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
{
EAX = 18;
EBX = 22;
ECX = 3;
EDX = ID_REFRESH;
$int 0x40
EAX = 18;
EBX = 3;
EDX = ID_ACTIVE;
$int 0x40
}
:void UnsafeDefineButton(dword x,y,w,h,id,color)
{
EAX = 8;

View File

@ -161,7 +161,7 @@ struct frame
word start_y;
dword ext_col;
dword int_col;
dword draw_text_flag; // 0-not,1-yes
dword flags; // see FR_FLAGS
dword text_pointer;
dword text_position; // 0-up,1-bottom
dword font_number; // 0-monospace,1-variable
@ -170,6 +170,18 @@ struct frame
dword font_backgr_color;
};
// FR_FLAGS = [x][yyy][z]
// z - Caption
// yyy - BorderStyle
// x - BackStyle
#define FR_CAPTION 00001b // [z]
#define FR_DOUBLE 00000b // [yyy]
#define FR_RAISED 00010b // [yyy]
#define FR_SUNKEN 00100b // [yyy]
#define FR_ETCHED 00110b // [yyy]
#define FR_RIDGED 01000b // [yyy]
#define FR_FILLED 10000b // [x]
:frame frame123 = { 0, 260, 10, 60, 16, NULL, 0xFFFfff, 1, NULL, 0, 1, 12, 0x000111, 0xCCCccc };
:void DrawFrame(dword x,y,w,h,text)
{
@ -183,6 +195,7 @@ struct frame
frame123.size_x = w;
frame123.size_y = h;
frame123.text_pointer = text;
if (!text) frame123.flags=0; else frame123.flags=FR_CAPTION;
frame_draw stdcall (#frame123);
}

View File

@ -88,7 +88,9 @@ struct _Image
#define Image_bpp8g 7 // grayscale
#define Image_bpp2i 8
#define Image_bpp4i 9
#define Image_bpp8a 10 // grayscale with alpha channel; application layer only!!! kernel doesn't handle this image type, libimg can only create and destroy such images
#define Image_bpp8a 10 // grayscale with alpha channel; application layer only!!!
// kernel doesn't handle this image type,
// libimg can only create and destroy such images
:dword load_image(dword filename)
@ -191,8 +193,8 @@ struct _Image
);
}
//NOTICE: DO NOT FORGOT TO INIT libio AND libimg!!!
:void save_image(dword _image, _w, _h, _path)
//NOTICE: DO NOT FORGET TO INIT libio AND libimg!!!
:void save_image(dword _image_pointer, _w, _h, _path)
{
char save_success_message[4096+200];
dword encoded_data=0;
@ -206,7 +208,7 @@ struct _Image
}
else {
EDI = image_ptr;
memmov(EDI._Image.Data, _image, _w * _h * 3);
memmov(EDI._Image.Data, _image_pointer, _w * _h * 3);
encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size);