2018-10-09 22:12:02 +03:00
|
|
|
|
// Notes v1.1
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
|
|
|
|
#define MEMSIZE 0xDAE80
|
|
|
|
|
#include "..\lib\kolibri.h"
|
|
|
|
|
|
|
|
|
|
#include "..\lib\obj\box_lib.h"
|
|
|
|
|
#include "..\lib\gui.h"
|
|
|
|
|
#include "..\lib\list_box.h"
|
|
|
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
|
// //
|
|
|
|
|
// DATA //
|
|
|
|
|
// //
|
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
|
|
#ifndef AUTOBUILD
|
|
|
|
|
#include "lang.h--"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef LANG_RUS
|
|
|
|
|
?define WINDOW_CAPTION "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>⪨"
|
2018-10-01 19:41:14 +03:00
|
|
|
|
?define DELETE_TEXT "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
2018-09-09 20:02:05 +03:00
|
|
|
|
#else
|
|
|
|
|
?define WINDOW_CAPTION "Notes and reminders"
|
|
|
|
|
?define DELETE_TEXT "Delete";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define RED_LINE_X 22
|
|
|
|
|
#define COL_RED_LINE 0xF3C9C9
|
2018-10-04 23:08:44 +03:00
|
|
|
|
unsigned char edge[sizeof(file "img/edge.raw")]= FROM "img/edge.raw"; //292x6
|
2018-09-09 20:02:05 +03:00
|
|
|
|
#define EDGE_H 6
|
|
|
|
|
#define TITLE_H 24
|
|
|
|
|
#define HEADER_HEIGHT TITLE_H+EDGE_H
|
2018-10-01 19:41:14 +03:00
|
|
|
|
#define LINES_COUNT 13
|
|
|
|
|
|
|
|
|
|
#define WIN_W 270
|
|
|
|
|
#define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
|
|
|
|
#define DELETE_BTN 4;
|
2018-10-01 19:41:14 +03:00
|
|
|
|
#define DELETE_W sizeof(DELETE_TEXT)+2*6
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
2018-11-06 18:54:32 +03:00
|
|
|
|
proc_info Form;
|
|
|
|
|
|
2018-09-09 20:02:05 +03:00
|
|
|
|
#include "engine.h"
|
2018-11-06 18:54:32 +03:00
|
|
|
|
#include "ini.h"
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
2018-10-04 23:08:44 +03:00
|
|
|
|
edit_box notebox = {NULL,NULL,NULL,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,
|
2020-05-26 03:17:12 +03:00
|
|
|
|
MAX_LINE_CHARS-1,NULL,0,ed_always_focus+ed_focus};
|
2018-09-09 20:02:05 +03:00
|
|
|
|
dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
|
|
|
|
|
|
2018-10-01 19:41:14 +03:00
|
|
|
|
bool delete_active = false;
|
2018-10-09 22:12:02 +03:00
|
|
|
|
bool window_dragable = true;
|
2018-10-01 19:41:14 +03:00
|
|
|
|
block delBtn;
|
|
|
|
|
|
2018-09-09 20:02:05 +03:00
|
|
|
|
//===================================================//
|
|
|
|
|
// //
|
|
|
|
|
// CODE //
|
|
|
|
|
// //
|
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
2018-10-04 23:08:44 +03:00
|
|
|
|
bool first_redraw=true;
|
2018-09-09 20:02:05 +03:00
|
|
|
|
dword cur_line_offset;
|
|
|
|
|
load_dll(boxlib, #box_lib_init,0);
|
2018-10-09 22:12:02 +03:00
|
|
|
|
|
|
|
|
|
if (GetCpuFrequency()/1000000>=1000) window_dragable=true; else window_dragable=false;
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
2019-04-25 20:51:39 +03:00
|
|
|
|
if (param) notes.OpenTxt(#param); else notes.OpenTxt("/sys/notes.txt");
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
2020-05-26 03:17:12 +03:00
|
|
|
|
@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
|
2018-11-06 18:54:32 +03:00
|
|
|
|
LoadIniSettings();
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
2020-05-26 03:17:12 +03:00
|
|
|
|
loop() switch(@WaitEvent())
|
2018-09-09 20:02:05 +03:00
|
|
|
|
{
|
|
|
|
|
case evMouse:
|
2018-10-01 19:41:14 +03:00
|
|
|
|
edit_box_mouse stdcall (#notebox);
|
|
|
|
|
|
2018-09-09 20:02:05 +03:00
|
|
|
|
mouse.get();
|
|
|
|
|
|
2018-10-01 19:41:14 +03:00
|
|
|
|
if (delete_active) && (delBtn.hovered()) break;
|
|
|
|
|
|
2018-10-09 22:12:02 +03:00
|
|
|
|
if (mouse.lkm) && (mouse.y<TITLE_H) && (mouse.x<WIN_W-39)
|
|
|
|
|
&& (window_dragable) EventDragWindow();
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
2018-10-01 19:41:14 +03:00
|
|
|
|
if (mouse.pkm)
|
|
|
|
|
&& (notes.MouseOver(mouse.x, mouse.y)) {
|
|
|
|
|
if (notes.ProcessMouse(mouse.x, mouse.y)) EventListRedraw();
|
|
|
|
|
EventDrawDeleteButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mouse.key&MOUSE_LEFT)&&(mouse.up)
|
|
|
|
|
&& (notes.ProcessMouse(mouse.x, mouse.y)) {
|
2018-10-04 23:08:44 +03:00
|
|
|
|
notebox.pos = mouse.x - notebox.left / 6;
|
2018-10-01 19:41:14 +03:00
|
|
|
|
EventListRedraw();
|
|
|
|
|
EventActivateLine(notes.cur_y);
|
|
|
|
|
}
|
2018-09-09 20:02:05 +03:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evButton:
|
2020-05-26 03:17:12 +03:00
|
|
|
|
@GetButtonID();
|
|
|
|
|
switch(EAX)
|
2018-09-09 20:02:05 +03:00
|
|
|
|
{
|
2018-10-01 19:41:14 +03:00
|
|
|
|
case CLOSE_BTN:
|
|
|
|
|
EventExitApp();
|
|
|
|
|
break;
|
|
|
|
|
case DELETE_BTN:
|
|
|
|
|
EventDeleteCurrentNode();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-05-26 03:17:12 +03:00
|
|
|
|
EventCheckBoxClick(EAX-CHECKBOX_ID);
|
2018-10-01 19:41:14 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-09-09 20:02:05 +03:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
|
GetKeys();
|
2018-10-04 23:08:44 +03:00
|
|
|
|
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
|
|
|
|
|
{
|
|
|
|
|
if (key_scancode == SCAN_CODE_SPACE)
|
|
|
|
|
{
|
|
|
|
|
EventCheckBoxClick(notes.cur_y);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-01 19:41:14 +03:00
|
|
|
|
switch(key_scancode)
|
|
|
|
|
{
|
|
|
|
|
case SCAN_CODE_ESC:
|
|
|
|
|
EventExitApp();
|
|
|
|
|
break;
|
|
|
|
|
case SCAN_CODE_DOWN:
|
|
|
|
|
EventActivateLine(notes.cur_y+1);
|
|
|
|
|
break;
|
|
|
|
|
case SCAN_CODE_UP:
|
|
|
|
|
EventActivateLine(notes.cur_y-1);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (notes.cur_y>=0) {
|
|
|
|
|
EAX = key_editbox;
|
|
|
|
|
edit_box_key stdcall (#notebox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2018-09-09 20:02:05 +03:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evReDraw:
|
|
|
|
|
draw_window();
|
2018-10-04 23:08:44 +03:00
|
|
|
|
if (first_redraw) {
|
|
|
|
|
first_redraw = false;
|
|
|
|
|
EventActivateLine(0);
|
|
|
|
|
}
|
2018-09-09 20:02:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawCloseButton(dword x,y,w,h)
|
|
|
|
|
{
|
|
|
|
|
DrawRectangle(x,y,w,h,0xC96832);
|
|
|
|
|
DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452);
|
|
|
|
|
PutPixel(x+w-1, y+1, 0xE08C5E);
|
|
|
|
|
DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0);
|
|
|
|
|
WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void draw_window()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2018-10-09 22:12:02 +03:00
|
|
|
|
if (window_dragable)
|
2018-11-06 18:54:32 +03:00
|
|
|
|
DefineUnDragableWindow(Form.left,Form.top,WIN_W, WIN_H);
|
2018-10-09 22:12:02 +03:00
|
|
|
|
else
|
2018-11-06 18:54:32 +03:00
|
|
|
|
DefineDragableWindow(Form.left,Form.top,WIN_W, WIN_H);
|
|
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2018-10-01 19:41:14 +03:00
|
|
|
|
notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X);
|
|
|
|
|
DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B);
|
|
|
|
|
DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
|
|
|
|
|
DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E);
|
2018-09-09 20:02:05 +03:00
|
|
|
|
WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
|
|
|
|
|
WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
|
|
|
|
|
_PutImage(1, TITLE_H, 292,EDGE_H, #edge);
|
2018-10-06 01:10:27 +03:00
|
|
|
|
PutPixel(notes.x, notes.y-1, COL_RED_LINE);
|
2018-09-09 20:02:05 +03:00
|
|
|
|
ECX-=1; $int 0x40;
|
2018-10-01 19:41:14 +03:00
|
|
|
|
DrawCloseButton(WIN_W-23,4,16,16);
|
|
|
|
|
DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
|
|
|
|
|
for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]);
|
|
|
|
|
EventListRedraw();
|
2018-09-09 20:02:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 19:41:14 +03:00
|
|
|
|
void DrawEditBoxN()
|
2018-09-09 20:02:05 +03:00
|
|
|
|
{
|
2018-10-01 19:41:14 +03:00
|
|
|
|
notebox.width = notes.w-notes.x-8;
|
|
|
|
|
notebox.left = notes.x+5;
|
2018-10-04 23:08:44 +03:00
|
|
|
|
notebox.offset = notebox.shift = notebox.shift_old = 0;
|
2018-10-01 19:41:14 +03:00
|
|
|
|
notebox.cl_curs_x = notebox.cl_curs_y = 0;
|
|
|
|
|
notebox.size = strlen(notebox.text);
|
2018-10-06 01:10:27 +03:00
|
|
|
|
notebox.flags = ed_always_focus+ed_focus;
|
2018-10-04 23:08:44 +03:00
|
|
|
|
if (notebox.pos > notebox.size) notebox.pos = notebox.size;
|
2018-10-01 19:41:14 +03:00
|
|
|
|
notebox.top = notes.cur_y*notes.item_h+4+notes.y;
|
|
|
|
|
edit_box_draw stdcall(#notebox);
|
2018-09-09 20:02:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
|
// //
|
|
|
|
|
// EVENTS //
|
|
|
|
|
// //
|
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
|
|
void EventActivateLine(int line_n)
|
|
|
|
|
{
|
2018-10-09 22:12:02 +03:00
|
|
|
|
if (line_n<0) || (line_n>=notes.count) return;
|
2018-10-01 19:41:14 +03:00
|
|
|
|
notes.cur_y = line_n;
|
|
|
|
|
notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
|
|
|
|
|
EventListRedraw();
|
|
|
|
|
DrawEditBoxN();
|
2018-09-09 20:02:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventExitApp()
|
|
|
|
|
{
|
|
|
|
|
notes.SaveTxt();
|
2018-11-06 18:54:32 +03:00
|
|
|
|
SaveIniSettings();
|
2018-09-09 20:02:05 +03:00
|
|
|
|
ExitProcess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventDrawDeleteButton()
|
|
|
|
|
{
|
2018-10-01 19:41:14 +03:00
|
|
|
|
notes.DrawLine(notes.cur_y, notes.item_h);
|
|
|
|
|
delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1);
|
|
|
|
|
DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
|
|
|
|
|
WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
|
|
|
|
|
notebox.top=-20;
|
|
|
|
|
delete_active = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventDeleteCurrentNode()
|
|
|
|
|
{
|
2019-04-17 00:34:45 +03:00
|
|
|
|
dword t;
|
|
|
|
|
t = notes.cur_y;
|
2018-10-04 23:08:44 +03:00
|
|
|
|
notes.lines[t].Delete();
|
2018-10-01 19:41:14 +03:00
|
|
|
|
EventListRedraw();
|
2018-09-09 20:02:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 19:41:14 +03:00
|
|
|
|
void EventListRedraw()
|
2018-09-09 20:02:05 +03:00
|
|
|
|
{
|
2018-10-01 19:41:14 +03:00
|
|
|
|
delete_active = false;
|
|
|
|
|
DeleteButton(DELETE_BTN);
|
|
|
|
|
notes.DrawList();
|
2018-09-09 20:02:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-04 23:08:44 +03:00
|
|
|
|
void EventCheckBoxClick(int id)
|
|
|
|
|
{
|
|
|
|
|
notes.lines[id].state ^= 1;
|
|
|
|
|
EventListRedraw();
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-09 20:02:05 +03:00
|
|
|
|
stop:
|