Subversion Repositories Kolibri OS

Rev

Rev 7243 | Blame | Compare with Previous | 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.76"
  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.  
  39. char save_path[4096] = "/tmp0/1";
  40. dword mouse_dd1;
  41. edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  42.         0x10000000,sizeof(save_path),#save_path,#mouse_dd1, 0b};
  43.  
  44. more_less_box delay = { 1, 0, 64, "Delay in seconds" };
  45. checkbox minimise = { "Minimize window", true };
  46.  
  47.  
  48. /* === CODE === */
  49.  
  50. void main()
  51. {      
  52.         char id;
  53.  
  54.         load_dll(libio,  #libio_init,  1);
  55.         load_dll(libimg, #libimg_init, 1);
  56.         load_dll(boxlib, #box_lib_init,0);
  57.  
  58.         Libimg_LoadImage(#skin, "/sys/icons16.png");
  59.         screenshot_length = screen.width * screen.height * 3;
  60.         screenshot = malloc(screenshot_length);
  61.  
  62.         loop() switch(WaitEvent())
  63.         {
  64.         case evButton:
  65.                 id = GetButtonID();
  66.                 if (id == CLOSE_BTN) ExitProcess();
  67.                 if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
  68.                 if (id == BTN_SETTINGS) CreateThread(#SettingsWindow,#settings_stak+4092);
  69.                 break;
  70.  
  71.         case evKey:
  72.                 GetKeys();
  73.                 if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
  74.                 break;
  75.      
  76.         case evReDraw:
  77.                 system.color.get();
  78.                 DefineAndDrawWindow(screen.width/4, screen.height-100/3, 270,
  79.                         skin_height + 27+PD+PD, 0x34, system.color.work, T_WTITLE,0);
  80.                 GetProcessInfo(#Form, SelfInfo);
  81.                 if (Form.status_window>2) break;
  82.                 DrawMainContent();
  83.         }
  84. }
  85.  
  86. void DrawMainContent()
  87. {
  88.         int take_scr_btn_width;
  89.         take_scr_btn_width = DrawIconButton(PD, PD, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44);
  90.         DrawIconButton(PD+take_scr_btn_width, PD, BTN_SETTINGS, " ", 10);      
  91. }
  92.  
  93. void EventTakeScreenshot() {
  94.         if (minimise.checked) MinimizeWindow();
  95.         pause(delay.value*100);
  96.         CopyScreen(screenshot, 0, 0, screen.width, screen.height);
  97.         ActivateWindow(GetProcessSlot(Form.ID));
  98.         if (!minimise.checked) DrawMainContent();
  99.         EventSaveImageFile();
  100. }
  101.  
  102. void EventSaveImageFile()
  103. {
  104.         int i=0;
  105.         char save_file_name[4096];
  106.         do {
  107.                 i++;
  108.                 sprintf(#save_file_name, "%s/screen_%i.png", #save_path, i);
  109.         } while (file_exists(#save_file_name));
  110.         save_image(screenshot, screen.width, screen.height, #save_file_name);
  111. }
  112.  
  113.  
  114. void SettingsWindow()
  115. {
  116.         int id;
  117.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  118.         loop() switch(WaitEvent())
  119.         {
  120.         case evMouse:
  121.                 //edit_box_mouse stdcall (#address_box);
  122.                 break;
  123.  
  124.         case evKey:
  125.                 GetKeys();
  126.                 if (SCAN_CODE_ESC == key_scancode) ExitProcess();
  127.                 break;
  128.  
  129.         case evButton:
  130.                 id = GetButtonID();
  131.                 if (CLOSE_BTN == id) ExitProcess();
  132.                 delay.click(id);
  133.                 minimise.click(id);
  134.                 break;
  135.  
  136.         case evReDraw:
  137.                 DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0);
  138.                 _DRAW_CONTENT:
  139.                 minimise.draw(15, 10);
  140.                 delay.draw(15, 40);
  141.                 //DrawEditBox(#edit_box_path);
  142.         }
  143. }
  144.  
  145. int DrawIconButton(dword x, y, id, text, icon)
  146. {
  147.         int btwidth;
  148.         system.color.work_button = 0xFFFfff;
  149.         system.color.work_button_text = 0;
  150.         btwidth = DrawStandartCaptButton(x, y, id, text);
  151.         img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16);
  152.         system.color.get();
  153.         return btwidth;
  154. }
  155.  
  156. stop:
  157.  
  158. char settings_stak[4096];