Menu: Apply PeVe/mseed path: Menu optimisation/improvment and some fixation

This commit is contained in:
Martin Duquesnoy 2010-08-13 03:11:44 +02:00
parent 5017c4ced5
commit 179c94f26f
4 changed files with 59 additions and 13 deletions

View File

@ -123,6 +123,26 @@ barwin_draw_text(BarWindow *bw, int x, int y, char *text)
return; return;
} }
/** Draw text in a Barwindow
*/
void
barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_image_ofset, int y_image_ofset)
{
if(!text)
return;
/* Background color of the text if there is stipple */
if(bw->stipple)
draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg);
/* Draw text */
draw_image_ofset_text(bw->dr, x, y, bw->fg, 0, text, x_image_ofset, y_image_ofset);
barwin_refresh(bw);
return;
}
/** Delete a BarWindow /** Delete a BarWindow
* \param bw BarWindow pointer * \param bw BarWindow pointer
*/ */

View File

@ -32,6 +32,12 @@
#include "wmfs.h" #include "wmfs.h"
void
draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
{
draw_image_ofset_text(d, x, y, fg, pad, str, 0, 0);
}
/** Draw a string in a Drawable /** Draw a string in a Drawable
* \param d Drawable * \param d Drawable
* \param x X position * \param x X position
@ -41,7 +47,7 @@
* \param str String that will be draw * \param str String that will be draw
*/ */
void void
draw_text(Drawable d, int x, int y, char* fg, int pad, char *str) draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, int x_image_ofset, int y_image_ofset)
{ {
XftColor xftcolor; XftColor xftcolor;
XftDraw *xftd; XftDraw *xftd;
@ -65,7 +71,7 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
sw = systray_get_width(); sw = systray_get_width();
for(i = 0; i < ni; ++i) for(i = 0; i < ni; ++i)
draw_image(d, im[i].x - sw, im[i].y, im[i].w, im[i].h, im[i].name); draw_image(d, x_image_ofset + im[i].x - sw, y_image_ofset + im[i].y, im[i].w, im[i].h, im[i].name);
} }
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */

View File

@ -68,7 +68,11 @@ menu_draw(Menu menu, int x, int y)
BarWindow *item[menu.nitem]; BarWindow *item[menu.nitem];
BarWindow *frame; BarWindow *frame;
width = menu_get_longer_string(menu.item, menu.nitem) + PAD * 3; int chcklen = 0;
if(menu_get_checkstring_needed(menu.item, menu.nitem))
chcklen = textw(conf.selected_layout_symbol) + PAD / 3;
width = menu_get_longer_string(menu.item, menu.nitem) + chcklen + textw(">") + PAD * 3;
height = menu.nitem * (INFOBARH - SHADH); height = menu.nitem * (INFOBARH - SHADH);
/* Frame barwin */ /* Frame barwin */
@ -99,7 +103,7 @@ menu_draw(Menu menu, int x, int y)
barwin_map(item[i]); barwin_map(item[i]);
barwin_refresh_color(item[i]); barwin_refresh_color(item[i]);
menu_draw_item_name(&menu, i, item); menu_draw_item_name(&menu, i, item, chcklen);
barwin_refresh(item[i]); barwin_refresh(item[i]);
} }
@ -209,6 +213,9 @@ Bool
menu_activate_item(Menu *menu, int i) menu_activate_item(Menu *menu, int i)
{ {
int j, x, y; int j, x, y;
int chcklen = 0;
if(menu_get_checkstring_needed(menu->item, menu->nitem))
chcklen = textw(conf.selected_layout_symbol) + PAD / 3;
if(menu->item[i].submenu) if(menu->item[i].submenu)
{ {
@ -216,7 +223,7 @@ menu_activate_item(Menu *menu, int i)
if(!strcmp(menu->item[i].submenu, conf.menu[j].name)) if(!strcmp(menu->item[i].submenu, conf.menu[j].name))
{ {
y = menu->y + ((i - 1) * INFOBARH + PAD) - SHADH * 2; y = menu->y + ((i - 1) * INFOBARH + PAD) - SHADH * 2;
x = menu->x + menu_get_longer_string(menu->item, menu->nitem) + PAD * 3; x = menu->x + menu_get_longer_string(menu->item, menu->nitem) + chcklen + textw(">") + PAD * 3;
menu_draw(conf.menu[j], x, y); menu_draw(conf.menu[j], x, y);
@ -238,6 +245,10 @@ menu_focus_item(Menu *menu, int item, BarWindow *winitem[])
{ {
int i; int i;
int chcklen = 0;
if(menu_get_checkstring_needed(menu->item, menu->nitem))
chcklen = textw(conf.selected_layout_symbol) + PAD / 3;
menu->focus_item = item; menu->focus_item = item;
if(menu->focus_item > menu->nitem - 1) if(menu->focus_item > menu->nitem - 1)
@ -251,7 +262,7 @@ menu_focus_item(Menu *menu, int item, BarWindow *winitem[])
winitem[i]->bg = ((i == menu->focus_item) ? menu->colors.focus.bg : menu->colors.normal.bg); winitem[i]->bg = ((i == menu->focus_item) ? menu->colors.focus.bg : menu->colors.normal.bg);
barwin_refresh_color(winitem[i]); barwin_refresh_color(winitem[i]);
menu_draw_item_name(menu, i, winitem); menu_draw_item_name(menu, i, winitem, chcklen);
barwin_refresh(winitem[i]); barwin_refresh(winitem[i]);
} }
@ -259,29 +270,29 @@ menu_focus_item(Menu *menu, int item, BarWindow *winitem[])
} }
void void
menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[]) menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen)
{ {
int x; int x;
int width = menu_get_longer_string(menu->item, menu->nitem); int width = menu_get_longer_string(menu->item, menu->nitem) + chcklen + PAD / 3;
switch(menu->align) switch(menu->align)
{ {
case MA_Left: case MA_Left:
x = PAD * 3 / 2; x = chcklen + PAD / 2;
break; break;
case MA_Right: case MA_Right:
x = width - textw(menu->item[item].name) + PAD * 3 / 2; x = width - textw(menu->item[item].name) + PAD * 3 / 2;
break; break;
default: default:
case MA_Center: case MA_Center:
x = width / 2 - textw(menu->item[item].name) / 2 + PAD * 3 / 2; x = (width - (chcklen + PAD / 3)) / 2 - textw(menu->item[item].name) / 2 + chcklen + PAD / 3;
break; break;
} }
barwin_draw_text(winitem[item], x, FHINFOBAR, menu->item[item].name); barwin_draw_image_ofset_text(winitem[item], x, FHINFOBAR, menu->item[item].name, chcklen + PAD / 2, 0);
if(menu->item[item].check) if(menu->item[item].check)
if(menu->item[item].check(menu->item[item].cmd)) if(menu->item[item].check(menu->item[item].cmd))
barwin_draw_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol); barwin_draw_image_ofset_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol, PAD / 3, 0);
if(menu->item[item].submenu) if(menu->item[item].submenu)
barwin_draw_text(winitem[item], width + PAD * 2, FHINFOBAR, ">"); barwin_draw_text(winitem[item], width + PAD * 2, FHINFOBAR, ">");
@ -340,3 +351,9 @@ menu_clear(Menu *menu)
return; return;
} }
Bool
menu_get_checkstring_needed(MenuItem *mi, int nitem)
{
return True;
}

View File

@ -122,6 +122,7 @@ BarWindow *barwin_create(Window parent,
Bool stipple, Bool stipple,
Bool border); Bool border);
void barwin_draw_text(BarWindow *bw, int x, int y, char *text); void barwin_draw_text(BarWindow *bw, int x, int y, char *text);
void barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_image_ofset, int y_image_ofset);
void barwin_delete(BarWindow *bw); void barwin_delete(BarWindow *bw);
void barwin_delete_subwin(BarWindow *bw); void barwin_delete_subwin(BarWindow *bw);
void barwin_map(BarWindow *bw); void barwin_map(BarWindow *bw);
@ -135,6 +136,7 @@ void barwin_refresh(BarWindow *bw);
/* draw.c */ /* draw.c */
void draw_text(Drawable d, int x, int y, char* fg, int pad, char *str); void draw_text(Drawable d, int x, int y, char* fg, int pad, char *str);
void draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, int x_image_ofset, int y_image_ofset);
void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color); void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color);
void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data); void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data);
@ -258,10 +260,11 @@ void menu_draw(Menu menu, int x, int y);
Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]); Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]);
Bool menu_activate_item(Menu *menu, int i); Bool menu_activate_item(Menu *menu, int i);
void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]); void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]);
void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[]); void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen);
int menu_get_longer_string(MenuItem *mi, int nitem); int menu_get_longer_string(MenuItem *mi, int nitem);
void uicb_menu(uicb_t cmd); void uicb_menu(uicb_t cmd);
void menu_clear(Menu *menu); void menu_clear(Menu *menu);
Bool menu_get_checkstring_needed(MenuItem *mi, int nitem);
/* launcher.c */ /* launcher.c */
void launcher_execute(Launcher *launcher); void launcher_execute(Launcher *launcher);