2 * ion/mod_statusbar/draw.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
11 #include <ioncore/common.h>
12 #include <ioncore/mplex.h>
13 #include "statusbar.h"
17 static void calc_elems_x(WRectangle
*g
, WSBElem
*elems
, int nelems
)
23 if(elems
->type
==WSBELEM_STRETCH
)
24 x
+=elems
->text_w
+elems
->stretch
;
34 static void calc_elems_x_ra(WRectangle
*g
, WSBElem
*elems
, int nelems
)
41 if(elems
->type
==WSBELEM_STRETCH
)
42 x
-=elems
->text_w
+elems
->stretch
;
53 void statusbar_calculate_xs(WStatusBar
*sb
)
58 bool right_align
=FALSE
;
60 int nleft
=0, nright
=0;
62 if(sb
->brush
==NULL
|| sb
->elems
==NULL
)
65 grbrush_get_border_widths(sb
->brush
, &bdw
);
69 g
.w
=REGION_GEOM(sb
).w
;
70 g
.h
=REGION_GEOM(sb
).h
;
72 mgr
=OBJ_CAST(REGION_PARENT(sb
), WMPlex
);
76 din
.pos
=MPLEX_STDISP_TL
;
77 mplex_get_stdisp(mgr
, &std
, &din
);
79 right_align
=(din
.pos
==MPLEX_STDISP_TR
|| din
.pos
==MPLEX_STDISP_BR
);
83 g
.w
-=bdw
.left
+bdw
.right
;
85 g
.h
-=bdw
.top
+bdw
.bottom
;
89 nright
=sb
->nelems
-(sb
->filleridx
+1);
90 }else if(!right_align
){
99 calc_elems_x(&g
, sb
->elems
, nleft
);
102 calc_elems_x_ra(&g
, sb
->elems
+sb
->nelems
-nright
, nright
);
107 static void draw_elems(GrBrush
*brush
, WRectangle
*g
, int ty
,
108 WSBElem
*elems
, int nelems
, bool needfill
,
118 grbrush_clear_area(brush
, g
);
121 if(elems
->type
==WSBELEM_TEXT
|| elems
->type
==WSBELEM_METER
){
122 const char *s
=(elems
->text
!=NULL
126 grbrush_set_attr(brush
, elems
->attr
);
127 grbrush_set_attr(brush
, elems
->meter
);
129 grbrush_draw_string(brush
, elems
->x
, ty
, s
, strlen(s
), needfill
);
131 grbrush_unset_attr(brush
, elems
->meter
);
132 grbrush_unset_attr(brush
, elems
->attr
);
134 prevx
=elems
->x
+elems
->text_w
;
143 grbrush_clear_area(brush
, g
);
148 void statusbar_draw(WStatusBar
*sb
, bool complete
)
153 Window win
=sb
->wwin
.win
;
159 grbrush_get_border_widths(sb
->brush
, &bdw
);
160 grbrush_get_font_extents(sb
->brush
, &fnte
);
164 g
.w
=REGION_GEOM(sb
).w
;
165 g
.h
=REGION_GEOM(sb
).h
;
167 grbrush_begin(sb
->brush
, &g
, (complete
? 0 : GRBRUSH_NO_CLEAR_OK
));
169 grbrush_draw_border(sb
->brush
, &g
);
175 g
.w
-=bdw
.left
+bdw
.right
;
177 g
.h
-=bdw
.top
+bdw
.bottom
;
179 ty
=(g
.y
+fnte
.baseline
+(g
.h
-fnte
.max_height
)/2);
181 draw_elems(sb
->brush
, &g
, ty
, sb
->elems
, sb
->nelems
, TRUE
, complete
);
183 grbrush_end(sb
->brush
);