Subversion Repositories Kolibri OS

Rev

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