2 * ion/mod_statusbar/draw.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
14 #include <ioncore/common.h>
15 #include <ioncore/mplex.h>
16 #include "statusbar.h"
20 static void calc_elems_x(WRectangle *g, WSBElem *elems, int nelems)
26 if(elems->type==WSBELEM_STRETCH)
27 x+=elems->text_w+elems->stretch;
37 static void calc_elems_x_ra(WRectangle *g, WSBElem *elems, int nelems)
44 if(elems->type==WSBELEM_STRETCH)
45 x-=elems->text_w+elems->stretch;
56 void statusbar_calculate_xs(WStatusBar *sb)
61 bool right_align=FALSE;
63 int nleft=0, nright=0;
65 if(sb->brush==NULL || sb->elems==NULL)
68 grbrush_get_border_widths(sb->brush, &bdw);
72 g.w=REGION_GEOM(sb).w;
73 g.h=REGION_GEOM(sb).h;
75 mgr=OBJ_CAST(REGION_PARENT(sb), WMPlex);
79 din.pos=MPLEX_STDISP_TL;
80 mplex_get_stdisp(mgr, &std, &din);
82 right_align=(din.pos==MPLEX_STDISP_TR || din.pos==MPLEX_STDISP_BR);
86 g.w-=bdw.left+bdw.right;
88 g.h-=bdw.top+bdw.bottom;
92 nright=sb->nelems-(sb->filleridx+1);
93 }else if(!right_align){
102 calc_elems_x(&g, sb->elems, nleft);
105 calc_elems_x_ra(&g, sb->elems+sb->nelems-nright, nright);
110 static void draw_elems(GrBrush *brush, WRectangle *g, int ty,
111 WSBElem *elems, int nelems, bool needfill,
121 grbrush_clear_area(brush, g);
124 if(elems->type==WSBELEM_TEXT || elems->type==WSBELEM_METER){
125 const char *s=(elems->text!=NULL
129 grbrush_set_attr(brush, elems->attr);
130 grbrush_set_attr(brush, elems->meter);
132 grbrush_draw_string(brush, elems->x, ty, s, strlen(s), needfill);
134 grbrush_unset_attr(brush, elems->meter);
135 grbrush_unset_attr(brush, elems->attr);
137 prevx=elems->x+elems->text_w;
146 grbrush_clear_area(brush, g);
151 void statusbar_draw(WStatusBar *sb, bool complete)
156 Window win=sb->wwin.win;
162 grbrush_get_border_widths(sb->brush, &bdw);
163 grbrush_get_font_extents(sb->brush, &fnte);
167 g.w=REGION_GEOM(sb).w;
168 g.h=REGION_GEOM(sb).h;
170 grbrush_begin(sb->brush, &g, (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
172 grbrush_draw_border(sb->brush, &g);
178 g.w-=bdw.left+bdw.right;
180 g.h-=bdw.top+bdw.bottom;
182 ty=(g.y+fnte.baseline+(g.h-fnte.max_height)/2);
184 draw_elems(sb->brush, &g, ty, sb->elems, sb->nelems, TRUE, complete);
186 grbrush_end(sb->brush);