Subversion Repositories Kolibri OS

Rev

Rev 7229 | 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.75"
  17.  
  18. #ifdef LANG_RUS
  19.         ?define T_TAKE_SCREENSHOT "  ‘¤¥« âì áªà¨­è®â"
  20. #else
  21.         ?define T_TAKE_SCREENSHOT "  Take a screenshot"
  22. #endif
  23.  
  24. /* === DATA === */     
  25.  
  26. proc_info Form;
  27.  
  28. dword screenshot;
  29.  
  30. int screenshot_length;
  31.  
  32. enum {
  33.         BTN_MAKE_SCREENSHOT=10,
  34.         BTN_SETTINGS
  35. };
  36.  
  37. #define PD 18 //padding
  38.  
  39. struct _settings {
  40.         bool minimise;
  41.         int delay;
  42.         char save_path[4096];
  43. } settings = { true, 1, "/tmp0/1" };
  44.  
  45. /* === CODE === */
  46.  
  47. void main()
  48. {      
  49.         char id;
  50.  
  51.         load_dll(libio,  #libio_init,  1);
  52.         load_dll(libimg, #libimg_init, 1);
  53.         load_dll(boxlib, #box_lib_init,0);
  54.  
  55.         Libimg_LoadImage(#skin, "/sys/icons16.png");
  56.  
  57.         screenshot_length = screen.width * screen.height * 3;
  58.  
  59.         screenshot  = malloc(screenshot_length);
  60.  
  61.         loop() switch(WaitEvent())
  62.         {
  63.         case evButton:
  64.                 id = GetButtonID();
  65.                 if (id == CLOSE_BTN) ExitProcess();
  66.                 if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
  67.                 if (id == BTN_SETTINGS) EventShowSettings();
  68.                 break;
  69.  
  70.         case evKey:
  71.                 GetKeys();
  72.                 if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
  73.                 break;
  74.      
  75.         case evReDraw:
  76.                 system.color.get();
  77.                 DefineAndDrawWindow(screen.width/4, screen.height-100/3, 270,
  78.                         skin_height + 27+PD+PD, 0x34, system.color.work, T_WTITLE,0);
  79.                 GetProcessInfo(#Form, SelfInfo);
  80.                 if (Form.status_window>2) break;
  81.                 DrawMainContent();
  82.         }
  83. }
  84.  
  85. void DrawMainContent()
  86. {
  87.         int take_scr_btn_width;
  88.         take_scr_btn_width = DrawIconButton(PD, PD, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44);
  89.         DrawIconButton(PD+take_scr_btn_width, PD, BTN_SETTINGS, " ", 10);      
  90. }
  91.  
  92. void EventTakeScreenshot() {
  93.         if (settings.minimise) MinimizeWindow();
  94.         pause(settings.delay*100);
  95.         CopyScreen(screenshot, 0, 0, screen.width, screen.height);
  96.         ActivateWindow(GetProcessSlot(Form.ID));
  97.         if (!settings.minimise) DrawMainContent();
  98.         EventSaveImageFile();
  99. }
  100.  
  101. void EventSaveImageFile()
  102. {
  103.         int i=0;
  104.         char save_file_name[4096];
  105.         do {
  106.                 i++;
  107.                 sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i);
  108.         } while (file_exists(#save_file_name));
  109.         save_image(screenshot, screen.width, screen.height, #save_file_name);
  110. }
  111.  
  112. void EventShowSettings()
  113. {
  114.         CreateThread(#SettingsWindow,#settings_stak+4092);     
  115. }
  116.  
  117. char path_tmp[4096];
  118. dword mouse_dd1;
  119. edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,sizeof(path_tmp),#path_tmp,#mouse_dd1, 0b};
  120.  
  121. void SettingsWindow()
  122. {
  123.         #define x 15
  124.         int id;
  125.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  126.         loop() switch(WaitEvent())
  127.         {
  128.         case evMouse:
  129.                 //edit_box_mouse stdcall (#address_box);
  130.                 break;
  131.  
  132.         case evKey:
  133.                 GetKeys();
  134.                 if (SCAN_CODE_ESC == key_scancode) ExitProcess();
  135.                 break;
  136.  
  137.         case evButton:
  138.                 id = GetButtonID();
  139.                 if (CLOSE_BTN == id) ExitProcess();
  140.                 if (10 == id) settings.delay++;
  141.                 if (11 == id) && (settings.delay>0) settings.delay--;
  142.                 if (12 == id) settings.minimise ^= 1;
  143.                 goto _DRAW_CONTENT;
  144.                 break;
  145.  
  146.         case evReDraw:
  147.                 DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0);
  148.                 _DRAW_CONTENT:
  149.                 CheckBox(x, 10, 12, "Minimize window", settings.minimise);
  150.                 MoreLessBox(x, 40, 10, 11, settings.delay, "Delay in seconds");
  151.                 //DrawEditBox(#edit_box_path);
  152.         }
  153. }
  154.  
  155. inline byte calc_rgb(dword B, item_h)
  156. {
  157.         return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3]
  158.                 + ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5);
  159. }
  160.  
  161. int DrawIconButton(dword x, y, id, text, icon)
  162. {
  163.         int btwidth;
  164.         system.color.work_button = 0xFFFfff;
  165.         system.color.work_button_text = 0;
  166.         btwidth = DrawStandartCaptButton(x, y, id, text);
  167.         img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16);
  168.         system.color.get();
  169.         return btwidth;
  170. }
  171.  
  172. stop:
  173.  
  174. char settings_stak[4096];