static void menu_draw_entry(WMenu *menu, int i, const WRectangle *igeom, bool complete) { WRectangle geom; GrAttr sa, aa; aa=(REGION_IS_ACTIVE(menu) ? GR_ATTR(active) : GR_ATTR(inactive)); sa=(menu->selected_entry==i ? GR_ATTR(selected) : GR_ATTR(unselected)); if(menu->entry_brush==NULL) return; geom=*igeom; geom.h=menu->entry_h; geom.y+=(i-menu->first_entry)*(menu->entry_h+menu->entry_spacing); grbrush_begin(menu->entry_brush, &geom, GRBRUSH_AMEND|GRBRUSH_KEEP_ATTR); grbrush_init_attr(menu->entry_brush, &menu->entries[i].attr); grbrush_set_attr(menu->entry_brush, aa); grbrush_set_attr(menu->entry_brush, sa); grbrush_draw_textbox(menu->entry_brush, &geom, menu->entries[i].title, complete); grbrush_end(menu->entry_brush); }
void frame_update_attr(WFrame *frame, int i, WRegion *reg) { GrStyleSpec *spec; bool selected, tagged, dragged, activity; if(i>=frame->titles_n){ /* Might happen when deinitialising */ return; } ensure_create_attrs(); spec=&frame->titles[i].attr; selected=(reg==FRAME_CURRENT(frame)); tagged=(reg!=NULL && reg->flags®ION_TAGGED); dragged=(i==frame->tab_dragged_idx); activity=(reg!=NULL && region_is_activity_r(reg)); gr_stylespec_unalloc(spec); gr_stylespec_set(spec, selected ? GR_ATTR(selected) : GR_ATTR(unselected)); gr_stylespec_set(spec, tagged ? GR_ATTR(tagged) : GR_ATTR(not_tagged)); gr_stylespec_set(spec, dragged ? GR_ATTR(dragged) : GR_ATTR(not_dragged)); gr_stylespec_set(spec, activity ? GR_ATTR(activity) : GR_ATTR(no_activity)); }
static WMenuEntry *preprocess_menu(ExtlTab tab, int *n_entries) { WMenuEntry *entries; ExtlTab entry; int i, n; n=extl_table_get_n(tab); *n_entries=n; if(n<=0) return NULL; entries=ALLOC_N(WMenuEntry, n); if(entries==NULL) return NULL; init_attr(); /* Initialise entries and check submenus */ for(i=1; i<=n; i++){ WMenuEntry *ent=&entries[i-1]; ent->title=NULL; ent->flags=0; gr_stylespec_init(&ent->attr); if(extl_table_geti_t(tab, i, &entry)){ char *attr; ExtlTab sub; ExtlFn fn; if(extl_table_gets_s(entry, "attr", &attr)){ gr_stylespec_load_(&ent->attr, attr, TRUE); free(attr); } if(extl_table_gets_f(entry, "submenu_fn", &fn)){ ent->flags|=WMENUENTRY_SUBMENU; extl_unref_fn(fn); }else if(extl_table_gets_t(entry, "submenu", &sub)){ ent->flags|=WMENUENTRY_SUBMENU; extl_unref_table(sub); } if(ent->flags&WMENUENTRY_SUBMENU) gr_stylespec_set(&ent->attr, GR_ATTR(submenu)); extl_unref_table(entry); } } return entries; }
void menu_draw(WMenu *menu, bool complete) { GrAttr aa=(REGION_IS_ACTIVE(menu) ? GR_ATTR(active) : GR_ATTR(inactive)); WRectangle geom; if(menu->brush==NULL) return; get_outer_geom(menu, &geom); grbrush_begin(menu->brush, &geom, (complete ? 0 : GRBRUSH_NO_CLEAR_OK)); grbrush_set_attr(menu->brush, aa); grbrush_draw_border(menu->brush, &geom); menu_draw_entries(menu, FALSE); grbrush_end(menu->brush); }