Subversion Repositories Kolibri OS

Rev

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