Subversion Repositories Kolibri OS

Rev

Rev 7252 | 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. #include "../lib/obj/proc_lib.h"
  10.  
  11. #ifndef AUTOBUILD
  12.         #include "lang.h--"
  13. #endif
  14.  
  15. /* === TRANSLATIONS === */
  16.  
  17. #define T_WTITLE "EasyShot v1.1"
  18.  
  19. #ifdef LANG_RUS
  20.         ?define T_TAKE_SCREENSHOT "  ‘¤¥« âì áªà¨­è®â"
  21.         ?define T_SETTINGS " áâனª¨"
  22.         ?define T_EDITBOX_FRAME " ãâì á®åà ­¥­¨ï áªà¨­è®â  "
  23.         ?define T_MINIMIZE "‘¢¥à­ãâì ®ª­® ¯à¨ á­¨¬ª¥"
  24.         ?define T_CONTINUOUS_SHOOTING "Continuous shooting"
  25.         ?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å"
  26.         ?define T_NO_DIR "' ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E"
  27.         ?define T_SET_PATH "‡ ¤ âì"
  28. #else
  29.         ?define T_TAKE_SCREENSHOT "  Take a screenshot"
  30.         ?define T_SETTINGS "Settings"
  31.         ?define T_EDITBOX_FRAME " Save path "
  32.         ?define T_MINIMIZE "Minimize window"
  33.         ?define T_CONTINUOUS_SHOOTING "Continuous shooting"
  34.         ?define T_DELAY "Delay in seconds"
  35.         ?define T_NO_DIR "'Directory does not exists!' -E"
  36.         ?define T_SET_PATH "Set"
  37. #endif
  38.  
  39. /* === DATA === */     
  40.  
  41. proc_info Form;
  42. proc_info Settings;
  43.  
  44. dword screenshot;
  45. int screenshot_length;
  46.  
  47. enum {
  48.         BTN_MAKE_SCREENSHOT=10,
  49.         BTN_SETTINGS
  50. };
  51.  
  52. #define PD 18 //padding
  53.  
  54. char save_path[4096];
  55. char save_path_stable[4096];
  56. char open_dir[4096];
  57.  
  58. edit_box edit_save = {250,25,100,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  59.         0x10000000,sizeof(save_path),#save_path,0, 0b};
  60.  
  61. more_less_box delay = { 1, 0, 64, T_DELAY };
  62. checkbox minimize = { T_MINIMIZE, true };
  63. checkbox continuous_shooting = { T_CONTINUOUS_SHOOTING, true };
  64.  
  65.  
  66. opendialog open_folder_dialog =
  67. {
  68.   2, //0-file, 2-save, 3-select folder
  69.   #Settings,
  70.   #communication_area_name,
  71.   0,
  72.   0, //dword opendir_path,
  73.   #open_dir, //dword dir_default_path,
  74.   #open_dialog_path,
  75.   #DrawSettingsWindow,
  76.   0,
  77.   #open_dir, //dword openfile_path,
  78.   0, //dword filename_area,
  79.   0, //dword filter_area,
  80.   420,
  81.   NULL,
  82.   320,
  83.   NULL
  84. };
  85.  
  86. /* === CODE === */
  87.  
  88. void main()
  89. {      
  90.         int id;
  91.  
  92.         load_dll(libio,  #libio_init,  1);
  93.         load_dll(libimg, #libimg_init, 1);
  94.         load_dll(boxlib, #box_lib_init,0);
  95.         load_dll(Proc_lib,  #OpenDialog_init,0);
  96.         OpenDialog_init stdcall (#open_folder_dialog);
  97.  
  98.         system.color.get();
  99.         Libimg_LoadImage(#skin, "/sys/icons16.png");
  100.         Libimg_ReplaceColor(skin.image, skin.w, skin.h, 0xffFFFfff, system.color.work_button);
  101.         Libimg_ReplaceColor(skin.image, skin.w, skin.h, 0xffCACBD6, MixColors(system.color.work_button, 0, 200));
  102.         screenshot_length = screen.width * screen.height * 3;
  103.         screenshot = malloc(screenshot_length);
  104.  
  105.         strcpy(#save_path_stable, "/tmp0/1");
  106.         strcpy(#save_path, #save_path_stable);
  107.         edit_save.size = strlen(#save_path);
  108.  
  109.         loop() switch(WaitEvent())
  110.         {
  111.         case evButton:
  112.                 id = GetButtonID();
  113.                 if (id == CLOSE_BTN) ExitProcess();
  114.                 if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
  115.                 if (id == BTN_SETTINGS) CreateThread(#SettingsWindow,#settings_stak+4092);
  116.                 break;
  117.  
  118.         case evKey:
  119.                 GetKeys();
  120.                 if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
  121.                 break;
  122.      
  123.         case evReDraw:
  124.                 DefineAndDrawWindow(screen.width/4, screen.height-100/3, 270,
  125.                         skin_height + 27+PD+PD, 0x34, system.color.work, T_WTITLE,0);
  126.                 GetProcessInfo(#Form, SelfInfo);
  127.                 DrawMainContent();
  128.         }
  129. }
  130.  
  131. void DrawMainContent()
  132. {
  133.         int take_scr_btn_width;
  134.         take_scr_btn_width = DrawIconButton(PD, PD, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 45);
  135.         DrawIconButton(PD+take_scr_btn_width, PD, BTN_SETTINGS, " ", 10);      
  136. }
  137.  
  138. void EventTakeScreenshot() {
  139.         if (minimize.checked) MinimizeWindow();
  140.         pause(delay.value*100);
  141.         CopyScreen(screenshot, 0, 0, screen.width, screen.height);
  142.         ActivateWindow(GetProcessSlot(Form.ID));
  143.         if (!minimize.checked) DrawMainContent();
  144.         EventSaveImageFile();
  145. }
  146.  
  147. void EventSaveImageFile()
  148. {
  149.         int i=0;
  150.         char save_file_name[4096];
  151.         do {
  152.                 i++;
  153.                 sprintf(#save_file_name, "%s/screen_%i.png", #save_path_stable, i);
  154.         } while (file_exists(#save_file_name));
  155.         save_image(screenshot, screen.width, screen.height, #save_file_name);
  156. }
  157.  
  158.  
  159. void SettingsWindow()
  160. {
  161.         #define BTN_OD 10
  162.         #define BTN_SET 11
  163.         int id, butw;
  164.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  165.         loop() switch(WaitEvent())
  166.         {
  167.         case evMouse:
  168.                 edit_box_mouse stdcall (#edit_save);
  169.                 break;
  170.  
  171.         case evKey:
  172.                 GetKeys();
  173.                 if (SCAN_CODE_ESC == key_scancode) ExitProcess();
  174.                 EAX= key_ascii << 8;
  175.                 edit_box_key stdcall (#edit_save);     
  176.                 break;
  177.  
  178.         case evButton:
  179.                 id = GetButtonID();
  180.                 if (CLOSE_BTN == id) ExitProcess();
  181.                 if (BTN_OD == id) {
  182.                         OpenDialog_start stdcall (#open_folder_dialog);
  183.                         if (open_folder_dialog.status) {
  184.                                 strcpy(#save_path, open_folder_dialog.opendir_path);
  185.                                 edit_save.size = edit_save.pos = edit_save.shift
  186.                                         = edit_save.shift_old = strlen(#save_path);
  187.                         }
  188.                 }
  189.                 if (BTN_SET == id) {
  190.                         if (save_path[0]) && (dir_exists(#save_path)) {
  191.                                 strcpy(#save_path_stable, #save_path);
  192.                                 strrtrim(#save_path_stable);
  193.                                 if (save_path_stable[strlen(#save_path_stable)-1]=='/')
  194.                                     save_path_stable[strlen(#save_path_stable)-1]=NULL; //no "/" at the end
  195.                         }
  196.                         else notify(T_NO_DIR);
  197.  
  198.                 }
  199.                 delay.click(id);
  200.                 minimize.click(id);
  201.                 break;
  202.  
  203.         case evReDraw:
  204.                 DrawSettingsWindow();
  205.         }
  206. }
  207.  
  208. void DrawSettingsWindow()
  209. {
  210.         DefineAndDrawWindow(Form.left+100, Form.top-40, 400, 230, 0x34, system.color.work, T_SETTINGS, 0);
  211.         GetProcessInfo(#Settings, SelfInfo);
  212.         minimize.draw(15, 15);
  213.         delay.draw(15, 45);
  214.         DrawFrame(15, 85, 360, 95, T_EDITBOX_FRAME);
  215.                 DrawEditBoxPos(32, 110, #edit_save);
  216.                 DrawStandartCaptButton(edit_save.left + edit_save.width + 15, edit_save.top-3, BTN_OD, "...");
  217.                 DrawStandartCaptButton(edit_save.left, edit_save.top+32, BTN_SET, T_SET_PATH); 
  218. }
  219.  
  220. int DrawIconButton(dword x, y, id, text, icon)
  221. {
  222.         int btwidth;
  223.         btwidth = DrawStandartCaptButton(x, y, id, text);
  224.         img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16);
  225.         return btwidth;
  226. }
  227.  
  228. stop:
  229.  
  230. char settings_stak[4096];