Subversion Repositories Kolibri OS

Rev

Rev 9851 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 1024*100
  2.  
  3. /*=====================================================
  4. |                                                     |
  5. |                         LIB                         |
  6. |                                                     |
  7. =====================================================*/
  8.  
  9. #include "../lib/gui.h"
  10. #include "../lib/random.h"
  11. #include "../lib/mem.h"
  12. #include "../lib/cursor.h"
  13. #include "../lib/list_box.h"
  14. #include "../lib/events.h"
  15.  
  16. #include "../lib/obj/libimg.h"
  17. #include "../lib/obj/box_lib.h"
  18. #include "../lib/obj/proc_lib.h"
  19.  
  20. #include "../lib/patterns/rgb.h"
  21. #include "../lib/patterns/toolbar_button.h"
  22. #include "../lib/patterns/simple_open_dialog.h"
  23.  
  24. /*=====================================================
  25. |                                                     |
  26. |                        DATA                         |
  27. |                                                     |
  28. =====================================================*/
  29.  
  30. #include "data.h"
  31.  
  32. /*=====================================================
  33. |                                                     |
  34. |                        CODE                         |
  35. |                                                     |
  36. =====================================================*/
  37.  
  38. void main()
  39. {
  40.         /* Init external libraries */
  41.         load_dll(libimg, #libimg_init, 1);
  42.         load_dll(boxlib, #box_lib_init,0);
  43.         load_dll(Proc_lib, #OpenDialog_init,0);
  44.         OpenDialog_init stdcall (#o_dialog);
  45.  
  46.         /* Init UI */
  47.         icons18.load("/sys/icons16.png");
  48.         icons18.replace_2colors(0xffFFFfff, COL_LIGHT, 0xffCACBD6, COL_LIGHT-0x080808);
  49.         icons18a.load("/sys/icons16.png");
  50.         icons18a.replace_2colors(0xffFFFfff, COL_BUTTON, 0xffCACBD6, 0);
  51.         pixie_skin.load("/sys/media/pixieskn.png");
  52.         Form.width = screen.w/6*5;
  53.         Form.height = screen.h/6*5;
  54.         sc.work = COL_WORK;
  55.         sc.work_text = COL_WORK_TEXT;
  56.         sc.light = COL_LIGHT;
  57.         sc.dark = COL_DARK;
  58.         sc.line = COL_LINE;
  59.         sc.button = COL_BUTTON;
  60.         sc.button_text = COL_BUTTON_TEXT;
  61.  
  62.         /* Handle application parameters */
  63.         //if (!param) open_image("/sys/home.png");
  64.  
  65.         /* Set event mask and go to main loop */
  66.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  67.         loop() switch(WaitEvent())
  68.         {
  69.                 case evMouse:
  70.                         mouse.get();
  71.                         if (main_image.h > canvas.h) scrollbar_v_mouse stdcall(#scroll_v);
  72.                         if (main_image.w > canvas.w) scrollbar_h_mouse stdcall(#scroll_h);
  73.                         if (active_tool == TOOL_SCALE) {
  74.                                 edit_box_mouse stdcall (#edit_w);
  75.                                 edit_box_mouse stdcall (#edit_h);
  76.                         }
  77.                         if (scroll_v.delta) || (scroll_h.delta) draw_canvas();
  78.                         if (EAX = mouse.vert) {
  79.                                 if (EAX<10) event_scroll_canvas(SCAN_CODE_DOWN);
  80.                                 else event_scroll_canvas(SCAN_CODE_UP);
  81.                         } if (EAX = mouse.hor) {
  82.                                 if (EAX<10) event_scroll_canvas(SCAN_CODE_RIGHT);
  83.                                 else event_scroll_canvas(SCAN_CODE_LEFT);
  84.                         }
  85.                         break;
  86.  
  87.                 case evButton:
  88.                         pressed_button_id = GetButtonID();
  89.                         if (pressed_button_id==1) ExitProcess();
  90.                         keep_ratio.click(pressed_button_id);
  91.                         button.press(pressed_button_id);
  92.                         break;
  93.  
  94.                 case evKey:
  95.                         GetKeys();
  96.                         if (active_tool == TOOL_SCALE)
  97.                         && (edit_w.flags & ed_focus) || (edit_h.flags & ed_focus) {
  98.                                 if (key_scancode == SCAN_CODE_TAB) {
  99.                                         edit_w.flags >< edit_h.flags;
  100.                                         draw_acive_panel();
  101.                                         break;
  102.                                 }
  103.                                 if (edit_w.flags & ed_focus) {
  104.                                         edit_box_key_c stdcall (#edit_w, key_editbox);
  105.                                         if (keep_ratio.checked) && (text_w) && (atoi(#text_w)) {
  106.                                                 EDI = main_image.h*100 / calc(main_image.w*100 / atoi(#text_w));
  107.                                                 edit_box_set_text stdcall (#edit_h, itoa(EDI));
  108.                                                 edit_box_draw stdcall (#edit_h);
  109.                                         }
  110.                                 } else {
  111.                                         edit_box_key_c stdcall (#edit_h, key_editbox);
  112.                                         if (keep_ratio.checked) && (text_h) && (atoi(#text_h)) {
  113.                                                 EDI = main_image.h*100 / calc(main_image.w*100 / atoi(#text_h));
  114.                                                 edit_box_set_text stdcall (#edit_w, itoa(EDI));
  115.                                                 edit_box_draw stdcall (#edit_w);
  116.                                         }
  117.                                 }
  118.                                 break;
  119.                         }
  120.                         if (key_scancode == SCAN_CODE_DOWN) event_scroll_canvas(SCAN_CODE_DOWN);
  121.                         if (key_scancode == SCAN_CODE_UP) event_scroll_canvas(SCAN_CODE_UP);
  122.                         if (key_scancode == SCAN_CODE_LEFT) event_scroll_canvas(SCAN_CODE_LEFT);
  123.                         if (key_scancode == SCAN_CODE_RIGHT) event_scroll_canvas(SCAN_CODE_RIGHT);
  124.                         key.press(key_scancode);
  125.                         break;
  126.  
  127.                 case evReDraw:
  128.                         draw_window();
  129.                         break;
  130.         }
  131. }
  132.  
  133. void draw_window()
  134. {
  135.         DefineAndDrawWindow(screen.w-Form.width/2, screen.h-Form.height/2, Form.width, Form.height, 0x42, NULL, NULL, 0);
  136.         GetProcessInfo(#Form, SelfInfo);
  137.         /* Draw window borders */
  138.         DrawRectangle(0,0,Form.width,Form.height,COL_LINE);
  139.         DrawRectangle(1,1,Form.width-2,Form.height-2,COL_LIGHT);
  140.         /* Check if the window is collapsed into header */
  141.         if (Form.status_window&ROLLED_UP) {
  142.                 DrawBar(2, 2, Form.width-3, skin_h-4, COL_WORK);
  143.                 WriteText(5, skin_h-11/2, 0x90, COL_WORK_TEXT, "ImageEditor Pro [Collapsed]");
  144.                 draw_window_manipulation_buttons(skin_h-17/2);
  145.                 return;
  146.         }
  147.         if (Form.width  < 560) { MoveSize(OLD,OLD,560,OLD); return; }
  148.         if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
  149.         draw_content();
  150. }
  151.  
  152. void draw_content()
  153. {
  154.         incn tx;
  155.         button.init(40);
  156.         key.init(40);
  157.  
  158.         canvas.w = Form.cwidth - CANVASX - 1;
  159.         canvas.h = Form.cheight - STATUSBAR_H - CANVASY - 1;
  160.         if (main_image.h > canvas.h) canvas.w -= scroll_v.size_x + 1;
  161.         if (main_image.w > canvas.w) canvas.h -= scroll_h.size_y + 1;
  162.  
  163.         scroll_v.all_redraw = scroll_h.all_redraw = 1;
  164.  
  165.         //draw panel border
  166.         DrawBar(CANVASX, 0, 1, Form.cheight, COL_LINE);
  167.  
  168.         //draw title
  169.         DrawBar(2, 2, CANVASX-2, HEADERH-1, COL_DARK);
  170.         WriteText(PAD+5, HEADER_TEXTY, 0x90, COL_WORK_TEXT, "ImageEditor Pro");
  171.  
  172.         //draw header
  173.         DrawBar(CANVASX+1, CANVASY-1, Form.width-CANVASX-2, 1, COL_LINE);
  174.         draw_acive_panel();
  175.         draw_window_manipulation_buttons(7);
  176.  
  177.         //left panel bg
  178.         DrawBar(2, 1+HEADERH, CANVASX-2, Form.cheight-2-HEADERH, COL_WORK);
  179.  
  180.         if (main_image.h > canvas.h) && (main_image.w > canvas.w) {
  181.                 DrawBar(CANVASX+canvas.w, CANVASY+canvas.h, scroll_v.size_x+1, scroll_h.size_y+1, COL_WORK);
  182.         }
  183.  
  184.         #define GAP_S TOOLBAR_ITEM_H+8
  185.         #define GAP_B TOOLBAR_ITEM_H+23
  186.         tx.set(PAD-GAP_S+HEADERH);
  187.         //draw_tool_btn(10, ECTRL + SCAN_CODE_KEY_N, PAD, tx.inc(GAP_S), 02, "Create image", false);
  188.         draw_tool_btn(#event_open, ECTRL + SCAN_CODE_KEY_O, PAD, tx.inc(GAP_S), 00, "Open image  ", false);
  189.         if (main_image.image) {
  190.                 draw_tool_btn(#event_activate_export, ECTRL + SCAN_CODE_KEY_S, PAD, tx.inc(GAP_S), 05, "Export image", active_tool & TOOL_EXPORT);
  191.                 //draw_tool_btn(#event_activate_crop,  0, PAD, tx.inc(GAP_B), 46, "Crop", active_tool & TOOL_CROP);
  192.                 draw_tool_btn(#event_activate_depth, 0, PAD, tx.inc(GAP_B), 52, "Color depth ", active_tool & TOOL_COLOR_DEPTH);
  193.                 draw_tool_btn(#event_activate_flprot,0, PAD, tx.inc(GAP_S), 36, "Flip/Rotate ", active_tool & TOOL_FLIP_ROTATE);               
  194.                 draw_tool_btn(#event_activate_scale, 0, PAD, tx.inc(GAP_S), 06, "Scale       ", active_tool & TOOL_SCALE);
  195.         }
  196.         draw_status_bar();
  197.         draw_canvas();
  198. }
  199.  
  200. void draw_window_manipulation_buttons(int y)
  201. {
  202.         DrawBar(Form.width-65, 2, 63, HEADERH-1, COL_WORK);
  203.         img_draw stdcall(pixie_skin.image, Form.width-63, y, 57, 18, 265, 0);
  204.         DefineHiddenButton(Form.width-63, y, 28, 17, button.add(#MinimizeWindow));
  205.         DefineHiddenButton(Form.width-35, y, 28, 17, 1);
  206. }
  207.  
  208. void draw_status_bar()
  209. {
  210.         char img_info[24];
  211.         sprintf(#img_info, "%i\01%i\02%s", main_image.w, main_image.h, libimg_bpp[main_image.type]);
  212.         DrawBar(CANVASX+1, Form.cheight - STATUSBAR_H - 1, Form.cwidth - CANVASX -2, STATUSBAR_H, COL_WORK);
  213.         WriteText(CANVASX+4, Form.cheight - STATUSBAR_H + 2, 0x90, COL_WORK_TEXT, #img_info);
  214.         for (ESI=0; img_info[ESI]!=0; ESI++) {
  215.                 if (img_info[ESI] == '\01') img_info[ESI]='x';
  216.                 else if (img_info[ESI] == '\02') img_info[ESI]='@';
  217.                 else img_info[ESI]=' ';
  218.         }
  219.         ECX = 0x90 << 24 + COL_BUTTON_TEXT;
  220.         $int 64
  221. }
  222.  
  223. int draw_tool_btn(dword _event, _hotkey, _x, _y, _icon_n, _text, _active)
  224. {
  225.         dword img_ptr = icons18.image;
  226.  
  227.         int w = 32; //default width: icon only
  228.         if (_text) {
  229.                 w = strlen(_text) * 8 + 15;
  230.                 if (_icon_n!=-1) w += 26;
  231.         }
  232.  
  233.         if (_active==-1) {
  234.                 $push COL_LIGHT
  235.                 EDX = COL_LINE;
  236.         } else if (_active) {
  237.                 img_ptr = icons18a.image;
  238.                 $push COL_BUTTON_TEXT
  239.                 EDX = COL_BUTTON;
  240.  
  241.         } else {
  242.                 $push COL_WORK_TEXT
  243.                 EDX = COL_LIGHT;
  244.         }
  245.         DrawBar(_x, _y, w, TOOLBAR_ITEM_H+1, EDX);
  246.         PutPixel(_x,_y,COL_WORK);
  247.         PutPixel(_x,_y+TOOLBAR_ITEM_H,COL_WORK);
  248.         PutPixel(_x+w-1,_y,COL_WORK);
  249.         PutPixel(_x+w-1,_y+TOOLBAR_ITEM_H,COL_WORK);
  250.         if (_event) DefineHiddenButton(_x, _y, w, TOOLBAR_ITEM_H, button.add(_event));
  251.         if (_hotkey) key.add_n(_hotkey, _event);
  252.         if (_icon_n!=-1) {
  253.                 #define ISIZE 18
  254.                 img_draw stdcall(img_ptr, _x+7, _y+4, ISIZE, ISIZE, 0, _icon_n*ISIZE);
  255.                 _x += PAD+ISIZE+2;
  256.         } else {
  257.                 _x += 7;
  258.         }
  259.         $pop EDX
  260.         if (_text) {
  261.                 WriteText(_x, _y+6, 0x90, EDX, _text);
  262.         }
  263.         return w;
  264. }
  265.  
  266. void draw_canvas()
  267. {
  268.         int content_w = math.min(main_image.w, canvas.w-1);
  269.         int content_h = math.min(main_image.h, canvas.h);
  270.         //Draw scroll V
  271.         scroll_v.max_area = main_image.h;
  272.         scroll_v.cur_area = scroll_v.size_y = canvas.h + 1;
  273.         scroll_v.start_x = CANVASX + canvas.w;
  274.         if (main_image.h > canvas.h) scrollbar_v_draw stdcall (#scroll_v);
  275.         //Draw scroll H
  276.         scroll_h.max_area = main_image.w;
  277.         scroll_h.cur_area = scroll_h.size_x = canvas.w;
  278.         scroll_h.start_y = CANVASY + canvas.h;
  279.         if (main_image.w > canvas.w) scrollbar_h_draw stdcall (#scroll_h);
  280.         //Draw Image   
  281.         if (main_image.image) {
  282.                 img_draw stdcall(main_image.image, CANVASX+1, CANVASY,
  283.                 content_w, content_h, scroll_h.position, scroll_v.position);
  284.         }
  285.         DrawBar(CANVASX+1+content_w, CANVASY, canvas.w - content_w - 1, content_h, COL_DARK);
  286.         DrawBar(CANVASX+1, CANVASY+content_h, canvas.w - 1, canvas.h - content_h, COL_DARK);
  287.  
  288. }
  289.  
  290. void set_file_path(char* _new_title)
  291. {
  292.         strcpy(#param, _new_title);
  293.         draw_status_bar();
  294. }
  295.  
  296. void open_image(char* _path)
  297. {
  298.         main_image.load(_path);
  299.         set_file_path(_path);
  300.         scroll_v.position = 0;
  301.         scroll_h.position = 0;
  302. }
  303.  
  304. void event_set_color_depth() {
  305.         img_convert stdcall(main_image.image, 0, pressed_button_id-color_depth_btnid_1, 0, 0);
  306.         if (!EAX) {
  307.                 notify("'ImageEdit Pro\nNot possible to convert into specified color depth' -Et");
  308.         } else {
  309.                 $push eax
  310.                 img_destroy stdcall(main_image.image);
  311.                 $pop eax
  312.                 main_image.image = EAX;
  313.                 main_image.set_vars();
  314.                 draw_acive_panel();
  315.                 draw_status_bar();
  316.                 draw_canvas();
  317.         }
  318. }
  319.  
  320. void WritePanelText(int _x, _text) { WriteText(_x, HEADER_TEXTY, 0x90, COL_WORK_TEXT, _text); }
  321. void draw_acive_panel()
  322. {
  323.         int i, x = CANVASX + PAD;
  324.         bool a;
  325.         DrawBar(CANVASX+1, 2, Form.width-CANVASX-64, HEADERH-1, COL_WORK);
  326.         switch(active_tool) {
  327.                 case TOOL_EXPORT:
  328.                         WritePanelText(CANVASX+PAD, "Format");
  329.                         x += 6*8 + PAD;
  330.                         x += draw_tool_btn(#event_save_png, 0, x, 7, -1, "PNG", saving_type & SAVE_AS_PNG) + PAD;
  331.                         x += draw_tool_btn(#event_save_pnm, 0, x, 7, -1, "PNM", saving_type & SAVE_AS_PNM) + PAD;
  332.                         x += draw_tool_btn(#event_save_bmp, 0, x, 7, -1, "BMP", saving_type & SAVE_AS_BMP) + PAD + PAD;
  333.                         if (saving_type) draw_tool_btn(#event_save, 0, x, 7, 53, "Export", false);
  334.                         break;
  335.                 case TOOL_CROP:
  336.                         WritePanelText(CANVASX+PAD, "Crop tool");
  337.                         break;
  338.                 case TOOL_SCALE:
  339.                         WritePanelText(CANVASX+PAD, "New size          x");
  340.                         DefineHiddenButton(edit_w.left-2, edit_w.top-2, 148, 25, 2+BT_NOFRAME);
  341.                         DrawEditBox(#edit_w);
  342.                         DrawEditBox(#edit_h);
  343.                         keep_ratio.draw(CANVASX + PAD + 233, HEADER_TEXTY);
  344.                         draw_tool_btn(#event_scale, SCAN_CODE_ENTER, CANVASX + PAD + 370, 7, -1, "Apply", false);
  345.                         break;
  346.                 case TOOL_COLOR_DEPTH:
  347.                         WritePanelText(CANVASX+PAD, "Color depth");
  348.                         x += 11*8 + PAD;
  349.                         color_depth_btnid_1 = button.new_id;
  350.                         for (i=1; i<11; i++) {
  351.                                 DeleteButton(color_depth_btnid_1+i);
  352.                                 if (main_image.type == i) {
  353.                                         a = true; //this is current image depth
  354.                                 } else {
  355.                                         a = false; //this is image depth we can set
  356.                                         //probe does libimg support converting current image gepth to i-one
  357.                                         img_create stdcall(1, 1, main_image.type);
  358.                                         img_convert stdcall(EAX, 0, i, 0, 0);
  359.                                         if (EAX) {
  360.                                                 img_destroy stdcall(EAX);
  361.                                         } else {
  362.                                                 a = -1;
  363.                                                 if (Form.width-CANVASX-64 < 600) {
  364.                                                         button.add(1);
  365.                                                         continue;                                                      
  366.                                                 }
  367.                                         }
  368.                                 }
  369.                                 x += draw_tool_btn(#event_set_color_depth, SCAN_CODE_ENTER, x, 7, -1, libimg_bpp[i], a) + 6;                   
  370.                         }
  371.                         break;
  372.                 case TOOL_FLIP_ROTATE:
  373.                         WritePanelText(CANVASX+PAD, "Flip");
  374.                         draw_tool_btn(#event_flip_hor, ECTRL + SCAN_CODE_KEY_H, CANVASX + PAD + 040, 7, 34, NULL, false);
  375.                         draw_tool_btn(#event_flip_ver, ECTRL + SCAN_CODE_KEY_V, CANVASX + PAD + 080, 7, 35, NULL, false);
  376.                         WritePanelText(CANVASX+PAD + 142, "Rotate");
  377.                         draw_tool_btn(#event_rotate_left,  ECTRL + SCAN_CODE_KEY_L, CANVASX + PAD + 200, 7, 37, NULL, false);
  378.                         draw_tool_btn(#event_rotate_right, ECTRL + SCAN_CODE_KEY_R, CANVASX + PAD + 240, 7, 36, NULL, false);
  379.                         // WritePanelText(CANVASX+PAD + 142, "Move");
  380.                         //draw_tool_btn(#event_move_left,  ECTRL + SCAN_CODE_LEFT,  PAD, tx.inc(GAP_B), 30, false);
  381.                         //draw_tool_btn(#event_move_right, ECTRL + SCAN_CODE_RIGHT, PAD, tx.inc(GAP_S), 31, false);
  382.                         //draw_tool_btn(#event_move_up,    ECTRL + SCAN_CODE_UP,    PAD, tx.inc(GAP_S), 32, false);
  383.                         //draw_tool_btn(#event_move_down,  ECTRL + SCAN_CODE_DOWN,  PAD, tx.inc(GAP_S), 33, false);
  384.                         break;
  385.                 default:
  386.                         if (!param) WritePanelText(CANVASX+PAD, "Welcome to ImageEditor Pro! Try to open a file.");
  387.         }
  388. }
  389.  
  390. //===================================================//
  391. //                                                   //
  392. //                      EVENTS                       //
  393. //                                                   //
  394. //===================================================//
  395.  
  396. void event_save_png() { saving_type = SAVE_AS_PNG; draw_acive_panel(); }
  397. void event_save_bmp() { saving_type = SAVE_AS_BMP; draw_acive_panel(); }
  398. void event_save_raw() { saving_type = SAVE_AS_RAW; draw_acive_panel(); }
  399. void event_save_pnm() { saving_type = SAVE_AS_PNM; draw_acive_panel(); }
  400. void event_activate_export() { active_tool = TOOL_EXPORT; draw_content(); }
  401. void event_activate_crop() { active_tool = TOOL_CROP; draw_content(); }
  402. void event_activate_scale() { active_tool = TOOL_SCALE; set_text_scale_edits(); draw_content(); }
  403. void event_activate_depth() { active_tool = TOOL_COLOR_DEPTH; draw_content(); }
  404. void event_activate_flprot() { active_tool = TOOL_FLIP_ROTATE; draw_content(); }
  405.  
  406. void set_text_scale_edits()
  407. {
  408.         edit_box_set_text stdcall (#edit_w, itoa(main_image.w));
  409.         edit_box_set_text stdcall (#edit_h, itoa(main_image.h));
  410. }
  411.  
  412. /*
  413. ;;================================================================================================;;
  414. proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale, _inter, _param1, _param2 ;;
  415. ;;------------------------------------------------------------------------------------------------;;
  416. ;? scale _image                                                                                   ;;
  417. ;;------------------------------------------------------------------------------------------------;;
  418. ;> [_src]         = pointer to source image                                                       ;;
  419. ;> [_crop_x]      = left coord of cropping rect                                                   ;;
  420. ;> [_crop_y]      = top coord of cropping rect                                                    ;;
  421. ;> [_crop_width]  = width of cropping rect                                                        ;;
  422. ;> [_crop_height] = height of cropping rect                                                       ;;
  423. ;> [_dst]         = pointer to resulting image, 0 to create new one                               ;;
  424. ;> [_scale]       = scaling method, see libimg.inc (LIBIMG_SCALE_*)                               ;;
  425. ;> [_inter]       = interpolation algorithm, see libimg.inc (LIBIMG_INTER_*)                      ;;
  426. ;> [_param1]      = depends on _scale, see libimg.inc                                             ;;
  427. ;> [_param2]      = depends on _scale, see libimg.inc                                             ;;
  428. ;;------------------------------------------------------------------------------------------------;;
  429. ;< eax = 0 / pointer to scaled image                                                              ;;
  430. ;< ecx = error code / undefined                                                                   ;;
  431. ;;================================================================================================;;
  432. */
  433.  
  434. //invoke  img.scale, eax, 0, 0, [eax+Image.Width], [eax+Image.Height], 0, LIBIMG_SCALE_STRETCH, LIBIMG_INTER_DEFAULT, [view.width], [view.height]
  435.  
  436. void event_scale()
  437. {
  438.         img_scale stdcall (main_image.image, 0, 0, main_image.w, main_image.h, 0,
  439.                 LIBIMG_SCALE_STRETCH, LIBIMG_INTER_DEFAULT, atoi(#text_w), atoi(#text_h));
  440.         if (!EAX) {
  441.                 if (ECX == 4) {
  442.                         notify("'ImageEdit Pro\nThis color depth is not supported by Scale feature.\nPlease change color depth to 24 / 32 / 8grey.' -Et");
  443.                 } else {
  444.                         debugval("Error code", ECX);
  445.                         notify("'ImageEdit Pro\nImage scale failed :(' -Et");
  446.                 }
  447.         } else {
  448.                 $push eax
  449.                 img_destroy stdcall (main_image.image);
  450.                 $pop eax
  451.                 main_image.image = EAX;
  452.                 main_image.set_vars();
  453.                 scroll_v.position = scroll_h.position = 0;
  454.                 draw_content();
  455.         }
  456. }
  457.  
  458. void event_open()
  459. {
  460.         o_dialog.type = 0; //open file
  461.         OpenDialog_start stdcall (#o_dialog);
  462.         if (o_dialog.status) {
  463.                 open_image(#openfile_path);
  464.                 active_tool = NULL;
  465.                 draw_window();
  466.         }
  467. }
  468.  
  469. void event_flip_hor()
  470. {
  471.         img_flip stdcall (main_image.image, FLIP_HORIZONTAL);
  472.         draw_canvas();
  473. }
  474.  
  475. void event_flip_ver()
  476. {
  477.         img_flip stdcall (main_image.image, FLIP_VERTICAL);
  478.         draw_canvas();
  479. }
  480.  
  481. void event_rotate_left()
  482. {
  483.         img_rotate stdcall (main_image.image, ROTATE_270_CW);
  484.         main_image.w >< main_image.h;
  485.         scroll_v.position = scroll_h.position = 0;
  486.         draw_content();
  487. }
  488.  
  489. void event_rotate_right()
  490. {
  491.         img_rotate stdcall (main_image.image, ROTATE_90_CW);
  492.         main_image.w >< main_image.h;
  493.         scroll_v.position = scroll_h.position = 0;
  494.         draw_content();
  495. }
  496.  
  497. void event_save()
  498. {
  499.         dword _image_format, _image_depth;
  500.         strcpy(#filename_area, #param + strrchr(#param, '/'));
  501.         if (EAX = strrchr(#filename_area, '.')) filename_area[EAX-1] = '\0';
  502.         switch (saving_type) {
  503.                 case SAVE_AS_PNG:
  504.                                 strcat(#filename_area, "_IEP.png");
  505.                                 _image_format = LIBIMG_FORMAT_PNG;
  506.                                 _image_depth = IMAGE_BPP24;
  507.                                 break;
  508.                 case SAVE_AS_BMP:
  509.                                 strcat(#filename_area, "_IEP.bmp");
  510.                                 _image_format = LIBIMG_FORMAT_BMP;
  511.                                 _image_depth = IMAGE_BPP24;
  512.                                 break;
  513.                 case SAVE_AS_PNM:
  514.                                 strcat(#filename_area, "_IEP.pnm");
  515.                                 _image_format = LIBIMG_FORMAT_PNM;
  516.                                 _image_depth = IMAGE_BPP24;
  517.                                 break;
  518.                 case SAVE_AS_RAW:
  519.                                 notify("Not implemented yet.");
  520.                                 return;
  521.         }
  522.         o_dialog.type = 1; //save file
  523.         OpenDialog_start stdcall (#o_dialog);
  524.         if (o_dialog.status) {
  525.                 set_file_path(#openfile_path);
  526.                 img_convert stdcall(main_image.image, 0, _image_depth, 0, 0);
  527.                 if (!EAX) {
  528.                         notify("'ImageEdit Pro\nCan not convert image into specified color depth' -Et");
  529.                 } else {
  530.                         $push eax //converted data
  531.                         img_encode stdcall(EAX, _image_format, 0); //<=EAX data, ECX size
  532.                         $push eax //encoded data
  533.                         CreateFile(ECX, EAX, #openfile_path);
  534.                         $pop ecx
  535.                         free(ECX);
  536.                         $pop eax
  537.                         img_destroy stdcall(EAX);
  538.                 }
  539.         }
  540. }
  541.  
  542. void event_scroll_canvas(int _direction)
  543. {
  544.         switch(_direction) {
  545.                 case SCAN_CODE_DOWN:
  546.                         scroll_v.position = math.min(scroll_v.position+25,
  547.                                 scroll_v.max_area - scroll_v.cur_area);
  548.                         break;
  549.                 case SCAN_CODE_UP:
  550.                         scroll_v.position = math.max(scroll_v.position-25, 0);
  551.                         break;
  552.                 case SCAN_CODE_RIGHT:
  553.                         scroll_h.position = math.min(scroll_h.position+25,
  554.                                 scroll_h.max_area - scroll_h.cur_area);
  555.                         break;
  556.                 case SCAN_CODE_LEFT:
  557.                         scroll_h.position = math.max(scroll_h.position-25, 0);
  558.         }
  559.         draw_canvas();
  560. }
  561.  
  562. stop:
  563.  
  564.