Subversion Repositories Kolibri OS

Rev

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