Subversion Repositories Kolibri OS

Rev

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