Subversion Repositories Kolibri OS

Rev

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

Rev 7331 Rev 7422
Line 1... Line 1...
1
// Notes v0.7 ALPHA 
1
// Notes v0.8 ALPHA 
Line 2... Line 2...
2
 
2
 
3
#define MEMSIZE 0xDAE80
3
#define MEMSIZE 0xDAE80
4
#include "..\lib\kolibri.h" 
4
#include "..\lib\kolibri.h" 
5
#include "..\lib\mem.h" 
5
#include "..\lib\mem.h" 
Line 20... Line 20...
20
 
20
 
21
#ifndef AUTOBUILD
21
#ifndef AUTOBUILD
22
	#include "lang.h--"
22
	#include "lang.h--"
Line 23... Line -...
23
#endif
-
 
24
 
-
 
25
#define LANG_RUS
23
#endif
26
 
24
 
27
#ifdef LANG_RUS
25
#ifdef LANG_RUS
28
	?define WINDOW_CAPTION "‡ ¬¥âª¨"
26
	?define WINDOW_CAPTION "‡ ¬¥âª¨"
29
	?define DELETE_TEXT "Udoli";
27
	?define DELETE_TEXT "“¤ «¨âì";
30
#else
28
#else
31
	?define WINDOW_CAPTION "Notes and reminders"
29
	?define WINDOW_CAPTION "Notes and reminders"
Line 36... Line 34...
36
#define COL_RED_LINE 0xF3C9C9
34
#define COL_RED_LINE 0xF3C9C9
37
unsigned char edge[sizeof(file "edge.raw")]= FROM "edge.raw"; //292x6
35
unsigned char edge[sizeof(file "edge.raw")]= FROM "edge.raw"; //292x6
38
#define EDGE_H 6
36
#define EDGE_H 6
39
#define TITLE_H 24
37
#define TITLE_H 24
40
#define HEADER_HEIGHT TITLE_H+EDGE_H
38
#define HEADER_HEIGHT TITLE_H+EDGE_H
-
 
39
#define LINES_COUNT 13
-
 
40
 
-
 
41
#define WIN_W 270
-
 
42
#define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4
Line 41... Line 43...
41
 
43
 
-
 
44
#define DELETE_BTN 4;
Line 42... Line 45...
42
#define DELETE_BTN 4;
45
#define DELETE_W sizeof(DELETE_TEXT)+2*6
Line 43... Line 46...
43
 
46
 
44
#include "engine.h"
-
 
45
 
47
#include "engine.h"
-
 
48
 
46
dword editbox_text;
49
dword ed_mouse;
Line -... Line 50...
-
 
50
edit_box notebox = {0,999,0,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,
-
 
51
	MAX_LINE_CHARS-1,NULL,#ed_mouse,ed_always_focus+ed_focus};
-
 
52
dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
47
proc_info Form;
53
 
48
edit_box edit_box= {0,999,0,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,MAX_LINE_CHARS-1,#editbox_text,#mouse,100000000000010b};
54
bool delete_active = false;
49
dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
55
block delBtn;
50
 
56
 
51
//===================================================//
57
//===================================================//
Line 52... Line -...
52
//                                                   //
-
 
53
//                       CODE                        //
-
 
54
//                                                   //
-
 
55
//===================================================//
-
 
56
 
-
 
57
struct KDelete {
-
 
58
	char width;
-
 
59
	char active;
-
 
60
	void Draw();
-
 
61
} DeleteBtn;
-
 
62
 
-
 
63
void KDelete::Draw(dword x, y, h)
-
 
64
{
-
 
65
	width = strlen(DELETE_TEXT)+2*6;
-
 
66
	x -= width+1;
58
//                                                   //
67
	DefineButton(x, y, width, h-1, DELETE_BTN, 0xFF0000);
59
//                       CODE                        //
68
	WriteText(x+6+1, h/2-4+y, 0x80, 0xFFFfff, DELETE_TEXT);
60
//                                                   //
69
}
61
//===================================================//
70
 
62
 
Line 71... Line 63...
71
void main()
63
void main()
72
{   
64
{   
Line 73... Line 65...
73
	int btn;
65
	int btn;
Line 74... Line 66...
74
	dword cur_line_offset;
66
	dword cur_line_offset;
75
	load_dll(boxlib, #box_lib_init,0);
67
	load_dll(boxlib, #box_lib_init,0);
76
	
68
	
-
 
69
	if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
-
 
70
	notes.cur_y = -1;
77
	if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
71
 
Line 78... Line 72...
78
	notes.list.cur_y = -1;
72
	SetEventMask(0x27);
-
 
73
 
-
 
74
	loop() switch(WaitEvent())
-
 
75
	{
-
 
76
		case evMouse:
79
 
77
			edit_box_mouse stdcall (#notebox);
80
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
78
 
81
 
79
			mouse.get();
82
	loop() switch(WaitEvent())
80
 
Line 83... Line 81...
83
	{
81
			if (delete_active) && (delBtn.hovered()) break;
-
 
82
 
-
 
83
			if (mouse.lkm) && (mouse.y
-
 
84
 
-
 
85
			if (mouse.pkm) 
Line 84... Line -...
84
		case evMouse:
-
 
85
			mouse.get();
86
			&& (notes.MouseOver(mouse.x, mouse.y)) {
Line 86... Line 87...
86
 
87
				if (notes.ProcessMouse(mouse.x, mouse.y)) EventListRedraw();
87
			if (notes.list.MouseOver(mouse.x, mouse.y)) {
88
				EventDrawDeleteButton();
88
    			notes.list.ProcessMouse(mouse.x, mouse.y);
-
 
89
				if (mouse.lkm) EventSelectItem();
89
			} 
90
				if (mouse.pkm) EventDrawDeleteButton();
90
 
91
			}
-
 
92
 
91
			if (mouse.key&MOUSE_LEFT)&&(mouse.up) 
93
			if (mouse.lkm) && (mouse.y
92
			&& (notes.ProcessMouse(mouse.x, mouse.y)) {
94
 
93
				EventListRedraw();
95
			if (notes.list.cur_y>=0) edit_box_mouse stdcall (#edit_box);
94
				EventActivateLine(notes.cur_y);
96
			break;
95
			}
97
 
96
 
-
 
97
			break;
98
		 case evButton:
98
 
99
			btn = GetButtonID();               
99
		 case evButton:
100
			if (CLOSE_BTN == btn) EventExitApp();
100
			btn = GetButtonID();
101
			if (DELETE_BTN == btn)
101
			switch(btn)
102
			{
102
			{
Line 103... Line 103...
103
				notes.DeleteCurrentNode();
103
				case CLOSE_BTN:
104
				notes.DrawList();
104
					EventExitApp();
-
 
105
					break;
-
 
106
				case DELETE_BTN:
-
 
107
					EventDeleteCurrentNode();
105
				DeleteBtn.active = 0;
108
					break;
-
 
109
				default: 
-
 
110
					notes.lines[btn-CHECKBOX_ID].state ^= 1;
106
				break;
111
					EventListRedraw();
-
 
112
					break;
-
 
113
			}  
107
			}
114
			break;
-
 
115
	 
-
 
116
		case evKey:
-
 
117
			GetKeys();
-
 
118
			switch(key_scancode)
108
			if (btn>=CHECKBOX_ID) //checkboxes
119
			{
-
 
120
				case SCAN_CODE_ESC:
-
 
121
					EventExitApp();
-
 
122
					break;
109
			{
123
				case SCAN_CODE_DOWN:
Line 110... Line 124...
110
				notes.lines[btn-CHECKBOX_ID].state ^= 1;
124
					EventActivateLine(notes.cur_y+1);
111
				notes.DrawList();
125
					break;
112
				break;
126
				case SCAN_CODE_UP:
113
			}
127
					EventActivateLine(notes.cur_y-1);
Line 114... Line -...
114
			break;
-
 
115
	 
128
					break;
116
		case evKey:
129
				default:
117
			GetKeys();
130
					if (notes.cur_y>=0) {
118
			if (SCAN_CODE_ESC  == key_scancode) EventExitApp();
131
						EAX = key_editbox;
119
			if (SCAN_CODE_DOWN == key_scancode) { EventActivateLine(notes.list.cur_y+1); break; }
132
						edit_box_key stdcall (#notebox);
Line 137... Line 150...
137
}
150
}
Line 138... Line 151...
138
 
151
 
139
void draw_window()
152
void draw_window()
140
{
153
{
141
	int i;
-
 
142
	notes.list.SetSizes(1, HEADER_HEIGHT, 270, RED_LINE_X*LINES_COUNT, RED_LINE_X);
154
	int i;
143
	DefineAndDrawWindow(100,100,notes.list.w+1,notes.list.h+HEADER_HEIGHT+4,0x01,0,0,0x01fffFFF);
155
	DefineUnDragableWindow(100,100,WIN_W, WIN_H);
144
	//DefineDragableWindow(100, 100, notes.list.w+1, notes.list.h+HEADER_HEIGHT+4);
-
 
145
	GetProcessInfo(#Form, SelfInfo);
156
	notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X);
146
	DrawRectangle3D(0,0,Form.width,TITLE_H-1,0xBB6535, 0xCD6F3B);
157
	DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B);
147
	DrawRectangle3D(1,1,Form.width-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
158
	DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
148
	DrawBar(2,2,Form.width-3,TITLE_H-4,0xE08C5E);
159
	DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E);
149
	WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
160
	WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
150
	WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
161
	WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
151
	_PutImage(1, TITLE_H, 292,EDGE_H, #edge);
162
	_PutImage(1, TITLE_H, 292,EDGE_H, #edge);
152
	PutPixel(notes.list.x+RED_LINE_X, notes.list.y-1, COL_RED_LINE);
163
	PutPixel(notes.x+RED_LINE_X, notes.y-1, COL_RED_LINE);
153
	ECX-=1;	$int 0x40;
164
	ECX-=1;	$int 0x40;
154
	DrawCloseButton(Form.width-23,4,16,16);
165
	DrawCloseButton(WIN_W-23,4,16,16);
155
	DrawRectangle(0,TITLE_H,Form.width,Form.height-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
166
	DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
156
	for (i=0; lists[i]!=0; i++) DrawBar(1,Form.height-i-1, Form.width-1, 1, lists[i]);
-
 
157
	edit_box.width = notes.list.w-RED_LINE_X-8;
-
 
158
	edit_box.left = notes.list.x+RED_LINE_X+4;
-
 
159
 
167
	for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]);
160
	notes.DrawList();
168
	EventListRedraw();
Line 161... Line 169...
161
}
169
}
162
 
170
 
-
 
171
void DrawEditBoxN()
-
 
172
{
163
void DrawEditBox_Notes()
173
	notebox.width = notes.w-notes.x-8;
-
 
174
	notebox.left = notes.x+5;
164
{
175
	notebox.pos = notebox.offset = notebox.shift = notebox.shift_old = 0;
165
	edit_box.pos = edit_box.offset = edit_box.shift = 0;
176
	notebox.cl_curs_x = notebox.cl_curs_y = 0;
166
	edit_box.size = strlen(edit_box.text);
177
	notebox.size = strlen(notebox.text);
167
	edit_box.top = notes.list.cur_y*notes.list.item_h+4+notes.list.y;
178
	notebox.top = notes.cur_y*notes.item_h+4+notes.y;
Line 168... Line 179...
168
	edit_box_draw stdcall(#edit_box);	
179
	edit_box_draw stdcall(#notebox);	
169
}
180
}
170
 
181
 
171
//===================================================//
182
//===================================================//
172
//                                                   //
183
//                                                   //
Line 173... Line 184...
173
//                     EVENTS                        //
184
//                     EVENTS                        //
174
//                                                   //
185
//                                                   //
175
//===================================================//
-
 
176
 
186
//===================================================//
177
void EventActivateLine(int line_n)
-
 
178
{
-
 
179
	int old;
187
 
180
	if (line_n<0) || (line_n>notes.list.count) return;
188
void EventActivateLine(int line_n)
181
	DeleteBtn.active = 0;
189
{
182
	//redraw lines
190
	if (line_n<0) || (line_n>notes.count) return;
183
	notes.list.cur_y = line_n;
191
	notes.cur_y = line_n;
Line 184... Line -...
184
	edit_box.text = notes.DrawLine(notes.list.cur_y, notes.list.item_h);
-
 
185
	notes.DrawList();
192
	notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
186
	DrawEditBox_Notes();
193
	EventListRedraw();
187
}
194
	DrawEditBoxN();
188
 
195
}
189
 
196
 
Line 190... Line 197...
190
void EventExitApp()
197
void EventExitApp()
191
{
198
{
192
	notes.SaveTxt();
199
	notes.SaveTxt();
193
	ExitProcess();
200
	ExitProcess();
-
 
201
}
-
 
202
 
194
}
203
void EventDrawDeleteButton()
195
 
204
{
-
 
205
	notes.DrawLine(notes.cur_y, notes.item_h);
-
 
206
	delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1);
-
 
207
	DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
-
 
208
	WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
-
 
209
	notebox.top=-20;
-
 
210
	delete_active = true;
196
void EventDrawDeleteButton()
211
}
Line 197... Line 212...
197
{
212
 
198
	notes.DrawLine(notes.list.cur_y, notes.list.item_h);
213
void EventDeleteCurrentNode()
199
	DeleteBtn.Draw(notes.list.x+notes.list.w, notes.list.cur_y*notes.list.item_h+notes.list.y, notes.list.item_h);
214
{
200
	edit_box.top=-20;
215
	notes.lines[notes.cur_y].Delete();
201
	DeleteBtn.active = 1;
-
 
202
}
-
 
203
 
216
	EventListRedraw();
204
void EventSelectItem()
217
}
Line 205... Line 218...
205
{
218