Subversion Repositories Kolibri OS

Rev

Rev 6746 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6746 Rev 7220
Line 1... Line 1...
1
#define MEMSIZE 0xFFFFF
1
#define MEMSIZE 1024 * 420
2
#include "../lib/kolibri.h" 
2
#include "../lib/kolibri.h" 
3
#include "../lib/strings.h" 
3
#include "../lib/strings.h" 
4
#include "../lib/mem.h" 
4
#include "../lib/mem.h" 
5
#include "../lib/gui.h" 
5
#include "../lib/gui.h" 
Line -... Line 6...
-
 
6
 
-
 
7
#include "../lib/obj/libimg.h"
6
 
8
 
7
#ifndef AUTOBUILD
9
#ifndef AUTOBUILD
8
	#include "lang.h--"
10
	#include "lang.h--"
Line 9... Line 11...
9
#endif
11
#endif
Line 10... Line -...
10
 
-
 
11
/* === DATA === */
12
 
Line 12... Line -...
12
 
-
 
13
system_colors sc;
13
/* === DATA === */
14
proc_info Form;
14
 
Line 15... Line 15...
15
 
15
proc_info Form;
16
 
16
 
17
dword b_screen,
17
dword b_screen,
18
      s_screen;
18
      preview;
-
 
19
 
-
 
20
int b_screen_length,
19
 
21
    preview_width,
20
int b_screen_width,
22
    preview_height,
-
 
23
    preview_length;
Line -... Line 24...
-
 
24
 
Line 21... Line 25...
21
    b_screen_height,
25
enum {
Line 22... Line 26...
22
    b_screen_length,
26
	BTN_MAKE_SCREENSHOT=10,
23
    s_screen_width,
27
	BTN_SAVE
24
    s_screen_height,
28
};
25
    s_screen_length;
-
 
26
 
-
 
27
 
-
 
28
/* === CODE === */
29
 
29
 
30
#define TOOLBAR_H 50;
30
 
31
 
31
void main()
32
/* === CODE === */
Line 32... Line 33...
32
{	
33
 
33
	char id;
34
 
Line 34... Line -...
34
	mem_Init();
-
 
35
	b_screen_width  = GetScreenWidth()+1;
-
 
36
	b_screen_height = GetScreenHeight()+1;
35
void main()
37
	b_screen_length = b_screen_width*b_screen_height*3;
36
{	
38
	s_screen_width  = b_screen_width / 2;
37
	char id;
39
	s_screen_height = b_screen_height / 2;
38
	b_screen_length = screen.width * screen.height * 3;
40
	s_screen_length = b_screen_length / 2;	
39
	preview_width  = screen.width / 2;
41
 
40
	preview_height = screen.height / 2;
-
 
41
	preview_length = b_screen_length / 2;	
-
 
42
 
-
 
43
	b_screen  = malloc(b_screen_length);
-
 
44
	preview = malloc(b_screen_length/2);
-
 
45
 
-
 
46
	loop() switch(WaitEvent())
-
 
47
	{
42
	b_screen  = malloc(b_screen_length);
48
	case evButton:
Line 43... Line 49...
43
	s_screen = malloc(b_screen_length/2);
49
		id = GetButtonID();
44
 
50
		if (id == CLOSE_BTN) ExitProcess();
45
	loop()
51
		if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
-
 
52
		if (id == BTN_SAVE) EventSaveFile();
-
 
53
		break;
46
	{
54
 
47
		switch(WaitEvent())
55
	case evKey:
48
		{
56
		GetKeys();
49
		case evButton:
57
		if (SCAN_CODE_KEY_S == key_scancode) EventSaveFile();
50
			id = GetButtonID();
58
		if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
51
			if (id==1) ExitProcess();
59
		break;
52
			if (id==10) TakeScreenshot();
60
     
-
 
61
	case evReDraw:
53
			break;
62
		system.color.get();
54
         
63
		DefineAndDrawWindow(screen.width/4, screen.height/4, 
55
		case evReDraw:
64
			preview_width + 9, preview_height + skin_height + TOOLBAR_H,
56
			sc.get();
65
			0x74, 0, "EasyShot v0.3",0);
57
			DefineAndDrawWindow(b_screen_width/4, b_screen_height/4, s_screen_width + 9, s_screen_height + skin_height + 45,0x74, 0, "EasyShot v0.2",0);
66
		GetProcessInfo(#Form, SelfInfo);
Line 58... Line 67...
58
			GetProcessInfo(#Form, SelfInfo);
67
		if (Form.status_window>2) break;
59
			if (Form.status_window>2) break;
68
		DrawBar(0, 0, Form.cwidth, TOOLBAR_H-4, system.color.work);
60
			DrawBar(0, 0, Form.cwidth, 41, sc.work);
69
		DrawStandartCaptButton(10, 10, BTN_MAKE_SCREENSHOT, "Take a screenshot");
61
			DrawCaptButton(10, 10, 140, 20, 10, sc.work_button, sc.work_button_text, "Make screenshot");
70
		_PutImage(0, Form.cheight - preview_height,  preview_width, preview_height, preview);
62
			_PutImage(0, Form.cheight - s_screen_height,  s_screen_width, s_screen_height, s_screen);
71
		if (ESDWORD[preview]==0) {
63
			if (ESDWORD[s_screen]==0) 
72
			WriteTextB(Form.cwidth/2 - 90, Form.cheight/2+10, 0x90, 0xFFFfff, "There will be a preview");
64
				WriteTextB(Form.cwidth/2 - 60, Form.cheight/2+10, 0x90, 0xFFFfff, "There will be preview");
73
		}
-
 
74
		else {
-
 
75
			DrawStandartCaptButton(200, 10, BTN_SAVE, "Save");
-
 
76
		}
-
 
77
	}
-
 
78
}
-
 
79
 
-
 
80
void EventTakeScreenshot() {
-
 
81
	MinimizeWindow();
-
 
82
	pause(100);
-
 
83
	CopyScreen(b_screen, 0, 0, screen.width, screen.height);
-
 
84
	ZoomImageTo50percent();
-
 
85
	ActivateWindow(GetProcessSlot(Form.ID));
-
 
86
	//_PutImage(0, Form.cheight - preview_height,  preview_width, preview_height, preview);
-
 
87
}
-
 
88
 
-
 
89
void EventSaveFile()
-
 
90
{
-
 
91
	SaveFile(b_screen, screen.width, screen.height, "/tmp0/1/screen.png");
-
 
92
}
-
 
93
 
-
 
94
void SaveFile(dword _image, _w, _h, _path)
-
 
95
{
-
 
96
	dword encoded_data=0;
-
 
97
	dword encoded_size=0;
-
 
98
	dword image_ptr = 0;
-
 
99
	
-
 
100
	image_ptr = create_image(Image_bpp24, _w, _h);
-
 
101
 
-
 
102
	if (image_ptr == 0) {
-
 
103
		notify("'Error saving file, probably not enought memory!' -E");
-
 
104
	}
-
 
105
	else {
-
 
106
		EDI = image_ptr;
-
 
107
		memmov(EDI._Image.Data, _image, _w * _h * 3);
-
 
108
 
-
 
109
		encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size);
-
 
110
 
-
 
111
		img_destroy stdcall(image_ptr);
65
			else
112
 
Line 66... Line 113...
66
			DrawCaptButton(160, 10, 80, 20, 11, sc.work_button, sc.work_button_text, "Save");
113
		if(encoded_data == 0) {
67
      }
114
			notify("'Error saving file, incorrect data!' -E");
68
   }
115
		}
69
}
116
		else {
70
 
117
			if (WriteFile(encoded_size, encoded_data, _path) == 0) {
71
void TakeScreenshot() {
118
				notify("'File saved as /rd/1/saved_image.png' -O");
72
	MinimizeWindow();
119
			}
73
	pause(20);
120
			else {
74
	CopyScreen(b_screen, 0, 0, b_screen_width, b_screen_height);
121
				notify("'Error saving file, probably not enought space on ramdisk!' -E");
75
	ZoomImageTo50percent();
122
			}
76
	ActivateWindow(GetProcessSlot(Form.ID));
123
		}
Line 77... Line 124...
77
	//_PutImage(0, Form.cheight - s_screen_height,  s_screen_width, s_screen_height, s_screen);
124
	}
Line 78... Line 125...
78
}
125
}
79
 
126
 
80
void ZoomImageTo50percent() {
127
void ZoomImageTo50percent() {
81
	dword point_x,
128
	dword point_x,
82
	      item_h= b_screen_width * 3,
129
	      item_h= screen.width * 3,
83
	      s_off = s_screen + 3,
130
	      s_off = preview + 3,
Line 116... Line 163...
116
	
163
	
117
		s_off+=3;
164
		s_off+=3;
Line 118... Line 165...
118
		b_off+=6;
165
		b_off+=6;
119
 
166
 
120
		point_x+=2;
167
		point_x+=2;
121
		if (point_x >= b_screen_width) 
168
		if (point_x >= screen.width) 
122
		{
169
		{
123
			b_off += item_h;
170
			b_off += item_h;
124
			point_x = 0;
171
			point_x = 0;