Subversion Repositories Kolibri OS

Rev

Rev 7984 | Rev 8955 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7444 leency 1
// Notes v1.1
7331 leency 2
 
8954 leency 3
#define MEMSIZE 1024*40
4
#define ENTRY_POINT #main
5
 
7331 leency 6
#include "..\lib\kolibri.h"
7
 
8
#include "..\lib\obj\box_lib.h"
9
#include "..\lib\gui.h"
10
#include "..\lib\list_box.h"
11
 
12
//===================================================//
13
//                                                   //
14
//                       DATA                        //
15
//                                                   //
16
//===================================================//
17
 
18
#ifdef LANG_RUS
19
	?define WINDOW_CAPTION "Заметки"
7422 leency 20
	?define DELETE_TEXT "Удалить";
7331 leency 21
#else
22
	?define WINDOW_CAPTION "Notes and reminders"
23
	?define DELETE_TEXT "Delete";
24
#endif
25
 
26
#define RED_LINE_X 22
27
#define COL_RED_LINE 0xF3C9C9
7434 leency 28
unsigned char edge[sizeof(file "img/edge.raw")]= FROM "img/edge.raw"; //292x6
7331 leency 29
#define EDGE_H 6
30
#define TITLE_H 24
31
#define HEADER_HEIGHT TITLE_H+EDGE_H
7422 leency 32
#define LINES_COUNT 13
7331 leency 33
 
7422 leency 34
#define WIN_W 270
35
#define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4
36
 
7331 leency 37
#define DELETE_BTN 4;
7422 leency 38
#define DELETE_W sizeof(DELETE_TEXT)+2*6
7331 leency 39
 
40
#include "engine.h"
7532 leency 41
#include "ini.h"
8954 leency 42
 
43
proc_info Form;
7331 leency 44
 
8954 leency 45
edit_box notebox = {WIN_W-RED_LINE_X-6,RED_LINE_X+5,RED_LINE_X,
46
	COL_BG_ACTIVE, 0x94AECE,COL_BG_ACTIVE,0xffffff,0,
47
	MAX_LINE_CHARS-1, NULL,0,ed_always_focus+ed_focus};
7331 leency 48
dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
49
 
7422 leency 50
bool delete_active = false;
7444 leency 51
bool window_dragable = true;
8954 leency 52
block delBtn = { WIN_W-DELETE_W-1, NULL, DELETE_W, RED_LINE_X};
7422 leency 53
 
7331 leency 54
//===================================================//
55
//                                                   //
56
//                       CODE                        //
57
//                                                   //
58
//===================================================//
59
 
60
void main()
61
{
7434 leency 62
	bool first_redraw=true;
7331 leency 63
	load_dll(boxlib, #box_lib_init,0);
7444 leency 64
 
65
	if (GetCpuFrequency()/1000000>=1000) window_dragable=true; else window_dragable=false;
7331 leency 66
 
7640 leency 67
	if (param) notes.OpenTxt(#param); else notes.OpenTxt("/sys/notes.txt");
7331 leency 68
 
7984 leency 69
	@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
7532 leency 70
	LoadIniSettings();
7984 leency 71
	loop() switch(@WaitEvent())
7331 leency 72
	{
73
		case evMouse:
7422 leency 74
			edit_box_mouse stdcall (#notebox);
75
 
7331 leency 76
			mouse.get();
77
 
7422 leency 78
			if (delete_active) && (delBtn.hovered()) break;
79
 
7444 leency 80
			if (mouse.lkm) && (mouse.y
81
				&& (window_dragable) EventDragWindow();
7422 leency 82
 
83
			if (mouse.pkm)
84
			&& (notes.MouseOver(mouse.x, mouse.y)) {
85
				if (notes.ProcessMouse(mouse.x, mouse.y)) EventListRedraw();
86
				EventDrawDeleteButton();
87
			}
88
 
89
			if (mouse.key&MOUSE_LEFT)&&(mouse.up)
90
			&& (notes.ProcessMouse(mouse.x, mouse.y)) {
7434 leency 91
				notebox.pos = mouse.x - notebox.left / 6;
7422 leency 92
				EventListRedraw();
93
				EventActivateLine(notes.cur_y);
7331 leency 94
			}
95
 
96
			break;
97
 
98
		 case evButton:
7984 leency 99
			@GetButtonID();
100
			switch(EAX)
7331 leency 101
			{
7422 leency 102
				case CLOSE_BTN:
103
					EventExitApp();
104
					break;
105
				case DELETE_BTN:
106
					EventDeleteCurrentNode();
107
					break;
108
				default:
7984 leency 109
					EventCheckBoxClick(EAX-CHECKBOX_ID);
7422 leency 110
					break;
111
			}
7331 leency 112
			break;
113
 
114
		case evKey:
8954 leency 115
			@GetKeys();
7434 leency 116
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
117
			{
118
				if (key_scancode == SCAN_CODE_SPACE)
119
				{
120
					EventCheckBoxClick(notes.cur_y);
121
				}
122
			}
7422 leency 123
			switch(key_scancode)
124
			{
125
				case SCAN_CODE_ESC:
126
					EventExitApp();
127
					break;
128
				case SCAN_CODE_DOWN:
129
					EventActivateLine(notes.cur_y+1);
130
					break;
131
				case SCAN_CODE_UP:
132
					EventActivateLine(notes.cur_y-1);
133
					break;
134
				default:
135
					if (notes.cur_y>=0) {
136
						EAX = key_editbox;
137
						edit_box_key stdcall (#notebox);
138
					}
139
 
140
			}
7331 leency 141
			break;
142
 
143
		 case evReDraw:
144
		 	draw_window();
7434 leency 145
		 	if (first_redraw) {
146
		 		first_redraw = false;
147
		 		EventActivateLine(0);
148
		 	}
7331 leency 149
   }
150
}
151
 
152
void DrawCloseButton(dword x,y,w,h)
153
{
154
	DrawRectangle(x,y,w,h,0xC96832);
155
	DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452);
156
	PutPixel(x+w-1, y+1, 0xE08C5E);
157
	DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0);
158
	WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x");
159
}
160
 
161
void draw_window()
162
{
163
	int i;
7444 leency 164
	if (window_dragable)
7532 leency 165
		DefineUnDragableWindow(Form.left,Form.top,WIN_W, WIN_H);
7444 leency 166
	else
7532 leency 167
		DefineDragableWindow(Form.left,Form.top,WIN_W, WIN_H);
168
	GetProcessInfo(#Form, SelfInfo);
7422 leency 169
	notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X);
170
	DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B);
171
	DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
172
	DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E);
7331 leency 173
	WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
174
	WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
175
	_PutImage(1, TITLE_H, 292,EDGE_H, #edge);
7437 leency 176
	PutPixel(notes.x, notes.y-1, COL_RED_LINE);
7331 leency 177
	ECX-=1;	$int 0x40;
7422 leency 178
	DrawCloseButton(WIN_W-23,4,16,16);
179
	DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
180
	for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]);
181
	EventListRedraw();
7331 leency 182
}
183
 
184
//===================================================//
185
//                                                   //
186
//                     EVENTS                        //
187
//                                                   //
188
//===================================================//
189
 
190
void EventActivateLine(int line_n)
191
{
7444 leency 192
	if (line_n<0) || (line_n>=notes.count) return;
7422 leency 193
	notes.cur_y = line_n;
194
	notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
195
	EventListRedraw();
8954 leency 196
 
197
	notebox.size = strlen(notebox.text);
198
	notebox.offset = notebox.shift = notebox.shift_old = 0;
199
	notebox.cl_curs_x = notebox.cl_curs_y = 0;
200
	if (notebox.pos > notebox.size) notebox.pos = notebox.size;
201
	notebox.top = notes.cur_y*notes.item_h+4+notes.y;
202
	edit_box_draw stdcall(#notebox);
7331 leency 203
}
204
 
205
void EventExitApp()
206
{
207
	notes.SaveTxt();
7532 leency 208
	SaveIniSettings();
7331 leency 209
	ExitProcess();
210
}
211
 
212
void EventDrawDeleteButton()
213
{
7422 leency 214
	notes.DrawLine(notes.cur_y, notes.item_h);
8954 leency 215
	delBtn.y = notes.cur_y*notes.item_h+notes.y;
7422 leency 216
	DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
217
	WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
218
	notebox.top=-20;
219
	delete_active = true;
7331 leency 220
}
221
 
7422 leency 222
void EventDeleteCurrentNode()
7331 leency 223
{
7629 leency 224
	dword t;
225
	t = notes.cur_y;
7434 leency 226
	notes.lines[t].Delete();
7422 leency 227
	EventListRedraw();
7331 leency 228
}
229
 
7422 leency 230
void EventListRedraw()
231
{
232
	delete_active = false;
233
	DeleteButton(DELETE_BTN);
234
	notes.DrawList();
235
}
236
 
7434 leency 237
void EventCheckBoxClick(int id)
238
{
239
	notes.lines[id].state ^= 1;
240
	EventListRedraw();
241
}
242
 
7331 leency 243
stop: