Subversion Repositories Kolibri OS

Rev

Rev 8752 | Rev 9015 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 1024 * 40
  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. /* === TRANSLATIONS === */
  12.  
  13. #ifdef LANG_RUS
  14.         ?define T_TAKE_SCREENSHOT "‘¤¥« âì áªà¨­è®â"
  15.         ?define T_SETTINGS " áâனª¨"
  16.         ?define T_EDITBOX_FRAME "ãâì á®åà ­¥­¨ï áªà¨­è®â "
  17.         ?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å"
  18.         ?define T_NO_DIR "' ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E"
  19. #else
  20.         ?define T_TAKE_SCREENSHOT "Take a screenshot"
  21.         ?define T_SETTINGS "Settings"
  22.         ?define T_EDITBOX_FRAME "Save path"
  23.         ?define T_DELAY "Delay in seconds"
  24.         ?define T_NO_DIR "'Directory does not exists!' -E"
  25. #endif
  26.  
  27. /* === DATA === */     
  28.  
  29. proc_info Form;
  30.  
  31. enum {
  32.         BTN_MAKE_SCREENSHOT=10,
  33.         BTN_SETTINGS,
  34.         BTN_CHOOSE_SAVING_PATH
  35. };
  36.  
  37. #define PD 18 //padding
  38. #define SETTINGS_Y PD+PD+30+10
  39.  
  40. char save_path[4096];
  41.  
  42. more_less_box delay = { 1, 0, SETTINGS_Y, T_DELAY };
  43. edit_box edit_save = {260,PD,SETTINGS_Y+50,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  44.         0x10000000,sizeof(save_path)-2,#save_path,0, 0b};
  45.  
  46. bool show_settings = false;
  47.  
  48. opendialog open_folder_dialog =
  49. {
  50.   2, //0-file, 2-save, 3-select folder
  51.   #Form,
  52.   #communication_area_name,
  53.   0,
  54.   0, //dword opendir_path,
  55.   #save_path, //dword dir_default_path,
  56.   #open_dialog_path,
  57.   #DrawWindow,
  58.   0,
  59.   #save_path, //dword openfile_path,
  60.   0, //dword filename_area,
  61.   0, //dword filter_area,
  62.   420,
  63.   NULL,
  64.   320,
  65.   NULL
  66. };
  67.  
  68. /* === CODE === */
  69.  
  70. void init_libraries()
  71. {
  72.         load_dll(libimg, #libimg_init, 1);
  73.         load_dll(boxlib, #box_lib_init,0);
  74.         load_dll(Proc_lib,  #OpenDialog_init,0);
  75.         OpenDialog_init stdcall (#open_folder_dialog); 
  76. }
  77.  
  78. void main()
  79. {      
  80.         int id;
  81.  
  82.         init_libraries();
  83.  
  84.         edit_box_set_text stdcall (#edit_save, "/tmp0/1");     
  85.  
  86.         @SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  87.         loop() switch(@WaitEvent())
  88.         {
  89.         case evMouse:
  90.                 edit_box_mouse stdcall (#edit_save);
  91.                 break;
  92.  
  93.         case evButton:
  94.                 id = @GetButtonID();
  95.                 switch(id){
  96.                         case CLOSE_BTN: @ExitProcess();
  97.                         case BTN_MAKE_SCREENSHOT: EventTakeScreenshot(); break;
  98.                         case BTN_SETTINGS: EventClickSettings(); break;
  99.                         case BTN_CHOOSE_SAVING_PATH: EventChooseSavePath(); break;
  100.                         default: delay.click(id);
  101.                 }
  102.                 break;
  103.  
  104.         case evKey:
  105.                 @GetKey();
  106.                 edit_box_key stdcall (#edit_save);
  107.                 EAX >>= 16;
  108.                 if (SCAN_CODE_ENTER == AL) EventTakeScreenshot();
  109.                 if (SCAN_CODE_ESC == AL) ExitProcess();
  110.                 break;
  111.      
  112.         case evReDraw:
  113.                 DrawWindow();
  114.         }
  115. }
  116.  
  117.  
  118. void DrawWindow()
  119. {
  120.         int i;
  121.  
  122.         sc.get();
  123.         DefineAndDrawWindow(screen.width-400, screen.height/3, 270,
  124.                 skin_height + 30+PD+PD, 0x34, sc.work, "EasyShot",0);
  125.         GetProcessInfo(#Form, SelfInfo);
  126.  
  127.         DrawCaptButton(PD, PD, 170, 28, BTN_MAKE_SCREENSHOT, 0x0090B8, 0xFFFfff, T_TAKE_SCREENSHOT);
  128.         DefineButton(PD+170+20, PD, 35, 28, BTN_SETTINGS, sc.button);
  129.         for (i=0; i<=2; i++) DrawBar(PD+170+30, i*5+PD+9, 15, 2, sc.button_text);
  130.         delay.draw(PD, SETTINGS_Y);
  131.         DrawFileBox(#edit_save, T_EDITBOX_FRAME, BTN_CHOOSE_SAVING_PATH);      
  132. }
  133.  
  134.  
  135. void EventChooseSavePath()
  136. {
  137.         OpenDialog_start stdcall (#open_folder_dialog);
  138.         if (open_folder_dialog.status) {
  139.                 edit_box_set_text stdcall (#edit_save, #save_path);    
  140.         }
  141. }
  142.  
  143.  
  144. void EventClickSettings()
  145. {
  146.         show_settings ^= 1;
  147.         @MoveSize(OLD, OLD, show_settings*75 + 270,
  148.                 show_settings*110 + skin_height + PD+PD+30);
  149. }
  150.  
  151.  
  152. void EventTakeScreenshot()
  153. {
  154.         int i=0;
  155.         char save_file_name[4096];
  156.         static dword screenshot;
  157.  
  158.         if (!screenshot) screenshot = malloc(screen.width * screen.height * 3);
  159.  
  160.         do {
  161.                 i++;
  162.                 //sprintf(, "%s/screen_%i.png", #save_path, i);
  163.                 strcpy(#save_file_name, #save_path);
  164.                 if (save_file_name[strlen(#save_file_name)-1]!='/') chrcat(#save_file_name, '/');
  165.                 strcat(#save_file_name, "screen_");
  166.                 strcat(#save_file_name, itoa(i));
  167.                 strcat(#save_file_name, ".png");
  168.         } while (file_exists(#save_file_name));
  169.  
  170.         if (!dir_exists(#save_path)) {
  171.                 notify(T_NO_DIR);
  172.                 return;
  173.         }
  174.  
  175.         MinimizeWindow();
  176.         pause(delay.value*100);
  177.         CopyScreen(screenshot, 0, 0, screen.width, screen.height);
  178.         save_image(screenshot, screen.width, screen.height, #save_file_name);
  179.         ActivateWindow(GetProcessSlot(Form.ID));
  180. }
  181.  
  182.