Subversion Repositories Kolibri OS

Rev

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