Notes 0.7 ALPHA

git-svn-id: svn://kolibrios.org@7331 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-09-09 17:02:05 +00:00
parent bd55a099d5
commit 29e0e255d4
11 changed files with 367 additions and 19 deletions

View File

@ -203,25 +203,6 @@
}
:int GetFile(dword buf, filesize, read_path)
{
int return_val = 0;
BDVK ReadFile_atr;
dword rBuf;
if (! GetFileInfo(read_path, #ReadFile_atr))
{
rBuf = malloc(ReadFile_atr.sizelo);
if (! ReadFile(0, ReadFile_atr.sizelo, rBuf, read_path))
{
ESDWORD[buf] = rBuf;
ESDWORD[filesize] = ReadFile_atr.sizelo;
return_val = 1;
}
}
free(rBuf);
return return_val;
}
enum
{
DIRS_ALL,

View File

@ -0,0 +1,6 @@
if tup.getconfig("NO_CMM") ~= "" then return end
if tup.getconfig("LANG") == "ru"
then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config
end
tup.rule("notes.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "notes.com")

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

View File

@ -0,0 +1,9 @@
@del lang.h--
@echo #define LANG_ENG 1 >lang.h--
C-- notes.c
@del notes
@rename notes.com notes
@pause
@del lang.h--
@del warning.txt

BIN
programs/cmm/notes/edge.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

File diff suppressed because one or more lines are too long

132
programs/cmm/notes/engine.h Normal file
View File

@ -0,0 +1,132 @@
#define LINES_COUNT 13
#define MAX_LINE_CHARS 256
#define CHBOX 12
#define CHECKBOX_ID 50
unsigned char checkbox[sizeof(file "checkbox.raw")]= FROM "checkbox.raw";
#define COL_BG_ACTIVE 0xFFE56B
#define COL_BG_INACTIVE 0xFFFFFF
//===================================================//
// //
// LINE //
// //
//===================================================//
struct NOTE_LINE
{
bool state;
char data[MAX_LINE_CHARS];
};
//===================================================//
// //
// LIST //
// //
//===================================================//
struct NOTES {
llist list;
char txt_path[4096];
char txt_data[MAX_LINE_CHARS*LINES_COUNT];
NOTE_LINE lines[LINES_COUNT];
char edit_active;
int OpenTxt();
int SaveTxt();
void DeleteCurrentNode();
void DrawList();
dword DrawLine(int line_n, draw_h);
} notes;
int NOTES::OpenTxt(dword file_path)
{
int i=0, linepos=0;
int item_n=-1;
strcpy(#txt_path, file_path);
ReadFile(0, 4096, #txt_data, #txt_path);
if (!txt_data) || (strncmp(#txt_data, "notes", 5)!=0)
{
notify("'Notes\nData file does not exists or is not valid' -tE");
return 0;
}
else
{
i+=5; //skip "notes" indefinier
while (txt_data[i])
{
if (txt_data[i]=='\n') {
item_n++;
i+=2;
if (txt_data[i]=='-') lines[item_n].state=false; else lines[item_n].state=true;
i+=2;
linepos = 0;
continue;
}
if (linepos<MAX_LINE_CHARS) lines[item_n].data[linepos] = txt_data[i];
linepos++;
i++;
}
list.count = item_n;
return 1;
}
}
int NOTES::SaveTxt()
{
int i;
dword tm;
strcpy(#txt_data, "notes");
for (i=0; i<=list.count; i++)
{
if (lines[i].state==false) strcat(#txt_data, "\n- "); else strcat(#txt_data, "\n+ ");
tm = #lines[i].data;
strcat(#txt_data, #lines[i].data);
}
WriteFile(0, strlen(#txt_data), #txt_data, #txt_path);
}
void NOTES::DeleteCurrentNode()
{
return;
}
void NOTES::DrawList()
{
int i;
for (i=0; i<list.visible; i++) DrawLine(i, list.item_h);
}
dword NOTES::DrawLine(int line_n, draw_h) {
dword
COL_BOTTOM_LINE=0xE8EFF4,
COL_BG,
cur_text;
char line_text[4096];
if (line_n<0) return;
if (line_n==list.cur_y) COL_BG = COL_BG_ACTIVE; else COL_BG = COL_BG_INACTIVE;
DrawBar(list.x, line_n*list.item_h+list.y, RED_LINE_X, draw_h-1, COL_BG_INACTIVE);
DrawBar(list.x+RED_LINE_X+1, line_n*list.item_h+list.y, list.w-RED_LINE_X-1, draw_h-1, COL_BG);
cur_text = #lines[line_n].data;
if (draw_h!=list.item_h)
{
COL_BOTTOM_LINE=COL_BG;
}
else
{
DefineButton(RED_LINE_X-CHBOX/2+list.x, list.item_h*line_n+5+list.y, CHBOX-1,CHBOX-1, CHECKBOX_ID+line_n+BT_HIDE, 0); //checkbox
_PutImage(RED_LINE_X-CHBOX/2+list.x, list.item_h*line_n+5+list.y, CHBOX,CHBOX, lines[line_n].state*CHBOX*CHBOX*3+#checkbox);
if (cur_text) WriteText(list.x+RED_LINE_X+6, list.item_h*line_n+7+list.y, 0x80, lines[line_n].state*0x777777, cur_text);
if (lines[line_n].state == true) DrawBar(list.x+RED_LINE_X+6, list.item_h*line_n+11+list.y, strlen(cur_text)*6, 1, 0x444444); //strike
}
DrawBar(list.x, line_n*list.item_h+draw_h-1+list.y, list.w, 1, COL_BOTTOM_LINE);
DrawBar(list.x+RED_LINE_X, line_n*list.item_h+list.y, 1, draw_h, COL_RED_LINE);
return cur_text;
}

BIN
programs/cmm/notes/notes Normal file

Binary file not shown.

213
programs/cmm/notes/notes.c Normal file
View File

@ -0,0 +1,213 @@
// Notes v0.7 ALPHA
#define MEMSIZE 0xDAE80
#include "..\lib\kolibri.h"
#include "..\lib\mem.h"
#include "..\lib\strings.h"
#include "..\lib\fs.h"
#include "..\lib\dll.h"
#include "..\lib\obj\box_lib.h"
#include "..\lib\gui.h"
#include "..\lib\encoding.h"
#include "..\lib\list_box.h"
//===================================================//
// //
// DATA //
// //
//===================================================//
#ifndef AUTOBUILD
#include "lang.h--"
#endif
#define LANG_RUS
#ifdef LANG_RUS
?define WINDOW_CAPTION "‡ ¬¥âª¨"
?define DELETE_TEXT "Udoli";
#else
?define WINDOW_CAPTION "Notes and reminders"
?define DELETE_TEXT "Delete";
#endif
#define RED_LINE_X 22
#define COL_RED_LINE 0xF3C9C9
unsigned char edge[sizeof(file "edge.raw")]= FROM "edge.raw"; //292x6
#define EDGE_H 6
#define TITLE_H 24
#define HEADER_HEIGHT TITLE_H+EDGE_H
#define DELETE_BTN 4;
#include "engine.h"
dword editbox_text;
proc_info Form;
edit_box edit_box= {0,999,0,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,MAX_LINE_CHARS-1,#editbox_text,#mouse,100000000000010b};
dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
//===================================================//
// //
// CODE //
// //
//===================================================//
struct KDelete {
char width;
char active;
void Draw();
} DeleteBtn;
void KDelete::Draw(dword x, y, h)
{
width = strlen(DELETE_TEXT)+2*6;
x -= width+1;
DefineButton(x, y, width, h-1, DELETE_BTN, 0xFF0000);
WriteText(x+6+1, h/2-4+y, 0x80, 0xFFFfff, DELETE_TEXT);
}
void main()
{
int btn;
dword cur_line_offset;
load_dll(boxlib, #box_lib_init,0);
if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
notes.list.cur_y = -1;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
loop() switch(WaitEvent())
{
case evMouse:
mouse.get();
if (notes.list.MouseOver(mouse.x, mouse.y)) {
notes.list.ProcessMouse(mouse.x, mouse.y);
if (mouse.lkm) EventSelectItem();
if (mouse.pkm) EventDrawDeleteButton();
}
if (mouse.lkm) && (mouse.y<TITLE_H) && (mouse.x<Form.width-30) EventDragWindow();
if (notes.list.cur_y>=0) edit_box_mouse stdcall (#edit_box);
break;
case evButton:
btn = GetButtonID();
if (CLOSE_BTN == btn) EventExitApp();
if (DELETE_BTN == btn)
{
notes.DeleteCurrentNode();
notes.DrawList();
DeleteBtn.active = 0;
break;
}
if (btn>=CHECKBOX_ID) //checkboxes
{
notes.lines[btn-CHECKBOX_ID].state ^= 1;
notes.DrawList();
break;
}
break;
case evKey:
GetKeys();
if (SCAN_CODE_ESC == key_scancode) EventExitApp();
if (SCAN_CODE_DOWN == key_scancode) { EventActivateLine(notes.list.cur_y+1); break; }
if (SCAN_CODE_UP == key_scancode) { EventActivateLine(notes.list.cur_y-1); break; }
if (notes.list.cur_y>=0) edit_box_key stdcall (#edit_box);
break;
case evReDraw:
draw_window();
}
}
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;
notes.list.SetSizes(1, HEADER_HEIGHT, 270, RED_LINE_X*LINES_COUNT, RED_LINE_X);
DefineAndDrawWindow(100,100,notes.list.w+1,notes.list.h+HEADER_HEIGHT+4,0x01,0,0,0x01fffFFF);
//DefineDragableWindow(100, 100, notes.list.w+1, notes.list.h+HEADER_HEIGHT+4);
GetProcessInfo(#Form, SelfInfo);
DrawRectangle3D(0,0,Form.width,TITLE_H-1,0xBB6535, 0xCD6F3B);
DrawRectangle3D(1,1,Form.width-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
DrawBar(2,2,Form.width-3,TITLE_H-4,0xE08C5E);
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);
PutPixel(notes.list.x+RED_LINE_X, notes.list.y-1, COL_RED_LINE);
ECX-=1; $int 0x40;
DrawCloseButton(Form.width-23,4,16,16);
DrawRectangle(0,TITLE_H,Form.width,Form.height-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
for (i=0; lists[i]!=0; i++) DrawBar(1,Form.height-i-1, Form.width-1, 1, lists[i]);
edit_box.width = notes.list.w-RED_LINE_X-8;
edit_box.left = notes.list.x+RED_LINE_X+4;
notes.DrawList();
}
void DrawEditBox_Notes()
{
edit_box.pos = edit_box.offset = edit_box.shift = 0;
edit_box.size = strlen(edit_box.text);
edit_box.top = notes.list.cur_y*notes.list.item_h+4+notes.list.y;
edit_box_draw stdcall(#edit_box);
}
//===================================================//
// //
// EVENTS //
// //
//===================================================//
void EventActivateLine(int line_n)
{
int old;
if (line_n<0) || (line_n>notes.list.count) return;
DeleteBtn.active = 0;
//redraw lines
notes.list.cur_y = line_n;
edit_box.text = notes.DrawLine(notes.list.cur_y, notes.list.item_h);
notes.DrawList();
DrawEditBox_Notes();
}
void EventExitApp()
{
notes.SaveTxt();
ExitProcess();
}
void EventDrawDeleteButton()
{
notes.DrawLine(notes.list.cur_y, notes.list.item_h);
DeleteBtn.Draw(notes.list.x+notes.list.w, notes.list.cur_y*notes.list.item_h+notes.list.y, notes.list.item_h);
edit_box.top=-20;
DeleteBtn.active = 1;
}
void EventSelectItem()
{
int id;
id = mouse.y-notes.list.y/notes.list.item_h;
if (DeleteBtn.active) && (mouse.x>notes.list.x+notes.list.w-DeleteBtn.width) return;
if (id!=notes.list.cur_y) && (id<notes.list.count) EventActivateLine(id);
else { notes.list.cur_y=-1; notes.DrawList(); }
}
stop:

View File

@ -0,0 +1,6 @@
notes
+ lorem ipsum dolor sit amet
+ sed diam nonummy nibh euismod
+ consectetuer adipiscing elit
- Nunc viverra imperdiet
- Pellentesque habitant morbi tristique