Subversion Repositories Kolibri OS

Rev

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