2021-12-05 00:24:31 +01:00
|
|
|
#define MEMSIZE 1024*100
|
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
/*=====================================================
|
|
|
|
| |
|
|
|
|
| LIB |
|
|
|
|
| |
|
|
|
|
=====================================================*/
|
|
|
|
|
2021-12-05 00:24:31 +01:00
|
|
|
#include "../lib/gui.h"
|
|
|
|
#include "../lib/random.h"
|
|
|
|
#include "../lib/mem.h"
|
|
|
|
#include "../lib/cursor.h"
|
|
|
|
#include "../lib/list_box.h"
|
|
|
|
#include "../lib/events.h"
|
|
|
|
|
|
|
|
#include "../lib/obj/libimg.h"
|
|
|
|
#include "../lib/obj/box_lib.h"
|
|
|
|
#include "../lib/obj/proc_lib.h"
|
|
|
|
|
|
|
|
#include "../lib/patterns/rgb.h"
|
|
|
|
#include "../lib/patterns/toolbar_button.h"
|
|
|
|
#include "../lib/patterns/simple_open_dialog.h"
|
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
/*=====================================================
|
|
|
|
| |
|
|
|
|
| DATA |
|
|
|
|
| |
|
|
|
|
=====================================================*/
|
2021-12-05 00:24:31 +01:00
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
#include "data.h"
|
2022-01-14 08:12:38 +01:00
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
/*=====================================================
|
|
|
|
| |
|
|
|
|
| CODE |
|
|
|
|
| |
|
|
|
|
=====================================================*/
|
2021-12-05 00:24:31 +01:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2022-01-15 17:31:40 +01:00
|
|
|
/* Init external libraries */
|
2021-12-05 00:24:31 +01:00
|
|
|
load_dll(libimg, #libimg_init, 1);
|
|
|
|
load_dll(boxlib, #box_lib_init,0);
|
|
|
|
load_dll(Proc_lib, #OpenDialog_init,0);
|
|
|
|
OpenDialog_init stdcall (#o_dialog);
|
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
/* Init UI */
|
|
|
|
icons18.load("/sys/icons16.png");
|
|
|
|
icons18.replace_2colors(0xffFFFfff, COL_LIGHT, 0xffCACBD6, COL_LIGHT-0x080808);
|
|
|
|
icons18a.load("/sys/icons16.png");
|
|
|
|
icons18a.replace_2colors(0xffFFFfff, COL_BUTTON, 0xffCACBD6, 0);
|
|
|
|
pixie_skin.load("/sys/media/pixieskn.png");
|
|
|
|
Form.width = screen.w/6*5;
|
|
|
|
Form.height = screen.h/6*5;
|
2022-01-15 21:30:04 +01:00
|
|
|
sc.work = COL_WORK;
|
|
|
|
sc.work_text = COL_WORK_TEXT;
|
|
|
|
sc.light = COL_LIGHT;
|
|
|
|
sc.dark = COL_DARK;
|
|
|
|
sc.line = COL_LINE;
|
|
|
|
sc.button = COL_BUTTON;
|
|
|
|
sc.button_text = COL_BUTTON_TEXT;
|
2022-01-15 17:31:40 +01:00
|
|
|
|
|
|
|
/* Handle application parameters */
|
|
|
|
//if (!param) open_image("/sys/home.png");
|
2021-12-05 00:24:31 +01:00
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
/* Set event mask and go to main loop */
|
2021-12-05 00:24:31 +01:00
|
|
|
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
|
|
|
|
loop() switch(WaitEvent())
|
|
|
|
{
|
|
|
|
case evMouse:
|
|
|
|
mouse.get();
|
2022-01-15 17:31:40 +01:00
|
|
|
if (main_image.h > canvas.h) scrollbar_v_mouse stdcall(#scroll_v);
|
|
|
|
if (main_image.w > canvas.w) scrollbar_h_mouse stdcall(#scroll_h);
|
2022-01-15 21:30:04 +01:00
|
|
|
if (active_tool == TOOL_SCALE) {
|
|
|
|
edit_box_mouse stdcall (#edit_w);
|
|
|
|
edit_box_mouse stdcall (#edit_h);
|
|
|
|
}
|
2021-12-05 00:24:31 +01:00
|
|
|
if (scroll_v.delta) || (scroll_h.delta) draw_canvas();
|
2022-01-08 20:52:20 +01:00
|
|
|
if (EAX = mouse.vert) {
|
|
|
|
if (EAX<10) event_scroll_canvas(SCAN_CODE_DOWN);
|
|
|
|
else event_scroll_canvas(SCAN_CODE_UP);
|
|
|
|
} if (EAX = mouse.hor) {
|
|
|
|
if (EAX<10) event_scroll_canvas(SCAN_CODE_RIGHT);
|
|
|
|
else event_scroll_canvas(SCAN_CODE_LEFT);
|
|
|
|
}
|
2021-12-05 00:24:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case evButton:
|
|
|
|
pressed_button_id = GetButtonID();
|
|
|
|
if (pressed_button_id==1) ExitProcess();
|
2022-01-15 21:30:04 +01:00
|
|
|
keep_ratio.click(pressed_button_id);
|
2021-12-05 00:24:31 +01:00
|
|
|
button.press(pressed_button_id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
GetKeys();
|
2022-01-15 21:30:04 +01:00
|
|
|
if (active_tool == TOOL_SCALE)
|
|
|
|
&& (edit_w.flags & ed_focus) || (edit_h.flags & ed_focus) {
|
|
|
|
if (key_scancode == SCAN_CODE_TAB) {
|
|
|
|
edit_w.flags >< edit_h.flags;
|
|
|
|
draw_acive_panel();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (edit_w.flags & ed_focus) {
|
|
|
|
edit_box_key_c stdcall (#edit_w, key_editbox);
|
|
|
|
if (keep_ratio.checked) && (text_w) && (atoi(#text_w)) {
|
|
|
|
EDI = main_image.h*100 / calc(main_image.w*100 / atoi(#text_w));
|
|
|
|
edit_box_set_text stdcall (#edit_h, itoa(EDI));
|
|
|
|
edit_box_draw stdcall (#edit_h);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
edit_box_key_c stdcall (#edit_h, key_editbox);
|
|
|
|
if (keep_ratio.checked) && (text_h) && (atoi(#text_h)) {
|
|
|
|
EDI = main_image.h*100 / calc(main_image.w*100 / atoi(#text_h));
|
|
|
|
edit_box_set_text stdcall (#edit_w, itoa(EDI));
|
|
|
|
edit_box_draw stdcall (#edit_w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-01-08 20:52:20 +01:00
|
|
|
if (key_scancode == SCAN_CODE_DOWN) event_scroll_canvas(SCAN_CODE_DOWN);
|
|
|
|
if (key_scancode == SCAN_CODE_UP) event_scroll_canvas(SCAN_CODE_UP);
|
|
|
|
if (key_scancode == SCAN_CODE_LEFT) event_scroll_canvas(SCAN_CODE_LEFT);
|
|
|
|
if (key_scancode == SCAN_CODE_RIGHT) event_scroll_canvas(SCAN_CODE_RIGHT);
|
|
|
|
key.press(key_scancode);
|
2021-12-05 00:24:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case evReDraw:
|
|
|
|
draw_window();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_window()
|
|
|
|
{
|
2022-01-14 08:12:38 +01:00
|
|
|
DefineAndDrawWindow(screen.w-Form.width/2, screen.h-Form.height/2, Form.width, Form.height, 0x42, NULL, NULL, 0);
|
2021-12-05 00:24:31 +01:00
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2022-01-15 17:31:40 +01:00
|
|
|
/* Draw window borders */
|
|
|
|
DrawRectangle(0,0,Form.width,Form.height,COL_LINE);
|
|
|
|
DrawRectangle(1,1,Form.width-2,Form.height-2,COL_LIGHT);
|
|
|
|
/* Check if the window is collapsed into header */
|
|
|
|
if (Form.status_window&ROLLED_UP) {
|
|
|
|
DrawBar(2, 2, Form.width-3, skin_h-4, COL_WORK);
|
|
|
|
WriteText(5, skin_h-11/2, 0x90, COL_WORK_TEXT, "ImageEditor Pro [Collapsed]");
|
|
|
|
draw_window_manipulation_buttons(skin_h-17/2);
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 00:24:31 +01:00
|
|
|
if (Form.width < 560) { MoveSize(OLD,OLD,560,OLD); return; }
|
|
|
|
if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
|
2022-01-14 08:12:38 +01:00
|
|
|
scroll_v.all_redraw = scroll_h.all_redraw = 1;
|
|
|
|
draw_content();
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_content()
|
|
|
|
{
|
|
|
|
incn tx;
|
2021-12-05 00:24:31 +01:00
|
|
|
button.init(40);
|
|
|
|
key.init(40);
|
|
|
|
|
2022-01-14 08:12:38 +01:00
|
|
|
canvas.w = Form.cwidth - CANVASX - 1;
|
|
|
|
canvas.h = Form.cheight - STATUSBAR_H - CANVASY - 1;
|
2021-12-05 00:24:31 +01:00
|
|
|
if (main_image.h > canvas.h) canvas.w -= scroll_v.size_x + 1;
|
|
|
|
if (main_image.w > canvas.w) canvas.h -= scroll_h.size_y + 1;
|
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
//draw panel border
|
2022-01-14 08:12:38 +01:00
|
|
|
DrawBar(CANVASX, 0, 1, Form.cheight, COL_LINE);
|
2021-12-05 00:24:31 +01:00
|
|
|
|
2022-01-14 08:12:38 +01:00
|
|
|
//draw title
|
|
|
|
DrawBar(2, 2, CANVASX-2, HEADERH-1, COL_DARK);
|
2022-01-14 09:45:27 +01:00
|
|
|
WriteText(PAD+5, HEADER_TEXTY, 0x90, COL_WORK_TEXT, "ImageEditor Pro");
|
2022-01-14 08:12:38 +01:00
|
|
|
|
|
|
|
//draw header
|
|
|
|
DrawBar(CANVASX+1, CANVASY-1, Form.width-CANVASX-2, 1, COL_LINE);
|
|
|
|
draw_acive_panel();
|
2022-01-15 17:31:40 +01:00
|
|
|
draw_window_manipulation_buttons(7);
|
2022-01-14 08:12:38 +01:00
|
|
|
|
|
|
|
//left panel bg
|
|
|
|
DrawBar(2, 1+HEADERH, CANVASX-2, Form.cheight-2-HEADERH, COL_WORK);
|
|
|
|
|
|
|
|
if (main_image.h > canvas.h) && (main_image.w > canvas.w) {
|
|
|
|
DrawBar(CANVASX+canvas.w, CANVASY+canvas.h, scroll_v.size_x+1, scroll_h.size_y+1, COL_WORK);
|
2022-01-08 20:52:20 +01:00
|
|
|
}
|
2021-12-05 00:24:31 +01:00
|
|
|
|
2022-01-08 20:52:20 +01:00
|
|
|
#define GAP_S TOOLBAR_ITEM_H+8
|
|
|
|
#define GAP_B TOOLBAR_ITEM_H+23
|
2022-01-14 08:12:38 +01:00
|
|
|
tx.set(PAD-GAP_S+HEADERH);
|
2022-01-08 20:52:20 +01:00
|
|
|
//draw_tool_btn(10, ECTRL + SCAN_CODE_KEY_N, PAD, tx.inc(GAP_S), 02, "Create image", false);
|
2022-01-15 17:31:40 +01:00
|
|
|
draw_tool_btn(#event_open, ECTRL + SCAN_CODE_KEY_O, PAD, tx.inc(GAP_S), 00, "Open image ", false);
|
|
|
|
if (main_image.image) {
|
|
|
|
draw_tool_btn(#event_activate_export, ECTRL + SCAN_CODE_KEY_S, PAD, tx.inc(GAP_S), 05, "Export image", active_tool & TOOL_EXPORT);
|
|
|
|
//draw_tool_btn(#event_activate_crop, 0, PAD, tx.inc(GAP_B), 46, "Crop", active_tool & TOOL_CROP);
|
|
|
|
draw_tool_btn(#event_activate_depth, 0, PAD, tx.inc(GAP_B), 52, "Color depth ", active_tool & TOOL_COLOR_DEPTH);
|
|
|
|
draw_tool_btn(#event_activate_flprot,0, PAD, tx.inc(GAP_S), 36, "Flip/Rotate ", active_tool & TOOL_FLIP_ROTATE);
|
2022-01-15 21:30:04 +01:00
|
|
|
draw_tool_btn(#event_activate_scale, 0, PAD, tx.inc(GAP_S), 06, "Scale ", active_tool & TOOL_SCALE);
|
2022-01-15 17:31:40 +01:00
|
|
|
}
|
2022-01-08 20:52:20 +01:00
|
|
|
draw_status_bar();
|
2021-12-05 00:24:31 +01:00
|
|
|
draw_canvas();
|
|
|
|
}
|
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
void draw_window_manipulation_buttons(int y)
|
|
|
|
{
|
|
|
|
DrawBar(Form.width-65, 2, 63, HEADERH-1, COL_WORK);
|
|
|
|
img_draw stdcall(pixie_skin.image, Form.width-63, y, 57, 18, 265, 0);
|
|
|
|
DefineHiddenButton(Form.width-63, y, 28, 17, button.add(#MinimizeWindow));
|
|
|
|
DefineHiddenButton(Form.width-35, y, 28, 17, 1);
|
|
|
|
}
|
|
|
|
|
2022-01-08 20:52:20 +01:00
|
|
|
void draw_status_bar()
|
2021-12-05 00:24:31 +01:00
|
|
|
{
|
2022-01-08 20:52:20 +01:00
|
|
|
char img_info[24];
|
2022-01-14 09:45:27 +01:00
|
|
|
sprintf(#img_info, "%i\01%i\02%s", main_image.w, main_image.h, libimg_bpp[main_image.type]);
|
2022-01-14 08:12:38 +01:00
|
|
|
DrawBar(CANVASX+1, Form.cheight - STATUSBAR_H - 1, Form.cwidth - CANVASX -2, STATUSBAR_H, COL_WORK);
|
|
|
|
WriteText(CANVASX+4, Form.cheight - STATUSBAR_H + 2, 0x90, COL_WORK_TEXT, #img_info);
|
|
|
|
for (ESI=0; img_info[ESI]!=0; ESI++) {
|
|
|
|
if (img_info[ESI] == '\01') img_info[ESI]='x';
|
|
|
|
else if (img_info[ESI] == '\02') img_info[ESI]='@';
|
|
|
|
else img_info[ESI]=' ';
|
|
|
|
}
|
|
|
|
ECX = 0x90 << 24 + COL_BUTTON_TEXT;
|
|
|
|
$int 64
|
2021-12-05 00:24:31 +01:00
|
|
|
}
|
|
|
|
|
2022-01-14 09:45:27 +01:00
|
|
|
int draw_tool_btn(dword _event, _hotkey, _x, _y, _icon_n, _text, _active)
|
2021-12-05 00:24:31 +01:00
|
|
|
{
|
2022-01-14 09:45:27 +01:00
|
|
|
dword img_ptr = icons18.image;
|
2022-01-15 17:31:40 +01:00
|
|
|
|
|
|
|
int w = 32; //default width: icon only
|
|
|
|
if (_text) {
|
|
|
|
w = strlen(_text) * 8 + 15;
|
|
|
|
if (_icon_n!=-1) w += 26;
|
|
|
|
}
|
|
|
|
|
2022-01-14 09:45:27 +01:00
|
|
|
if (_active==-1) {
|
|
|
|
$push COL_LIGHT
|
2022-01-14 09:48:57 +01:00
|
|
|
EDX = COL_LINE;
|
2022-01-14 09:45:27 +01:00
|
|
|
} else if (_active) {
|
2022-01-14 08:12:38 +01:00
|
|
|
img_ptr = icons18a.image;
|
2022-01-14 09:45:27 +01:00
|
|
|
$push COL_BUTTON_TEXT
|
2022-01-14 09:48:57 +01:00
|
|
|
EDX = COL_BUTTON;
|
2022-01-14 09:45:27 +01:00
|
|
|
|
2022-01-14 08:12:38 +01:00
|
|
|
} else {
|
2022-01-14 09:45:27 +01:00
|
|
|
$push COL_WORK_TEXT
|
2022-01-14 08:12:38 +01:00
|
|
|
EDX = COL_LIGHT;
|
2022-01-14 09:45:27 +01:00
|
|
|
}
|
2022-01-08 20:52:20 +01:00
|
|
|
DrawBar(_x, _y, w, TOOLBAR_ITEM_H+1, EDX);
|
2022-01-14 08:12:38 +01:00
|
|
|
PutPixel(_x,_y,COL_WORK);
|
|
|
|
PutPixel(_x,_y+TOOLBAR_ITEM_H,COL_WORK);
|
|
|
|
PutPixel(_x+w-1,_y,COL_WORK);
|
|
|
|
PutPixel(_x+w-1,_y+TOOLBAR_ITEM_H,COL_WORK);
|
2021-12-05 00:24:31 +01:00
|
|
|
if (_event) DefineHiddenButton(_x, _y, w, TOOLBAR_ITEM_H, button.add(_event));
|
2022-01-08 20:52:20 +01:00
|
|
|
if (_hotkey) key.add_n(_hotkey, _event);
|
|
|
|
if (_icon_n!=-1) {
|
2022-01-14 08:12:38 +01:00
|
|
|
#define ISIZE 18
|
|
|
|
img_draw stdcall(img_ptr, _x+7, _y+4, ISIZE, ISIZE, 0, _icon_n*ISIZE);
|
2022-01-08 20:52:20 +01:00
|
|
|
_x += PAD+ISIZE+2;
|
|
|
|
} else {
|
|
|
|
_x += 7;
|
|
|
|
}
|
2022-01-14 09:45:27 +01:00
|
|
|
$pop EDX
|
2022-01-08 20:52:20 +01:00
|
|
|
if (_text) {
|
|
|
|
WriteText(_x, _y+6, 0x90, EDX, _text);
|
|
|
|
}
|
2022-01-14 09:45:27 +01:00
|
|
|
return w;
|
2021-12-05 00:24:31 +01:00
|
|
|
}
|
|
|
|
|
2022-01-14 08:12:38 +01:00
|
|
|
void draw_canvas()
|
2021-12-05 00:24:31 +01:00
|
|
|
{
|
2022-01-14 08:12:38 +01:00
|
|
|
int content_w = math.min(main_image.w, canvas.w-1);
|
|
|
|
int content_h = math.min(main_image.h, canvas.h);
|
|
|
|
if (main_image.image) {
|
|
|
|
img_draw stdcall(main_image.image, CANVASX+1, CANVASY,
|
|
|
|
content_w, content_h, scroll_h.position, scroll_v.position);
|
|
|
|
}
|
|
|
|
DrawBar(CANVASX+1+content_w, CANVASY, canvas.w - content_w - 1, content_h, COL_DARK);
|
|
|
|
DrawBar(CANVASX+1, CANVASY+content_h, canvas.w - 1, canvas.h - content_h, COL_DARK);
|
|
|
|
//Draw scroll V
|
2021-12-05 00:24:31 +01:00
|
|
|
scroll_v.max_area = main_image.h;
|
2022-01-14 08:12:38 +01:00
|
|
|
scroll_v.cur_area = scroll_v.size_y = canvas.h + 1;
|
|
|
|
scroll_v.start_x = CANVASX + canvas.w;
|
2021-12-05 00:24:31 +01:00
|
|
|
if (main_image.h > canvas.h) scrollbar_v_draw stdcall (#scroll_v);
|
2022-01-14 08:12:38 +01:00
|
|
|
//Draw scroll H
|
2021-12-05 00:24:31 +01:00
|
|
|
scroll_h.max_area = main_image.w;
|
|
|
|
scroll_h.cur_area = scroll_h.size_x = canvas.w;
|
2022-01-14 08:12:38 +01:00
|
|
|
scroll_h.start_y = CANVASY + canvas.h;
|
2021-12-05 00:24:31 +01:00
|
|
|
if (main_image.w > canvas.w) scrollbar_h_draw stdcall (#scroll_h);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-01-14 08:12:38 +01:00
|
|
|
void set_file_path(char* _new_title)
|
2021-12-05 00:24:31 +01:00
|
|
|
{
|
2022-01-14 08:12:38 +01:00
|
|
|
strcpy(#param, _new_title);
|
|
|
|
draw_status_bar();
|
2021-12-05 00:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void open_image(char* _path)
|
|
|
|
{
|
|
|
|
main_image.load(_path);
|
2022-01-14 08:12:38 +01:00
|
|
|
set_file_path(_path);
|
2021-12-05 00:24:31 +01:00
|
|
|
scroll_v.position = 0;
|
|
|
|
scroll_h.position = 0;
|
|
|
|
}
|
|
|
|
|
2022-01-14 09:45:27 +01:00
|
|
|
void event_set_color_depth() {
|
2022-01-15 17:31:40 +01:00
|
|
|
img_convert stdcall(main_image.image, 0, pressed_button_id-color_depth_btnid_1, 0, 0);
|
2022-01-14 09:45:27 +01:00
|
|
|
if (!EAX) {
|
2022-01-15 17:31:40 +01:00
|
|
|
notify("'ImageEdit Pro\nNot possible to convert into specified color depth' -Et");
|
2022-01-14 09:45:27 +01:00
|
|
|
} else {
|
|
|
|
$push eax
|
2022-01-14 09:48:57 +01:00
|
|
|
img_destroy stdcall(main_image.image);
|
|
|
|
$pop eax
|
|
|
|
main_image.image = EAX;
|
2022-01-14 09:45:27 +01:00
|
|
|
main_image.set_vars();
|
|
|
|
draw_acive_panel();
|
|
|
|
draw_status_bar();
|
2022-01-14 20:34:48 +01:00
|
|
|
draw_canvas();
|
2022-01-14 09:45:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 21:30:04 +01:00
|
|
|
void WritePanelText(int _x, _text) { WriteText(_x, HEADER_TEXTY, 0x90, COL_WORK_TEXT, _text); }
|
2022-01-14 08:12:38 +01:00
|
|
|
void draw_acive_panel()
|
|
|
|
{
|
2022-01-14 09:45:27 +01:00
|
|
|
int i, x = CANVASX + PAD;
|
|
|
|
bool a;
|
2022-01-15 17:31:40 +01:00
|
|
|
DrawBar(CANVASX+1, 2, Form.width-CANVASX-64, HEADERH-1, COL_WORK);
|
2022-01-14 08:12:38 +01:00
|
|
|
switch(active_tool) {
|
2022-01-15 17:31:40 +01:00
|
|
|
case TOOL_EXPORT:
|
|
|
|
WritePanelText(CANVASX+PAD, "Format");
|
|
|
|
x += 6*8 + PAD;
|
|
|
|
x += draw_tool_btn(#event_save_png, 0, x, 7, -1, "PNG", saving_type & SAVE_AS_PNG) + PAD;
|
|
|
|
x += draw_tool_btn(#event_save_pnm, 0, x, 7, -1, "PNM", saving_type & SAVE_AS_PNM) + PAD;
|
|
|
|
x += draw_tool_btn(#event_save_bmp, 0, x, 7, -1, "BMP", saving_type & SAVE_AS_BMP) + PAD + PAD;
|
2022-01-15 21:30:04 +01:00
|
|
|
if (saving_type) draw_tool_btn(#event_save, 0, x, 7, 53, "Export", false);
|
2022-01-15 17:31:40 +01:00
|
|
|
break;
|
2022-01-14 08:12:38 +01:00
|
|
|
case TOOL_CROP:
|
2022-01-15 17:31:40 +01:00
|
|
|
WritePanelText(CANVASX+PAD, "Crop tool");
|
2022-01-14 08:12:38 +01:00
|
|
|
break;
|
2022-01-15 21:30:04 +01:00
|
|
|
case TOOL_SCALE:
|
|
|
|
WritePanelText(CANVASX+PAD, "New size x");
|
|
|
|
DefineHiddenButton(edit_w.left-2, edit_w.top-2, 148, 25, 2+BT_NOFRAME);
|
|
|
|
DrawEditBox(#edit_w);
|
|
|
|
DrawEditBox(#edit_h);
|
|
|
|
keep_ratio.draw(CANVASX + PAD + 233, HEADER_TEXTY);
|
|
|
|
draw_tool_btn(#event_scale, SCAN_CODE_ENTER, CANVASX + PAD + 370, 7, -1, "Apply", false);
|
2022-01-14 08:12:38 +01:00
|
|
|
break;
|
|
|
|
case TOOL_COLOR_DEPTH:
|
2022-01-15 17:31:40 +01:00
|
|
|
WritePanelText(CANVASX+PAD, "Color depth");
|
2022-01-14 09:45:27 +01:00
|
|
|
x += 11*8 + PAD;
|
2022-01-15 17:31:40 +01:00
|
|
|
color_depth_btnid_1 = button.new_id;
|
2022-01-14 09:45:27 +01:00
|
|
|
for (i=1; i<11; i++) {
|
2022-01-15 17:31:40 +01:00
|
|
|
DeleteButton(color_depth_btnid_1+i);
|
2022-01-14 09:45:27 +01:00
|
|
|
if (main_image.type == i) {
|
2022-01-15 17:31:40 +01:00
|
|
|
a = true; //this is current image depth
|
2022-01-14 09:45:27 +01:00
|
|
|
} else {
|
2022-01-15 17:31:40 +01:00
|
|
|
a = false; //this is image depth we can set
|
2022-01-14 09:45:27 +01:00
|
|
|
//probe does libimg support converting current image gepth to i-one
|
|
|
|
img_create stdcall(1, 1, main_image.type);
|
|
|
|
img_convert stdcall(EAX, 0, i, 0, 0);
|
|
|
|
if (EAX) {
|
|
|
|
img_destroy stdcall(EAX);
|
|
|
|
} else {
|
|
|
|
a = -1;
|
2022-01-15 21:30:04 +01:00
|
|
|
if (Form.width-CANVASX-64 < 600) {
|
2022-01-15 17:31:40 +01:00
|
|
|
button.add(1);
|
|
|
|
continue;
|
|
|
|
}
|
2022-01-14 09:45:27 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-15 21:30:04 +01:00
|
|
|
x += draw_tool_btn(#event_set_color_depth, SCAN_CODE_ENTER, x, 7, -1, libimg_bpp[i], a) + 6;
|
2022-01-14 09:45:27 +01:00
|
|
|
}
|
2022-01-14 08:12:38 +01:00
|
|
|
break;
|
|
|
|
case TOOL_FLIP_ROTATE:
|
2022-01-15 17:31:40 +01:00
|
|
|
WritePanelText(CANVASX+PAD, "Flip");
|
2022-01-14 08:12:38 +01:00
|
|
|
draw_tool_btn(#event_flip_hor, ECTRL + SCAN_CODE_KEY_H, CANVASX + PAD + 040, 7, 34, NULL, false);
|
|
|
|
draw_tool_btn(#event_flip_ver, ECTRL + SCAN_CODE_KEY_V, CANVASX + PAD + 080, 7, 35, NULL, false);
|
2022-01-15 17:31:40 +01:00
|
|
|
WritePanelText(CANVASX+PAD + 142, "Rotate");
|
|
|
|
draw_tool_btn(#event_rotate_left, ECTRL + SCAN_CODE_KEY_L, CANVASX + PAD + 200, 7, 37, NULL, false);
|
|
|
|
draw_tool_btn(#event_rotate_right, ECTRL + SCAN_CODE_KEY_R, CANVASX + PAD + 240, 7, 36, NULL, false);
|
|
|
|
// WritePanelText(CANVASX+PAD + 142, "Move");
|
|
|
|
//draw_tool_btn(#event_move_left, ECTRL + SCAN_CODE_LEFT, PAD, tx.inc(GAP_B), 30, false);
|
|
|
|
//draw_tool_btn(#event_move_right, ECTRL + SCAN_CODE_RIGHT, PAD, tx.inc(GAP_S), 31, false);
|
|
|
|
//draw_tool_btn(#event_move_up, ECTRL + SCAN_CODE_UP, PAD, tx.inc(GAP_S), 32, false);
|
|
|
|
//draw_tool_btn(#event_move_down, ECTRL + SCAN_CODE_DOWN, PAD, tx.inc(GAP_S), 33, false);
|
2022-01-14 08:12:38 +01:00
|
|
|
break;
|
|
|
|
default:
|
2022-01-15 17:31:40 +01:00
|
|
|
if (!param) WritePanelText(CANVASX+PAD, "Welcome to ImageEditor Pro! Try to open a file.");
|
2022-01-14 08:12:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 00:24:31 +01:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// EVENTS //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2022-01-15 17:31:40 +01:00
|
|
|
void event_save_png() { saving_type = SAVE_AS_PNG; draw_acive_panel(); }
|
|
|
|
void event_save_bmp() { saving_type = SAVE_AS_BMP; draw_acive_panel(); }
|
|
|
|
void event_save_raw() { saving_type = SAVE_AS_RAW; draw_acive_panel(); }
|
|
|
|
void event_save_pnm() { saving_type = SAVE_AS_PNM; draw_acive_panel(); }
|
|
|
|
void event_activate_export() { active_tool = TOOL_EXPORT; draw_content(); }
|
|
|
|
void event_activate_crop() { active_tool = TOOL_CROP; draw_content(); }
|
2022-01-15 21:30:04 +01:00
|
|
|
void event_activate_scale() { active_tool = TOOL_SCALE; set_text_scale_edits(); draw_content(); }
|
2022-01-15 17:31:40 +01:00
|
|
|
void event_activate_depth() { active_tool = TOOL_COLOR_DEPTH; draw_content(); }
|
|
|
|
void event_activate_flprot() { active_tool = TOOL_FLIP_ROTATE; draw_content(); }
|
|
|
|
|
2022-01-15 21:30:04 +01:00
|
|
|
void set_text_scale_edits()
|
|
|
|
{
|
|
|
|
edit_box_set_text stdcall (#edit_w, itoa(main_image.w));
|
|
|
|
edit_box_set_text stdcall (#edit_h, itoa(main_image.h));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale, _inter, _param1, _param2 ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? scale _image ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> [_src] = pointer to source image ;;
|
|
|
|
;> [_crop_x] = left coord of cropping rect ;;
|
|
|
|
;> [_crop_y] = top coord of cropping rect ;;
|
|
|
|
;> [_crop_width] = width of cropping rect ;;
|
|
|
|
;> [_crop_height] = height of cropping rect ;;
|
|
|
|
;> [_dst] = pointer to resulting image, 0 to create new one ;;
|
|
|
|
;> [_scale] = scaling method, see libimg.inc (LIBIMG_SCALE_*) ;;
|
|
|
|
;> [_inter] = interpolation algorithm, see libimg.inc (LIBIMG_INTER_*) ;;
|
|
|
|
;> [_param1] = depends on _scale, see libimg.inc ;;
|
|
|
|
;> [_param2] = depends on _scale, see libimg.inc ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to scaled image ;;
|
|
|
|
;< ecx = error code / undefined ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
*/
|
|
|
|
|
|
|
|
//invoke img.scale, eax, 0, 0, [eax+Image.Width], [eax+Image.Height], 0, LIBIMG_SCALE_STRETCH, LIBIMG_INTER_DEFAULT, [view.width], [view.height]
|
|
|
|
|
|
|
|
void event_scale()
|
|
|
|
{
|
|
|
|
img_scale stdcall (main_image.image, 0, 0, main_image.w, main_image.h, 0,
|
|
|
|
LIBIMG_SCALE_STRETCH, LIBIMG_INTER_DEFAULT, atoi(#text_w), atoi(#text_h));
|
|
|
|
if (!EAX) {
|
|
|
|
if (ECX == 4) {
|
|
|
|
notify("'ImageEdit Pro\nThis color depth is not supported by Scale feature.\nPlease change color depth to 24 / 32 / 8grey.' -Et");
|
|
|
|
} else {
|
|
|
|
debugval("Error code", ECX);
|
|
|
|
notify("'ImageEdit Pro\nImage scale failed :(' -Et");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$push eax
|
|
|
|
img_destroy stdcall (main_image.image);
|
|
|
|
$pop eax
|
|
|
|
main_image.image = EAX;
|
|
|
|
main_image.set_vars();
|
|
|
|
draw_canvas();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 00:24:31 +01:00
|
|
|
void event_open()
|
|
|
|
{
|
|
|
|
o_dialog.type = 0; //open file
|
|
|
|
OpenDialog_start stdcall (#o_dialog);
|
|
|
|
if (o_dialog.status) {
|
|
|
|
open_image(#openfile_path);
|
2022-01-15 21:30:04 +01:00
|
|
|
active_tool = NULL;
|
2022-01-14 20:34:48 +01:00
|
|
|
draw_window();
|
2021-12-05 00:24:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void event_flip_hor()
|
|
|
|
{
|
|
|
|
img_flip stdcall (main_image.image, FLIP_HORIZONTAL);
|
|
|
|
draw_canvas();
|
|
|
|
}
|
|
|
|
|
|
|
|
void event_flip_ver()
|
|
|
|
{
|
|
|
|
img_flip stdcall (main_image.image, FLIP_VERTICAL);
|
|
|
|
draw_canvas();
|
|
|
|
}
|
|
|
|
|
2022-01-14 08:12:38 +01:00
|
|
|
void event_rotate_left()
|
|
|
|
{
|
|
|
|
img_rotate stdcall (main_image.image, ROTATE_270_CW);
|
|
|
|
main_image.w >< main_image.h;
|
|
|
|
draw_content();
|
|
|
|
}
|
|
|
|
|
|
|
|
void event_rotate_right()
|
2021-12-05 00:24:31 +01:00
|
|
|
{
|
|
|
|
img_rotate stdcall (main_image.image, ROTATE_90_CW);
|
|
|
|
main_image.w >< main_image.h;
|
2022-01-14 08:12:38 +01:00
|
|
|
draw_content();
|
2021-12-05 00:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void event_save()
|
|
|
|
{
|
2022-01-15 17:31:40 +01:00
|
|
|
dword _image_format, _image_depth;
|
|
|
|
strcpy(#filename_area, #param + strrchr(#param, '/'));
|
|
|
|
if (EAX = strrchr(#filename_area, '.')) filename_area[EAX-1] = '\0';
|
2022-01-08 20:52:20 +01:00
|
|
|
switch (saving_type) {
|
|
|
|
case SAVE_AS_PNG:
|
2022-01-15 17:31:40 +01:00
|
|
|
strcat(#filename_area, "_IEP.png");
|
|
|
|
_image_format = LIBIMG_FORMAT_PNG;
|
|
|
|
_image_depth = IMAGE_BPP24;
|
2022-01-08 20:52:20 +01:00
|
|
|
break;
|
|
|
|
case SAVE_AS_BMP:
|
2022-01-15 17:31:40 +01:00
|
|
|
strcat(#filename_area, "_IEP.bmp");
|
|
|
|
_image_format = LIBIMG_FORMAT_BMP;
|
|
|
|
_image_depth = IMAGE_BPP24;
|
|
|
|
break;
|
|
|
|
case SAVE_AS_PNM:
|
|
|
|
strcat(#filename_area, "_IEP.pnm");
|
|
|
|
_image_format = LIBIMG_FORMAT_PNM;
|
|
|
|
_image_depth = IMAGE_BPP24;
|
2022-01-08 20:52:20 +01:00
|
|
|
break;
|
|
|
|
case SAVE_AS_RAW:
|
|
|
|
notify("Not implemented yet.");
|
2022-01-15 17:31:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
o_dialog.type = 1; //save file
|
|
|
|
OpenDialog_start stdcall (#o_dialog);
|
|
|
|
if (o_dialog.status) {
|
|
|
|
set_file_path(#openfile_path);
|
|
|
|
img_convert stdcall(main_image.image, 0, _image_depth, 0, 0);
|
|
|
|
if (!EAX) {
|
|
|
|
notify("'ImageEdit Pro\nCan not convert image into specified color depth' -Et");
|
|
|
|
} else {
|
|
|
|
$push eax //converted data
|
|
|
|
img_encode stdcall(EAX, _image_format, 0); //<=EAX data, ECX size
|
|
|
|
$push eax //encoded data
|
|
|
|
CreateFile(ECX, EAX, #openfile_path);
|
|
|
|
$pop ecx
|
|
|
|
free(ECX);
|
|
|
|
$pop eax
|
|
|
|
img_destroy stdcall(EAX);
|
|
|
|
}
|
2022-01-08 20:52:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void event_scroll_canvas(int _direction)
|
|
|
|
{
|
|
|
|
switch(_direction) {
|
|
|
|
case SCAN_CODE_DOWN:
|
|
|
|
scroll_v.position = math.min(scroll_v.position+25,
|
|
|
|
scroll_v.max_area - scroll_v.cur_area);
|
|
|
|
break;
|
|
|
|
case SCAN_CODE_UP:
|
|
|
|
scroll_v.position = math.max(scroll_v.position-25, 0);
|
|
|
|
break;
|
|
|
|
case SCAN_CODE_RIGHT:
|
|
|
|
scroll_h.position = math.min(scroll_h.position+25,
|
|
|
|
scroll_h.max_area - scroll_h.cur_area);
|
|
|
|
break;
|
|
|
|
case SCAN_CODE_LEFT:
|
|
|
|
scroll_h.position = math.max(scroll_h.position-25, 0);
|
2021-12-05 00:24:31 +01:00
|
|
|
}
|
2022-01-08 20:52:20 +01:00
|
|
|
draw_canvas();
|
2021-12-05 00:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stop:
|
|
|
|
|