Subversion Repositories Kolibri OS

Rev

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