Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 7771 → Rev 7783

/programs/cmm/easyshot/easyshot.c
14,62 → 14,52
 
/* === TRANSLATIONS === */
 
#define T_WTITLE "EasyShot v1.1"
 
#ifdef LANG_RUS
?define T_TAKE_SCREENSHOT " ‘¤¥« âì áªà¨­è®â"
?define T_SETTINGS " áâனª¨"
?define T_EDITBOX_FRAME " ãâì á®åà ­¥­¨ï áªà¨­è®â  "
?define T_CONTINUOUS_SHOOTING "Continuous shooting"
?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å"
?define T_NO_DIR "' ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E"
?define T_SET_PATH "‡ ¤ âì"
#else
?define T_TAKE_SCREENSHOT " Take a screenshot"
?define T_SETTINGS "Settings"
?define T_EDITBOX_FRAME " Save path "
?define T_CONTINUOUS_SHOOTING "Continuous shooting"
?define T_DELAY "Delay in seconds"
?define T_NO_DIR "'Directory does not exists!' -E"
?define T_SET_PATH "Set"
#endif
 
/* === DATA === */
 
proc_info Form;
proc_info Settings;
 
dword screenshot;
int screenshot_length;
 
enum {
BTN_MAKE_SCREENSHOT=10,
BTN_SETTINGS
BTN_SETTINGS,
BTN_CHOOSE_SAVING_PATH
};
 
#define PD 18 //padding
#define SETTINGS_Y PD+PD+30+10
 
char save_path[4096];
char save_path_stable[4096];
char open_dir[4096];
 
edit_box edit_save = {250,25,100,0xffffff,0x94AECE,0xFFFfff,0xffffff,
more_less_box delay = { 1, 0, SETTINGS_Y, T_DELAY };
edit_box edit_save = {260,PD,SETTINGS_Y+50,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(save_path)-2,#save_path,0, 0b};
 
more_less_box delay = { 1, 0, 64, T_DELAY };
checkbox continuous_shooting = { T_CONTINUOUS_SHOOTING, true };
bool show_settings = false;
 
 
opendialog open_folder_dialog =
{
2, //0-file, 2-save, 3-select folder
#Settings,
#Form,
#communication_area_name,
0,
0, //dword opendir_path,
#open_dir, //dword dir_default_path,
#open_dialog_path,
#DrawSettingsWindow,
#DrawWindow,
0,
#open_dir, //dword openfile_path,
0, //dword filename_area,
82,147 → 72,118
 
/* === CODE === */
 
void main()
void init_libraries()
{
int id;
 
load_dll(libio, #libio_init, 1);
load_dll(libimg, #libimg_init, 1);
load_dll(boxlib, #box_lib_init,0);
load_dll(Proc_lib, #OpenDialog_init,0);
OpenDialog_init stdcall (#open_folder_dialog);
}
 
system.color.get();
Libimg_LoadImage(#skin, "/sys/icons16.png");
Libimg_ReplaceColor(skin.image, skin.w, skin.h, 0xffFFFfff, system.color.work_button);
Libimg_ReplaceColor(skin.image, skin.w, skin.h, 0xffCACBD6, MixColors(system.color.work_button, 0, 200));
screenshot_length = screen.width * screen.height * 3;
screenshot = malloc(screenshot_length);
void main()
{
int id;
 
strcpy(#save_path_stable, "/tmp0/1");
strcpy(#save_path, #save_path_stable);
edit_save.size = strlen(#save_path);
init_libraries();
 
strcpy(#save_path, "/tmp0/1");
EditBox_UpdateText(#edit_save, 0);
 
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
loop() switch(WaitEvent())
{
case evMouse:
edit_box_mouse stdcall (#edit_save);
break;
 
case evButton:
id = GetButtonID();
if (id == CLOSE_BTN) ExitProcess();
if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
if (id == BTN_SETTINGS) CreateThread(#SettingsWindow,#settings_stak+4092);
switch(id){
case CLOSE_BTN: ExitProcess();
case BTN_MAKE_SCREENSHOT: EventTakeScreenshot(); break;
case BTN_SETTINGS: EventClickSettings(); break;
case BTN_CHOOSE_SAVING_PATH: EventChooseSavePath(); break;
default: delay.click(id);
}
break;
 
case evKey:
GetKeys();
if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
if (SCAN_CODE_ESC == key_scancode) ExitProcess();
EAX = key_editbox;
edit_box_key stdcall (#edit_save);
break;
case evReDraw:
DefineAndDrawWindow(screen.width/4, screen.height-100/3, 270,
skin_height + 27+PD+PD, 0x34, system.color.work, T_WTITLE,0);
GetProcessInfo(#Form, SelfInfo);
DrawMainContent();
DrawWindow();
}
}
 
void DrawMainContent()
 
void DrawWindow()
{
int take_scr_btn_width;
take_scr_btn_width = DrawIconButton(PD, PD, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 45);
DrawIconButton(PD+take_scr_btn_width, PD, BTN_SETTINGS, " ", 10);
}
int i;
 
void EventTakeScreenshot() {
MinimizeWindow();
pause(delay.value*100);
CopyScreen(screenshot, 0, 0, screen.width, screen.height);
ActivateWindow(GetProcessSlot(Form.ID));
EventSaveImageFile();
}
system.color.get();
DefineAndDrawWindow(screen.width-400, screen.height/3, 270,
skin_height + 30+PD+PD, 0x34, system.color.work, "EasyShot",0);
GetProcessInfo(#Form, SelfInfo);
 
void EventSaveImageFile()
{
int i=0;
char save_file_name[4096];
do {
i++;
//sprintf(, "%s/screen_%i.png", #save_path_stable, i);
strcpy(#save_file_name, #save_path_stable);
strcat(#save_file_name, "/screen_");
strcat(#save_file_name, itoa(i));
strcat(#save_file_name, ".png");
} while (file_exists(#save_file_name));
save_image(screenshot, screen.width, screen.height, #save_file_name);
DrawCaptButton(PD, PD, 170, 28, BTN_MAKE_SCREENSHOT, 0x0090B8, 0xFFFfff, T_TAKE_SCREENSHOT);
DefineButton(PD+170+20, PD, 35, 28, BTN_SETTINGS, system.color.work_button);
for (i=0; i<=2; i++) DrawBar(PD+170+30, i*5+PD+9, 15, 2, system.color.work_button_text);
delay.draw(PD, SETTINGS_Y);
DrawFileBox(#edit_save, T_EDITBOX_FRAME, BTN_CHOOSE_SAVING_PATH);
}
 
 
void SettingsWindow()
void EventChooseSavePath()
{
#define BTN_OD 10
#define BTN_SET 11
int id, butw;
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
loop() switch(WaitEvent())
{
case evMouse:
edit_box_mouse stdcall (#edit_save);
break;
 
case evKey:
GetKeys();
if (SCAN_CODE_ESC == key_scancode) ExitProcess();
EAX = key_editbox;
edit_box_key stdcall (#edit_save);
break;
 
case evButton:
id = GetButtonID();
if (CLOSE_BTN == id) ExitProcess();
if (BTN_OD == id) {
OpenDialog_start stdcall (#open_folder_dialog);
if (open_folder_dialog.status) {
strcpy(#save_path, open_folder_dialog.opendir_path);
edit_save.size = edit_save.pos = edit_save.shift
= edit_save.shift_old = strlen(#save_path);
EditBox_UpdateText(#edit_save, 0);
}
}
if (BTN_SET == id) {
if (save_path[0]) && (dir_exists(#save_path)) {
strcpy(#save_path_stable, #save_path);
strrtrim(#save_path_stable);
if (save_path_stable[strlen(#save_path_stable)-1]=='/')
save_path_stable[strlen(#save_path_stable)-1]=NULL; //no "/" at the end
}
else notify(T_NO_DIR);
 
}
delay.click(id);
break;
 
case evReDraw:
DrawSettingsWindow();
void EventClickSettings()
{
show_settings ^= 1;
MoveSize(OLD, OLD, show_settings*75 + 270,
show_settings*110 + skin_height + PD+PD+30);
}
}
 
void DrawSettingsWindow()
 
void EventTakeScreenshot()
{
DefineAndDrawWindow(Form.left+100, Form.top-40, 400, 230, 0x34, system.color.work, T_SETTINGS, 0);
GetProcessInfo(#Settings, SelfInfo);
delay.draw(15, 30);
DrawFrame(15, 85, 360, 95, T_EDITBOX_FRAME);
DrawEditBoxPos(32, 110, #edit_save);
DrawStandartCaptButton(edit_save.left + edit_save.width + 15, edit_save.top-3, BTN_OD, "...");
DrawStandartCaptButton(edit_save.left, edit_save.top+32, BTN_SET, T_SET_PATH);
int i=0;
char save_file_name[4096];
static dword screenshot;
 
if (!screenshot) screenshot = malloc(screen.width * screen.height * 3);
 
do {
i++;
//sprintf(, "%s/screen_%i.png", #save_path, i);
strcpy(#save_file_name, #save_path);
if (save_file_name[strlen(#save_file_name)-1]!='/') chrcat(#save_file_name, '/');
strcat(#save_file_name, "screen_");
strcat(#save_file_name, itoa(i));
strcat(#save_file_name, ".png");
} while (file_exists(#save_file_name));
 
if (!dir_exists(#save_path)) {
notify(T_NO_DIR);
return;
}
 
int DrawIconButton(dword x, y, id, text, icon)
{
int btwidth;
btwidth = DrawStandartCaptButton(x, y, id, text);
img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16);
return btwidth;
MinimizeWindow();
pause(delay.value*100);
CopyScreen(screenshot, 0, 0, screen.width, screen.height);
save_image(screenshot, screen.width, screen.height, #save_file_name);
ActivateWindow(GetProcessSlot(Form.ID));
}
 
stop:
 
char settings_stak[4096];