Appearance v2.0: code refactoring, bigger font, add RMB menu, item search by first letter

git-svn-id: svn://kolibrios.org@6212 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-02-13 11:00:14 +00:00
parent 4a01275caa
commit c76a2da0d0

View File

@ -1,4 +1,5 @@
//11.03.12 - start! //11.03.12 - start!
//ver 2.0
#ifndef AUTOBUILD #ifndef AUTOBUILD
?include "lang.h--" ?include "lang.h--"
@ -9,13 +10,21 @@
#include "..\lib\strings.h" #include "..\lib\strings.h"
#include "..\lib\io.h" #include "..\lib\io.h"
#include "..\lib\list_box.h" #include "..\lib\list_box.h"
#include "..\lib\menu.h"
#include "..\lib\gui.h" #include "..\lib\gui.h"
#include "..\lib\obj\box_lib.h" #include "..\lib\obj\box_lib.h"
//===================================================//
// //
// DATA //
// //
//===================================================//
#ifdef LANG_RUS #ifdef LANG_RUS
?define WINDOW_HEADER "“¯à ¢«¥­¨¥ ⥬®©" ?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"
@ -24,13 +33,16 @@
unsigned char icons[]= FROM "icons.raw"; unsigned char icons[]= FROM "icons.raw";
#define PANEL_H 30 #define PANEL_H 40
#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[2]; llist list;
int active; signed int active_tab, active_skin=-1, active_wallpaper=-1;
enum { SKINS, WALLPAPERS }; enum { SKINS=2, WALLPAPERS };
char folder_path[4096]; char folder_path[4096];
char cur_file_path[4096]; char cur_file_path[4096];
@ -43,105 +55,12 @@ proc_info Form;
scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
void Open_Dir()
{
int j;
list[active].count = 0;
if(io.dir.buffer)free(io.dir.buffer);
io.dir.load(#folder_path,DIR_ONLYREAL);
for (j=0; j<io.dir.count; j++)
{
strcpy(#temp_filename, io.dir.position(j));
strlwr(#temp_filename);
if (active==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
if (active==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue;
cur = list[active].count;
files_mas[cur]=j;
if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[list[active].count];
list[active].count++;
}
}
void Draw_List()
{
int i;
int yyy;
int list_last;
list[SKINS].SetFont(6, 6, 10000000b);
list[WALLPAPERS].SetFont(6, 6, 10000000b);
list[SKINS].SetSizes(0, PANEL_H, Form.cwidth-scroll1.size_x-1, Form.cheight-PANEL_H, 20);
list[WALLPAPERS].SetSizes(0, PANEL_H, Form.cwidth-scroll1.size_x-1, Form.cheight-PANEL_H, 20);
if (list[active].count > list[active].visible) list_last = list[active].visible; else list_last = list[active].count;
for (i=0; i<list_last; i++;)
{
cur = list[active].first;
strcpy(#temp_filename, io.dir.position(files_mas[i+cur]));
temp_filename[strlen(#temp_filename)-4] = 0;
yyy = i*list[active].item_h+list[active].y;
if (list[active].cur_y-list[active].first==i)
{
if (system.color.work_button!=system.color.work)
{
DrawBar(0, yyy, list[active].w, list[active].item_h, system.color.work_button);
if (i<list[active].count) WriteText(12,yyy+list[active].text_y,0x80,system.color.work_button_text, #temp_filename);
}
else
{
DrawBar(0, yyy, list[active].w, list[active].item_h, 0x94AECE);
if (i<list[active].count) WriteText(12,yyy+list[active].text_y,0x80,0x000000, #temp_filename);
}
}
else
{
DrawBar(0,yyy,list[active].w, list[active].item_h, 0xFFFfff);
WriteText(12,yyy+list[active].text_y,0x80,0, #temp_filename);
}
}
DrawBar(0,list_last*list[active].item_h+list[active].y, list[active].w, -list_last*list[active].item_h+ list[active].h, 0xFFFfff);
DrawScroller();
}
void GetFiles()
{
if (list[SKINS].active)
{
strcpy(#folder_path, SKINS_STANDART_PATH);
Open_Dir();
if (!list[active].count) notify("'No skins were found' -E");
}
if (list[WALLPAPERS].active)
{
strcpy(#folder_path, WALP_STANDART_PATH);
Open_Dir();
if (!list[active].count) notify("'No wallpapers were found' -E");
}
}
void Apply()
{
if (list[SKINS].active)
{
cur = list[SKINS].cur_y;
sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
SetSystemSkin(#cur_file_path);
}
if (list[WALLPAPERS].active)
{
cur = list[WALLPAPERS].cur_y;
sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur]));
RunProgram("/sys/media/kiv", #cur_file_path);
Draw_List();
}
}
OpenFile()
{
if (list[SKINS].active) RunProgram("/sys/skincfg", #cur_file_path);
if (list[WALLPAPERS].active) RunProgram("/sys/media/kiv", #cur_file_path);
}
//===================================================//
// //
// CODE //
// //
//===================================================//
void main() void main()
{ {
@ -149,79 +68,104 @@ void main()
SetEventMask(0x27); SetEventMask(0x27);
load_dll(boxlib, #box_lib_init,0); load_dll(boxlib, #box_lib_init,0);
list[SKINS].cur_y = list[WALLPAPERS].cur_y = -1; EventTabClick(SKINS);
list[SKINS].first = list[WALLPAPERS].first = 0;
TabClick(SKINS);
list[WALLPAPERS].SetSizes(0, 230, 350, 400-PANEL_H, 18);
list[SKINS].SetSizes(0, 230, 350, 400-PANEL_H, 18);
loop() switch(WaitEvent()) loop() switch(WaitEvent())
{ {
case evMouse: case evMouse:
if (!CheckActiveProcess(Form.ID)) break; if (!CheckActiveProcess(Form.ID)) break;
mouse.get(); mouse.get();
scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll1);
if (list[active].first != scroll1.position) if (list.first != scroll1.position)
{ {
list[active].first = scroll1.position; list.first = scroll1.position;
Draw_List(); Draw_List();
break; break;
} }
if (mouse.vert) if (mouse.vert) && (list.MouseScroll(mouse.vert)) Draw_List();
{
if (list[SKINS].active) && (list[SKINS].MouseScroll(mouse.vert)) Draw_List();
if (list[WALLPAPERS].active) && (list[WALLPAPERS].MouseScroll(mouse.vert)) Draw_List();
}
if (mouse.up)&&(mouse_clicked) if (mouse.up)&&(mouse_clicked)
{ {
if (mouse.lkm) &&(list[SKINS].active) && (list[SKINS].ProcessMouse(mouse.x, mouse.y)) Apply(); if (mouse.lkm) && (list.ProcessMouse(mouse.x, mouse.y)) EventApply();
if (mouse.lkm) &&(list[WALLPAPERS].active) && (list[WALLPAPERS].ProcessMouse(mouse.x, mouse.y)) Apply();
mouse_clicked=false; mouse_clicked=false;
} }
else if (mouse.down)&&(mouse.lkm) && (list[SKINS].MouseOver(mouse.x, mouse.y)) mouse_clicked=true; else if (mouse.down)&&(mouse.lkm) && (list.MouseOver(mouse.x, mouse.y)) mouse_clicked=true;
if (mouse.down)&&(mouse.pkm) {
list.ProcessMouse(mouse.x, mouse.y);
Draw_List();
menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 136, "Open file Enter\nDelete Del", 10);
}
break; break;
case evButton: case evButton:
id=GetButtonID(); id=GetButtonID();
if (id==1) ExitProcess(); if (id==1) ExitProcess();
if (id==2) TabClick(WALLPAPERS); if (id==SKINS) EventTabClick(SKINS);
if (id==3) TabClick(SKINS); if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
break; break;
case evKey: case evKey:
GetKeys(); GetKeys();
if (list[SKINS].active) && (list[SKINS].ProcessKey(key_scancode)) Apply(); if (list.ProcessKey(key_scancode)) EventApply();
if (list[WALLPAPERS].active) && (list[WALLPAPERS].ProcessKey(key_scancode)) Apply(); if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
IF (key_scancode==SCAN_CODE_ENTER) OpenFile(); if (key_scancode==SCAN_CODE_TAB) if (active_tab==SKINS) EventTabClick(WALLPAPERS); else EventTabClick(SKINS);
if (key_scancode==SCAN_CODE_TAB) if (list[SKINS].active) TabClick(WALLPAPERS); else TabClick(SKINS); if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
IF (key_scancode==SCAN_CODE_TAB) //Del for (id=list.cur_y+1; id<list.count; id++)
{ {
DeleteFile(#cur_file_path); strcpy(#temp_filename, io.dir.position(files_mas[id]));
Open_Dir(); if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
Apply(); {
list.cur_y = id - 1;
list.KeyDown();
EventApply();
break;
}
} }
break; break;
case evReDraw: case evReDraw:
system.color.get(); system.color.get();
DefineAndDrawWindow(30,80,list[active].w+9,list[active].h+4+GetSkinHeight(),0x73,0xE4DFE1,WINDOW_HEADER,0); DefineAndDrawWindow(screen.width-400/2,80,400,404+skin_height,0x73,0xE4DFE1,WINDOW_HEADER,0);
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
IF (Form.status_window>=2) break; IF (Form.status_window>=2) break;
DrawTabs(); DrawWindowContent();
Draw_List(); debugi(menu.list.cur_y);
if (menu.list.cur_y) {
if (menu.list.cur_y == 10) EventOpenFile();
if (menu.list.cur_y == 11) EventDeleteFile();
menu.list.cur_y = 0;
};
} }
} }
#define BT_PADDING 16 void DrawWindowContent()
{
int id;
list.SetFont(8, 14, 0x90);
id = list.cur_y;
list.SetSizes(LIST_PADDING, PANEL_H, Form.cwidth-scroll1.size_x-LIST_PADDING-LIST_PADDING, Form.cheight-PANEL_H-LIST_PADDING, 20);
list.cur_y = id;
void DrawTab(dword x,y, but_id, is_active, text) 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);
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);
if (isdir(WALP_STANDART_PATH)) DrawTab(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);
Draw_List();
}
void DrawTab(dword x,y, but_id, text)
{ {
dword col_bg, col_text; dword col_bg, col_text;
dword w=strlen(text)*6+BT_PADDING, h=21; dword w=strlen(text)*8+TAB_PADDING, h=TAB_HEIGHT;
y -= h;
if (is_active) if (but_id==active_tab)
{ {
col_bg=system.color.work_button; col_bg=system.color.work_button;
col_text=system.color.work_button_text; col_text=system.color.work_button_text;
@ -232,55 +176,132 @@ void DrawTab(dword x,y, but_id, is_active, text)
col_text=system.color.work_text; col_text=system.color.work_text;
} }
DrawCaptButton(x,y, w-1,h+1, but_id, col_bg, col_text, text); DrawCaptButton(x,y, w-1,h+1, but_id, col_bg, col_text, text);
_PutImage(x+6,y+4, 16,15, but_id-2*16*15*3+#icons); _PutImage(x+10,h-16/2+y+1, 16,15, but_id-2*16*15*3+#icons);
} }
void DrawTabs()
{
DrawBar(0,0, Form.cwidth, PANEL_H-1, system.color.work);
DrawTab(10,7, 3, list[SKINS].active, T_SKINS);
if (isdir(WALP_STANDART_PATH)) DrawTab(strlen(T_SKINS)*6+BT_PADDING+21,7, 2, list[WALLPAPERS].active, T_WALLPAPERS);
DrawBar(0,PANEL_H-2, Form.cwidth, 1, system.color.work_graph);
DrawBar(0,PANEL_H-1, Form.cwidth, 1, 0xEEEeee);
}
void TabClick(int N)
{
if (N==SKINS)
{
list[SKINS].active = 1;
list[WALLPAPERS].active = 0;
}
if (N==WALLPAPERS)
{
list[SKINS].active = 0;
list[WALLPAPERS].active = 1;
}
active = N;
GetFiles();
DrawTabs();
Draw_List();
}
void DrawScroller() void DrawScroller()
{ {
scroll1.bckg_col = 0xBBBbbb; scroll1.bckg_col = 0xBBBbbb;
scroll1.frnt_col = system.color.work; scroll1.frnt_col = system.color.work;
scroll1.line_col = system.color.work_graph; scroll1.line_col = system.color.work_graph;
scroll1.max_area = list[active].count; scroll1.max_area = list.count;
scroll1.cur_area = list[active].visible; scroll1.cur_area = list.visible;
scroll1.position = list[active].first; scroll1.position = list.first;
scroll1.all_redraw=1; scroll1.all_redraw=1;
scroll1.start_x = list[active].x + list[active].w; scroll1.start_x = list.x + list.w;
scroll1.start_y = list[active].y-2; scroll1.start_y = list.y-1;
scroll1.size_y = list[active].h+2; scroll1.size_y = list.h+2;
scrollbar_v_draw(#scroll1); scrollbar_v_draw(#scroll1);
} }
void Open_Dir()
{
int j;
list.count = 0;
if(io.dir.buffer)free(io.dir.buffer);
io.dir.load(#folder_path,DIR_ONLYREAL);
for (j=0; j<io.dir.count; j++)
{
strcpy(#temp_filename, io.dir.position(j));
strlwr(#temp_filename);
if (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;
cur = list.count;
files_mas[cur]=j;
if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[list.count];
list.count++;
}
}
void Draw_List()
{
int i, yyy, list_last;
if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
for (i=0; (i<list_last); i++;)
{
cur = list.first + i;
strcpy(#temp_filename, io.dir.position(files_mas[cur]));
temp_filename[strlen(#temp_filename)-4] = 0;
yyy = i*list.item_h+list.y;
if (list.cur_y-list.first==i)
{
DrawBar(list.x, yyy, list.w, list.item_h, system.color.work_button);
WriteText(list.x+12,yyy+list.text_y,list.font_type,system.color.work_button_text, #temp_filename);
}
else
{
DrawBar(list.x,yyy,list.w, list.item_h, 0xFFFfff);
WriteText(list.x+12,yyy+list.text_y,list.font_type,0, #temp_filename);
}
}
DrawBar(list.x,i*list.item_h+list.y, list.w, -i*list.item_h+ list.h, 0xFFFfff);
DrawScroller();
}
//===================================================//
// //
// EVENTS //
// //
//===================================================//
void EventTabClick(int N)
{
active_tab = N;
if (active_tab == SKINS)
{
active_wallpaper = list.cur_y;
strcpy(#folder_path, SKINS_STANDART_PATH);
list.ClearList();
Open_Dir();
if (!list.count) notify("'No skins were found' -E");
list.cur_y = active_skin;
}
if (active_tab == WALLPAPERS)
{
active_skin = list.cur_y;
strcpy(#folder_path, WALP_STANDART_PATH);
list.ClearList();
Open_Dir();
if (!list.count) notify("'No wallpapers were found' -E");
list.cur_y = active_wallpaper;
}
if (list.w) DrawWindowContent();
}
void EventDeleteFile()
{
io.del(#cur_file_path);
Open_Dir();
EventApply();
}
void EventApply()
{
if (active_tab==SKINS)
{
cur = list.cur_y;
sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
SetSystemSkin(#cur_file_path);
}
if (active_tab==WALLPAPERS)
{
cur = list.cur_y;
sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur]));
RunProgram("/sys/media/kiv", #cur_file_path);
Draw_List();
}
}
void EventOpenFile()
{
if (active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
if (active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
}
stop: stop: