Subversion Repositories Kolibri OS

Rev

Rev 7228 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 1024 * 50
  2. #include "../lib/kolibri.h"
  3. #include "../lib/strings.h"
  4. #include "../lib/mem.h"
  5. #include "../lib/gui.h"
  6.  
  7. #include "../lib/obj/libimg.h"
  8. #include "../lib/obj/box_lib.h"
  9.  
  10. #ifndef AUTOBUILD
  11.         #include "lang.h--"
  12. #endif
  13.  
  14. /* === TRANSLATIONS === */
  15.  
  16. #define T_WTITLE "EasyShot v0.7"
  17.  
  18. #ifdef LANG_RUS
  19.         ?define T_TAKE_SCREENSHOT "  ‘¤¥« âì áªà¨­è®â"
  20.         ?define T_SAVE "  ‘®åà ­¨âì"
  21.         ?define T_PREVIEW "à¥¤¯à®á¬®âà"
  22. #else
  23.         ?define T_TAKE_SCREENSHOT "  Take a screenshot"
  24.         ?define T_SAVE "  Save"
  25.         ?define T_PREVIEW "Preview"
  26. #endif
  27.  
  28. /* === DATA === */
  29.  
  30. proc_info Form;
  31.  
  32. dword screenshot,
  33.       preview;
  34.  
  35. int screenshot_length,
  36.     preview_length;
  37.  
  38. enum {
  39.         BTN_MAKE_SCREENSHOT=10,
  40.         BTN_SAVE,
  41.         BTN_SETTINGS
  42. };
  43.  
  44. #define PD 18 //padding
  45. #define TOOLBAR_H 20+PD
  46.  
  47. block pw;
  48.  
  49. struct _settings {
  50.         bool minimise;
  51.         int delay;
  52.         char save_path[4096];
  53. } settings = { true, 1, "/tmp0/1" };
  54.  
  55. /* === CODE === */
  56.  
  57. void main()
  58. {      
  59.         char id;
  60.  
  61.         load_dll(libio,  #libio_init,  1);
  62.         load_dll(libimg, #libimg_init, 1);
  63.         load_dll(boxlib, #box_lib_init,0);
  64.  
  65.         Libimg_LoadImage(#skin, "/sys/icons16.png");
  66.  
  67.         screenshot_length = screen.width * screen.height * 3;
  68.         pw.set_size(PD, TOOLBAR_H+PD, screen.width/2, screen.height/2);
  69.         preview_length = screenshot_length / 2;
  70.  
  71.         screenshot  = malloc(screenshot_length);
  72.         preview = malloc(screenshot_length/2);
  73.  
  74.         loop() switch(WaitEvent())
  75.         {
  76.         case evButton:
  77.                 id = GetButtonID();
  78.                 if (id == CLOSE_BTN) ExitProcess();
  79.                 if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
  80.                 if (id == BTN_SAVE) EventSaveImageFile();
  81.                 if (id == BTN_SETTINGS) EventShowSettings();
  82.                 break;
  83.  
  84.         case evKey:
  85.                 GetKeys();
  86.                 if (SCAN_CODE_KEY_S == key_scancode) EventSaveImageFile();
  87.                 if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
  88.                 break;
  89.      
  90.         case evReDraw:
  91.                 DefineAndDrawWindow(screen.width/4, screen.height/4, pw.w + 9 +PD+PD,
  92.                         pw.h + skin_height + TOOLBAR_H + 4 +PD+PD, 0x74, 0, T_WTITLE,0);
  93.                 GetProcessInfo(#Form, SelfInfo);
  94.                 if (Form.status_window>2) break;
  95.                 system.color.get();
  96.                 DrawMainContent();
  97.         }
  98. }
  99.  
  100. void DrawMainContent()
  101. {
  102.         int take_scr_btn_width;
  103.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H, system.color.work);
  104.         DrawWideRectangle(0, TOOLBAR_H, pw.w+PD+PD, pw.h+PD+PD, PD-1, system.color.work);
  105.         DrawRectangle(pw.x-1, pw.y-1, pw.w+1, pw.h+1, system.color.work_graph);
  106.         take_scr_btn_width = DrawIconButton(pw.x, pw.y-42, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44);
  107.         if (ESDWORD[preview]==0) {
  108.                 DrawBar(pw.x, pw.y, pw.w, pw.h, 0xEEEeee);
  109.                 WriteText(Form.cwidth-calc(strlen(T_PREVIEW)*8)/2, pw.h/2+pw.y, 0x90, 0x777777, T_PREVIEW);
  110.         }
  111.         else {
  112.                 _PutImage(pw.x, pw.y, pw.w, pw.h, preview);
  113.                 DrawIconButton(take_scr_btn_width + pw.x, pw.y-42, BTN_SAVE, T_SAVE, 5);
  114.         }
  115.         DrawIconButton(Form.cwidth-40-PD, pw.y-42, BTN_SETTINGS, " ", 10);     
  116. }
  117.  
  118. void EventTakeScreenshot() {
  119.         if (settings.minimise) MinimizeWindow();
  120.         pause(settings.delay*100);
  121.         CopyScreen(screenshot, 0, 0, screen.width, screen.height);
  122.         ZoomImageTo50percent();
  123.         ActivateWindow(GetProcessSlot(Form.ID));
  124.         if (!settings.minimise) DrawMainContent();
  125. }
  126.  
  127. void EventSaveImageFile()
  128. {
  129.         int i=0;
  130.         char save_file_name[4096];
  131.         do {
  132.                 i++;
  133.                 sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i);
  134.         } while (file_exists(#save_file_name));
  135.         save_image(screenshot, screen.width, screen.height, #save_file_name);
  136. }
  137.  
  138. void EventShowSettings()
  139. {
  140.         CreateThread(#SettingsWindow,#settings_stak+4092);     
  141. }
  142.  
  143. char path_tmp[4096];
  144. dword mouse_dd1;
  145. edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,sizeof(path_tmp),#path_tmp,#mouse_dd1, 0b};
  146.  
  147. void SettingsWindow()
  148. {
  149.         #define x 15
  150.         int id;
  151.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  152.         loop() switch(WaitEvent())
  153.         {
  154.         case evMouse:
  155.                 //edit_box_mouse stdcall (#address_box);
  156.                 break;
  157.  
  158.         case evKey:
  159.                 GetKeys();
  160.                 if (SCAN_CODE_ESC == key_scancode) ExitProcess();
  161.                 break;
  162.  
  163.         case evButton:
  164.                 id = GetButtonID();
  165.                 if (CLOSE_BTN == id) ExitProcess();
  166.                 if (10 == id) settings.delay++;
  167.                 if (11 == id) && (settings.delay>0) settings.delay--;
  168.                 if (12 == id) settings.minimise ^= 1;
  169.                 goto _DRAW_CONTENT;
  170.                 break;
  171.  
  172.         case evReDraw:
  173.                 DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0);
  174.                 _DRAW_CONTENT:
  175.                 CheckBox(x, 10, 12, "Minimize window", settings.minimise);
  176.                 MoreLessBox(x, 40, 10, 11, settings.delay, "Delay in seconds");
  177.                 //DrawEditBox(#edit_box_path);
  178.         }
  179. }
  180.  
  181. inline byte calc_rgb(dword B, item_h)
  182. {
  183.         return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3]
  184.                 + ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5);
  185. }
  186.  
  187. void ZoomImageTo50percent() {
  188.         dword point_x = 0;
  189.         dword item_h = screen.width * 3;
  190.         dword small = preview;
  191.         dword big = screenshot;
  192.  
  193.         while( (small <= preview + preview_length) && (big <= screenshot + screenshot_length ) ) {
  194.                
  195.                 if (big <= screenshot + item_h) || (big >= screenshot + screenshot_length - item_h)
  196.                 {
  197.                         ESBYTE[small]   = ESBYTE[big];
  198.                         ESBYTE[small+1] = ESBYTE[big+1];
  199.                         ESBYTE[small+2] = ESBYTE[big+2];
  200.                 }
  201.                 else
  202.                 {
  203.                         ESBYTE[small]   = calc_rgb(big, item_h);
  204.                         ESBYTE[small+1] = calc_rgb(big+1, item_h);
  205.                         ESBYTE[small+2] = calc_rgb(big+2, item_h);
  206.                 }
  207.        
  208.                 small+=3;
  209.                 big+=6;
  210.  
  211.                 point_x+=2;
  212.                 if (point_x >= screen.width)
  213.                 {
  214.                         big += item_h;
  215.                         point_x = 0;
  216.                 }
  217.         }
  218. }
  219.  
  220. int DrawIconButton(dword x, y, id, text, icon)
  221. {
  222.         int btwidth;
  223.         system.color.work_button = 0xFFFfff;
  224.         system.color.work_button_text = 0;
  225.         btwidth = DrawStandartCaptButton(x, y, id, text);
  226.         img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16);
  227.         system.color.get();
  228.         return btwidth;
  229. }
  230.  
  231. stop:
  232.  
  233. char settings_stak[4096];