gui.h: add tabs component, use it for kf_font_viewer and appearance; fix font.h crash when '_' is the last

git-svn-id: svn://kolibrios.org@6264 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-02-20 13:06:19 +00:00
parent 06644f770e
commit e3cfd43e3b
10 changed files with 128 additions and 72 deletions

View File

@ -23,25 +23,21 @@
#ifdef LANG_RUS #ifdef LANG_RUS
?define WINDOW_HEADER "<EFBFBD> áâனª¨ ®ä®à¬«¥­¨ï" ?define WINDOW_HEADER "<EFBFBD> áâனª¨ ®ä®à¬«¥­¨ï"
?define T_SKINS " ‘â¨«ì ®ª®­" ?define T_SKINS "‘â¨«ì ®ª®­"
?define T_WALLPAPERS " Ž¡®¨" ?define T_WALLPAPERS "Ž¡®¨"
#else #else
?define WINDOW_HEADER "Appearance" ?define WINDOW_HEADER "Appearance"
?define T_SKINS " Skins" ?define T_SKINS "Skins"
?define T_WALLPAPERS " Wallpappers" ?define T_WALLPAPERS "Wallpappers"
#endif #endif
unsigned char icons[]= FROM "icons.raw";
#define PANEL_H 40 #define PANEL_H 40
#define LIST_PADDING 20 #define LIST_PADDING 20
#define TAB_PADDING 16
#define TAB_HEIGHT 25
#define SKINS_STANDART_PATH "/kolibrios/res/skins" #define SKINS_STANDART_PATH "/kolibrios/res/skins"
#define WALP_STANDART_PATH "/kolibrios/res/wallpapers" #define WALP_STANDART_PATH "/kolibrios/res/wallpapers"
llist list; llist list;
signed int active_tab, active_skin=-1, active_wallpaper=-1; signed int active_skin=-1, active_wallpaper=-1;
enum { SKINS=2, WALLPAPERS }; enum { SKINS=2, WALLPAPERS };
char folder_path[4096]; char folder_path[4096];
@ -111,7 +107,7 @@ void main()
GetKeys(); GetKeys();
if (list.ProcessKey(key_scancode)) EventApply(); if (list.ProcessKey(key_scancode)) EventApply();
if (key_scancode==SCAN_CODE_ENTER) EventOpenFile(); if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
if (key_scancode==SCAN_CODE_TAB) if (active_tab==SKINS) EventTabClick(WALLPAPERS); else EventTabClick(SKINS); if (key_scancode==SCAN_CODE_TAB) if (tabs.active_tab==SKINS) EventTabClick(WALLPAPERS); else EventTabClick(SKINS);
if (key_scancode==SCAN_CODE_DEL) EventDeleteFile(); if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
for (id=list.cur_y+1; id<list.count; id++) for (id=list.cur_y+1; id<list.count; id++)
{ {
@ -152,33 +148,13 @@ void DrawWindowContent()
DrawBar(0,0, Form.cwidth, PANEL_H-LIST_PADDING, system.color.work); DrawBar(0,0, Form.cwidth, PANEL_H-LIST_PADDING, system.color.work);
DrawRectangle3D(list.x-2, list.y-2, list.w+3+scroll1.size_x, list.h+3, system.color.work_dark, system.color.work_light); DrawRectangle3D(list.x-2, list.y-2, list.w+3+scroll1.size_x, list.h+3, system.color.work_dark, system.color.work_light);
DrawWideRectangle(list.x-LIST_PADDING, list.y-LIST_PADDING, LIST_PADDING*2+list.w+scroll1.size_x, LIST_PADDING*2+list.h, LIST_PADDING-2, system.color.work); DrawWideRectangle(list.x-LIST_PADDING, list.y-LIST_PADDING, LIST_PADDING*2+list.w+scroll1.size_x, LIST_PADDING*2+list.h, LIST_PADDING-2, system.color.work);
DrawTab(list.x+10, list.y, SKINS, T_SKINS); tabs.draw(list.x+10, list.y, SKINS, T_SKINS);
if (dir_exists(WALP_STANDART_PATH)) DrawTab(strlen(T_SKINS)*8+TAB_PADDING+list.x+21, list.y, WALLPAPERS, T_WALLPAPERS); if (dir_exists(WALP_STANDART_PATH)) tabs.draw(strlen(T_SKINS)*8+TAB_PADDING+list.x+21, list.y, WALLPAPERS, T_WALLPAPERS);
DrawRectangle(list.x-1, list.y-1, list.w+1+scroll1.size_x, list.h+1, system.color.work_graph); DrawRectangle(list.x-1, list.y-1, list.w+1+scroll1.size_x, list.h+1, system.color.work_graph);
Draw_List(); Draw_List();
} }
void DrawTab(dword x,y, but_id, text)
{
dword col_bg, col_text;
dword w=strlen(text)*8+TAB_PADDING, h=TAB_HEIGHT;
y -= h;
if (but_id==active_tab)
{
col_bg=system.color.work_button;
col_text=system.color.work_button_text;
}
else
{
col_bg=system.color.work;
col_text=system.color.work_text;
}
DrawCaptButton(x,y, w-1,h+1, but_id, col_bg, col_text, text);
_PutImage(x+10,h-16/2+y+1, 16,15, but_id-2*16*15*3+#icons);
}
void DrawScroller() void DrawScroller()
{ {
scroll1.bckg_col = MixColors(system.color.work, 0xBBBbbb, 80); scroll1.bckg_col = MixColors(system.color.work, 0xBBBbbb, 80);
@ -207,8 +183,8 @@ void Open_Dir()
{ {
strcpy(#temp_filename, io.dir.position(j)); strcpy(#temp_filename, io.dir.position(j));
strlwr(#temp_filename); strlwr(#temp_filename);
if (active_tab==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue; if (tabs.active_tab==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
if (active_tab==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue; if (tabs.active_tab==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue;
cur = list.count; cur = list.count;
files_mas[cur]=j; files_mas[cur]=j;
if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[list.count]; if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[list.count];
@ -252,8 +228,8 @@ void Draw_List()
void EventTabClick(int N) void EventTabClick(int N)
{ {
active_tab = N; tabs.click(N);
if (active_tab == SKINS) if (tabs.active_tab == SKINS)
{ {
active_wallpaper = list.cur_y; active_wallpaper = list.cur_y;
strcpy(#folder_path, SKINS_STANDART_PATH); strcpy(#folder_path, SKINS_STANDART_PATH);
@ -262,7 +238,7 @@ void EventTabClick(int N)
if (!list.count) notify("'No skins were found' -E"); if (!list.count) notify("'No skins were found' -E");
list.cur_y = active_skin; list.cur_y = active_skin;
} }
if (active_tab == WALLPAPERS) if (tabs.active_tab == WALLPAPERS)
{ {
active_skin = list.cur_y; active_skin = list.cur_y;
strcpy(#folder_path, WALP_STANDART_PATH); strcpy(#folder_path, WALP_STANDART_PATH);
@ -271,6 +247,7 @@ void EventTabClick(int N)
if (!list.count) notify("'No wallpapers were found' -E"); if (!list.count) notify("'No wallpapers were found' -E");
list.cur_y = active_wallpaper; list.cur_y = active_wallpaper;
} }
if (list.cur_y>list.visible) list.first=list.cur_y; list.CheckDoesValuesOkey();
if (list.w) DrawWindowContent(); if (list.w) DrawWindowContent();
} }
@ -283,13 +260,13 @@ void EventDeleteFile()
void EventApply() void EventApply()
{ {
if (active_tab==SKINS) if (tabs.active_tab==SKINS)
{ {
cur = list.cur_y; cur = list.cur_y;
sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur])); sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
SetSystemSkin(#cur_file_path); SetSystemSkin(#cur_file_path);
} }
if (active_tab==WALLPAPERS) if (tabs.active_tab==WALLPAPERS)
{ {
cur = list.cur_y; cur = list.cur_y;
sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur])); sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur]));
@ -300,8 +277,8 @@ void EventApply()
void EventOpenFile() void EventOpenFile()
{ {
if (active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path); if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
if (active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path); if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
} }
stop: stop:

View File

@ -7,4 +7,3 @@ C-- appearance.c
@del warning.txt @del warning.txt
@del lang.h-- @del lang.h--
@pause @pause
kpack appearance

View File

@ -7,4 +7,3 @@ C-- appearance.c
@del warning.txt @del warning.txt
@del lang.h-- @del lang.h--
@pause @pause
kpack appearance

Binary file not shown.

Before

Width:  |  Height:  |  Size: 521 B

View File

@ -1 +0,0 @@
œ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüœ|tœ|tüüüôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´üüüœ|tœ|tüüüôÜ´ôÜ´ôäËôäËôäËôäËôÜ´ôÜ´ôÜ´ôÜ´ôÜ´ôÜ´üüüœ|tœ|tüüüôäËôäËôäËôäËôäËôäËôäËôäËôäËôäËäÜÌÌÌ”üüüœ|tœ|tüüüìôììôììôììôììôììôììôììôììôì«Ám“;m“;üüüœ|tœ|tüüüôÜ´ôÜ´ôÜ´ÌÌ”˜ŸL˜ŸL«ÁÌÌ”˜ŸLm“;m“;m“;üüüœ|tœ|tüüüä¼lä¼l˜ŸLcccccccccccccc«Áccüüüœ|tœ|tüüüä¼l˜ŸLccccccccccccccœ|t«Áccüüüœ|tœ|tüüüÔ” „lsm sm sm sm sm sm sm œ|t«Ásm üüüœ|tœ|tüüüϨPϨPϨPϨPϨPϨPϨPϨPϨP«Á«ÁϨPüüüœ|tœ|tüüüä¼lä¼lä¼lä¼lä¼lä¼lä¼lä¼lä¼lä¼l«Áä¼lüüüœ|tœ|tüüüÔ” Ô” Ô” Ô” Ô” Ô” Ô” Ô” Ô” Ô” Ô” Ô” üüüœ|tœ|tüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tœ|tx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`XàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀx`XŠpfŠpfŠpfŠpf¸—‡àÈÀàÈÀ¸—‡ŠpfŠpfŠpfŠpfŠpf¸—‡àÈÀx`XððèððèððèäààŠpfàÈÀàÈÀŠpf<70><66>è••Ñ<E280A2><C391>è••Ñ<E280A2><C391>èŠpfàÈÀx`XððèððèððèððèŠpfàÈÀàÈÀŠpf••Ñÿÿÿ••Ñÿÿÿ••ÑŠpfàÈÀx`XäààäààäààäààŠpfàÈÀàÈÀŠpf<70><66>è••Ñÿÿÿ••Ñ<E280A2><C391>èŠpfàÈÀx`Xˆ<58><CB86>ˆ<EFBFBD><CB86>ˆ<EFBFBD><CB86>àààŠpfàÈÀàÈÀŠpf••Ñÿÿÿ••Ñÿÿÿ••ÑŠpfàÈÀx`XÐÄÄÐÄÄÐÄÄÐÄÄŠpfàÈÀàÈÀŠpf€€È€€È€€È€€È€€ÈŠpfàÈÀx`XŠpfŠpfŠpfŠpf¸—‡àÈÀàÈÀ¸—‡ŠpfŠpfŠpfŠpfŠpf¸—‡àÈÀx`XàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀàÈÀx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xx`Xàààààààààààààààààààààààààààààààààààààààààààààx`Xàààààààààààààààààààààààààààààààààààààààààààààx`Xàààààààààààààààààààààààààààààààààààààààààààààx`Xàààààààààààààààààààààààààààààààààààààààààààààx`X

View File

@ -10,7 +10,7 @@ char *ext[]={
"exe", 7, "msi", 7, "exe", 7, "msi", 7,
"sys", 8, "ocx", 8, "drv", 8, "so", 8, "sys", 8, "ocx", 8, "drv", 8, "so", 8,
"inc", 9, "inc", 9,
"chr", 10, "mt", 10, "ttf", 10, "fon", 10, "chr", 10, "mt", 10, "ttf", 10, "fon", 10, "kf", 10,
"asm", 11, "asm", 11,
"mp3", 12, "wav", 12, "mid", 12, "midi",12, "ogg", 12, "wma", 12, "flac",12, "mp3", 12, "wav", 12, "mid", 12, "midi",12, "ogg", 12, "wma", 12, "flac",12,
"skn", 13, "skn", 13,

View File

@ -4,50 +4,87 @@
#include "../lib/gui.h" #include "../lib/gui.h"
#define PANELH 30 #define PANELH 30
proc_info Form;
enum {
STRONG_BTN=10, ITALIC_BTN, SMOOTH_BTN,
PHRASE_TAB=20, CHARS_TAB
};
void main() void main()
{ {
proc_info Form; int btn;
int i, y, btn; char title[4196];
char line[256], title[4196];
if (!param) strcpy(#param, DEFAULT_FONT); if (!param) strcpy(#param, DEFAULT_FONT);
label.init(#param); label.init(#param);
tabs.active_tab=PHRASE_TAB;
strcpy(#title, "Font preview: "); strcpy(#title, "Font preview: ");
strcat(#title, #param); strcat(#title, #param);
loop() loop() switch(WaitEvent())
{ {
switch(WaitEvent())
{
case evButton: case evButton:
btn = GetButtonID(); btn = GetButtonID();
if (btn==1) ExitProcess(); if (btn==1) ExitProcess();
if (btn==2) label.bold ^=1; if (btn==STRONG_BTN) label.bold ^=1;
if (btn==3) label.italic ^=1; if (btn==ITALIC_BTN) label.italic ^=1;
if (btn==4) label.smooth ^=1; if (btn==SMOOTH_BTN) label.smooth ^=1;
if (btn==PHRASE_TAB) || (btn==CHARS_TAB) tabs.click(btn);
goto _DRAW_WINDOW_CONTENT; goto _DRAW_WINDOW_CONTENT;
case evReDraw: case evReDraw:
system.color.get(); system.color.get();
DefineAndDrawWindow(215,100,500,320,0x74,0xFFFFFF,#title); DefineAndDrawWindow(215,100,500,320+skin_height,0x74,0xFFFFFF,#title);
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
if (Form.status_window>2) break; if (Form.status_window>2) break;
_DRAW_WINDOW_CONTENT: _DRAW_WINDOW_CONTENT:
DrawBar(0, 0, Form.cwidth, PANELH, system.color.work); DrawBar(0, 0, Form.cwidth, PANELH-1, system.color.work);
CheckBox(10, 8, 2, "Bold", label.bold); CheckBox(10, 8, STRONG_BTN, "Bold", label.bold);
CheckBox(83, 8, 3, "Italic", label.italic); CheckBox(83, 8, ITALIC_BTN, "Italic", label.italic);
CheckBox(170, 8, 4, "Smooth", label.smooth); CheckBox(170,8, SMOOTH_BTN, "Smooth", label.smooth);
label.raw_size = free(label.raw); tabs.draw(Form.cwidth-150, PANELH, PHRASE_TAB, "Phrase");
tabs.draw(Form.cwidth-70, PANELH, CHARS_TAB, "Chars");
DrawBar(0, PANELH-1,Form.cwidth,1,system.color.work_graph);
if (!label.font) if (!label.font)
{ {
DrawBar(0, PANELH, Form.cwidth, Form.cheight - PANELH, 0xFFFfff); DrawBar(0, PANELH, Form.cwidth, Form.cheight - PANELH, 0xFFFfff);
WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded."); WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded.");
break;
} }
else for (i=10, y=5; i<22; i++, y+=label.height;) //not flexible, need to calculate font count and max line length if (tabs.active_tab==PHRASE_TAB) DrawPreviewPhrase();
{ if (tabs.active_tab==CHARS_TAB) DrawPreviewChars();
sprintf(#line,"<EFBFBD> §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i);
label.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, i, #line);
}
if (label.smooth) label.apply_smooth();
label.show_buf(0, PANELH);
}
} }
} }
void DrawPreviewPhrase()
{
dword i, y;
char line[256];
label.raw_size = free(label.raw);
for (i=10, y=5; i<22; i++, y+=label.height;) //not flexible, need to calculate font count and max line length
{
sprintf(#line,"<EFBFBD> §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i);
label.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, i, #line);
}
if (label.smooth) label.apply_smooth();
label.show_buf(0, PANELH);
}
void DrawPreviewChars()
{
dword i, x=20, y=0;
char line[2];
line[1]=NULL;
label.raw_size = free(label.raw);
for (i=0; i<255; i++) //not flexible, need to calculate font count and max line length
{
line[0]=i;
label.write_buf(x,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, 16, #line);
x+= label.height+2;
if (x>=Form.cwidth-30) {
x=20;
y+=label.height+2;
}
}
if (label.smooth) label.apply_smooth();
label.show_buf(0, PANELH);
}

View File

@ -133,7 +133,7 @@
} }
size.width += rw; size.width += rw;
IF(bold) size.width+=size.TMP_WEIGHT; IF(bold) size.width+=size.TMP_WEIGHT;
IF(s=='_') size.width--; //IF(s=='_') size.width--; //http://board.kolibrios.org/viewtopic.php?f=44&t=973&start=645
IF(size.offset_x<0)size.offset_x = X; IF(size.offset_x<0)size.offset_x = X;
} }
:byte LABEL::symbol(signed x,y; byte s; dword image_raw) :byte LABEL::symbol(signed x,y; byte s; dword image_raw)
@ -275,7 +275,7 @@ inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
len = size.offset_x; len = size.offset_x;
WHILE(DSBYTE[text1]) WHILE(DSBYTE[text1])
{ {
IF(DSBYTE[text1]=='_') len--; //IF(DSBYTE[text1]=='_') len--; //http://board.kolibrios.org/viewtopic.php?f=44&t=973&start=645
len+=symbol(len,0,DSBYTE[text1], raw); len+=symbol(len,0,DSBYTE[text1], raw);
IF(bold)len+=math.ceil(size.pt/17); IF(bold)len+=math.ceil(size.pt/17);
text1++; text1++;

View File

@ -267,4 +267,49 @@ dword incn::inc(dword _addition)
return n; return n;
} }
/*=========================================================
==
== TABS
==
/========================================================*/
#define TAB_PADDING 25
#define TAB_HEIGHT 25
struct _tabs
{
int active_tab;
void draw();
int click();
} tabs;
void _tabs::draw(dword x,y, but_id, text)
{
dword col_bg, col_text;
dword w=strlen(text)*8+TAB_PADDING, h=TAB_HEIGHT;
y -= h;
if (but_id==active_tab)
{
col_bg=system.color.work_button;
col_text=system.color.work_button_text;
}
else
{
col_bg=system.color.work;
col_text=system.color.work_text;
}
DrawCaptButton(x,y, w-1,h+1, but_id, col_bg, col_text, text);
}
int _tabs::click(int N)
{
if (N==active_tab) return false;
active_tab = N;
return true;
}
#endif #endif