software_widget: calculate height, better code

git-svn-id: svn://kolibrios.org@6091 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-01-24 21:16:08 +00:00
parent 1c503b8257
commit 790c51fa55
2 changed files with 75 additions and 95 deletions

View File

@ -1,7 +1,7 @@
C-- software_widget.c C-- software_widget.c
@del game_center @del game_center
@copy software_widget.com game_center @copy software_widget.com game_center
@copy software_widget.com system_panel @copy software_widget.com syspanel
@del software_widget.com @del software_widget.com
@pause @pause
@del warning.txt @del warning.txt

View File

@ -1,5 +1,5 @@
/* /*
SOFTWARE CENTER v2.4 SOFTWARE CENTER v2.8
*/ */
#define MEMSIZE 0x9000 #define MEMSIZE 0x9000
@ -12,30 +12,25 @@ SOFTWARE CENTER v2.4
#include "..\lib\obj\libimg_lib.h" #include "..\lib\obj\libimg_lib.h"
#include "..\lib\obj\libini.h" #include "..\lib\obj\libini.h"
#include "..\lib\font.h" #include "..\lib\font.h"
#include "..\lib\list_box.h"
#include "..\lib\collection.h"
#include "..\lib\patterns\libimg_load_skin.h" #include "..\lib\patterns\libimg_load_skin.h"
proc_info Form; proc_info Form;
llist list;
collection app_path_collection;
byte kolibrios_mounted; byte kolibrios_mounted;
int item_id_need_to_run=-1,
current_item_id;
int window_width, int window_width,
window_height; window_height;
int col_max, int list_pos,
cell_w, row,
cell_h, col,
list_pos, default_icon;
list_top,
row,
old_row, //to detect empty sections
col,
default_icon;
char window_title[128], char window_title[128],
settings_ini_path[256] = "/sys/settings/"; settings_ini_path[256] = "/sys/settings/";
#define LIST_BACKGROUND_COLOR 0xF3F3F3 #define LIST_BACKGROUND_COLOR 0xF3F3F3
@ -44,12 +39,10 @@ void load_config()
ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
window_width = EAX; window_width = EAX;
ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540); ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73);
window_height = EAX; list.item_w = EAX;
ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66); ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71);
cell_w = EAX; list.item_h = EAX;
ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
cell_h = EAX;
ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
default_icon = EAX; default_icon = EAX;
} }
@ -57,14 +50,15 @@ void load_config()
void main() void main()
{ {
dword id, key; dword id;
label.init("/sys/fonts/Tahoma.kf"); label.init(DEFAULT_FONT);
load_dll(libio, #libio_init,1); load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1); load_dll(libimg, #libimg_init,1);
load_dll(libini, #lib_init,1); load_dll(libini, #lib_init,1);
Libimg_LoadImage(#skin, "/sys/icons32.png"); Libimg_LoadImage(#skin, "/sys/icons32.png");
Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
kolibrios_mounted = isdir("/kolibrios");
if (param) if (param)
{ {
@ -75,63 +69,56 @@ void main()
strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/')); strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
strcat(#settings_ini_path, ".ini"); strcat(#settings_ini_path, ".ini");
} }
load_config(); load_config();
list.cur_y = -1;
list.y = 32;
loop() DrawList();
window_height = row+1*list.item_h + list_pos + skin_height + 15;
loop() switch(WaitEvent())
{ {
switch(WaitEvent()) // case evKey:
{ // GetKeys();
case evButton: // if (list.ProcessKey(key_scancode)) DrawList();
id=GetButtonID(); // break;
if (id==1) ExitProcess();
if (id>=100) case evButton:
{ id=GetButtonID();
item_id_need_to_run = id - 100; if (id==1) ExitProcess();
current_item_id = 0; if (id>=100) RunProgram(app_path_collection.get(id-100), "");
ini_enum_sections stdcall (#settings_ini_path, #process_sections);
item_id_need_to_run = -1;
}
break; break;
case evReDraw: case evReDraw:
system.color.get(); system.color.get();
DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,system.color.work,""); DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,system.color.work,"");
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
draw_top_bar(); draw_top_bar();
kolibrios_mounted = isdir("/kolibrios"); DrawList();
col_max = Form.cwidth - 10 / cell_w; DrawBar(0, row + 1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
current_item_id = 0;
row = -1;
ini_enum_sections stdcall (#settings_ini_path, #process_sections);
DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
break; break;
}
} }
} }
byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name) void DrawList() {
{ list.count = 0;
int icon_char_pos; row = -1;
if (item_id_need_to_run == current_item_id) app_path_collection.drop();
{ list_pos = list.y;
icon_char_pos = strchr(key_value, ','); list.column_max = window_width - 10 / list.item_w;
if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string ini_enum_sections stdcall (#settings_ini_path, #process_sections);
RunProgram(key_value, ""); list.visible = list.count;
}
current_item_id++;
if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) current_item_id--;
return true;
} }
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
{ {
int tmp, int tmp,
icon_id, icon_id,
icon_char_pos; icon_char_pos;
if (col==col_max) { if (col==list.column_max) {
row++; row++;
col=0; col=0;
} }
@ -139,62 +126,55 @@ byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
//do not show items located in /kolibrios/ if this directory not mounted //do not show items located in /kolibrios/ if this directory not mounted
if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true; if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true;
if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR); if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, LIST_BACKGROUND_COLOR);
DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0); DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0);
tmp = cell_w/2; tmp = list.item_w/2;
icon_char_pos = strchr(key_value, ','); icon_char_pos = strchr(key_value, ',');
if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32); img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
label.write_center(col*cell_w+7,row*cell_h+47 + list_pos, cell_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name); if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
label.write_center(col*cell_w+6,row*cell_h+46 + list_pos, cell_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name); app_path_collection.add(key_value);
current_item_id++; //label.write_center(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name);
label.write_center(col*list.item_w+6,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name);
if (list.cur_y == list.count) DrawWideRectangle(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5, 2, 0x0080FF);
list.count++;
col++; col++;
return true; return true;
} }
int old_row; //to detect empty sections
byte process_sections(dword sec_name, f_name) byte process_sections(dword sec_name, f_name)
{ {
int text_len; int text_len;
if (!strcmp(sec_name, "Config")) return true; if (!strcmp(sec_name, "Config")) return true;
if (item_id_need_to_run!=-1) if ((col==0) && (row==old_row))
{ {
ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run); list_pos -= 28;
} }
else else
{ {
if ((col==0) && (row==old_row)) row++;
{
list_pos -= 28;
}
else
{
row++;
}
col = 0;
old_row = row;
DrawBar(0, row * cell_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
//WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
text_len = label.write(10, row * cell_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name);
DrawBar(text_len+20, row * cell_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
DrawBar(text_len+20, row * cell_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
list_pos += 29;
ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
} }
col = 0;
old_row = row;
DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
text_len = label.write(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name);
DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
list_pos += 29;
ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
return true; return true;
} }
void draw_top_bar() void draw_top_bar()
{ {
int top_position = 32; DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
DrawBar(0,0,Form.cwidth, top_position-2, system.color.work); DrawBar(0,list.y-2, Form.cwidth, 1, ShadowPixel(system.color.work, 1));
DrawBar(0,top_position-2, Form.cwidth, 1, ShadowPixel(system.color.work, 1)); DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
DrawBar(0,top_position-1, Form.cwidth, 1, system.color.work_graph); label.write_center(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
label.write_center(0,5, Form.cwidth, top_position, system.color.work, system.color.work_text, 16, #window_title);
list_top = top_position;
list_pos = list_top;
} }