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
;
59 int nleft
=0, nright
=0;
61 if(sb
->brush
==NULL
|| sb
->elems
==NULL
)
64 grbrush_get_border_widths(sb
->brush
, &bdw
);
68 g
.w
=REGION_GEOM(sb
).w
;
69 g
.h
=REGION_GEOM(sb
).h
;
71 mgr
=OBJ_CAST(REGION_PARENT(sb
), WMPlex
);
75 din
.pos
=MPLEX_STDISP_TL
;
76 mplex_get_stdisp(mgr
, &std
, &din
);
78 right_align
=(din
.pos
==MPLEX_STDISP_TR
|| din
.pos
==MPLEX_STDISP_BR
);
82 g
.w
-=bdw
.left
+bdw
.right
;
84 g
.h
-=bdw
.top
+bdw
.bottom
;
88 nright
=sb
->nelems
-(sb
->filleridx
+1);
89 }else if(!right_align
){
98 calc_elems_x(&g
, sb
->elems
, nleft
);
101 calc_elems_x_ra(&g
, sb
->elems
+sb
->nelems
-nright
, nright
);
106 static void draw_elems(GrBrush
*brush
, WRectangle
*g
, int ty
,
107 WSBElem
*elems
, int nelems
, bool needfill
)
116 grbrush_clear_area(brush
, g
);
119 if(elems
->type
==WSBELEM_TEXT
|| elems
->type
==WSBELEM_METER
){
120 const char *s
=(elems
->text
!=NULL
124 grbrush_set_attr(brush
, elems
->attr
);
125 grbrush_set_attr(brush
, elems
->meter
);
127 grbrush_draw_string(brush
, elems
->x
, ty
, s
, strlen(s
), needfill
);
129 grbrush_unset_attr(brush
, elems
->meter
);
130 grbrush_unset_attr(brush
, elems
->attr
);
132 prevx
=elems
->x
+elems
->text_w
;
141 grbrush_clear_area(brush
, g
);
146 void statusbar_draw(WStatusBar
*sb
, bool complete
)
156 grbrush_get_border_widths(sb
->brush
, &bdw
);
157 grbrush_get_font_extents(sb
->brush
, &fnte
);
161 g
.w
=REGION_GEOM(sb
).w
;
162 g
.h
=REGION_GEOM(sb
).h
;
164 grbrush_begin(sb
->brush
, &g
, (complete
? 0 : GRBRUSH_NO_CLEAR_OK
));
166 grbrush_draw_border(sb
->brush
, &g
);
172 g
.w
-=bdw
.left
+bdw
.right
;
174 g
.h
-=bdw
.top
+bdw
.bottom
;
176 ty
=(g
.y
+fnte
.baseline
+(g
.h
-fnte
.max_height
)/2);
178 draw_elems(sb
->brush
, &g
, ty
, sb
->elems
, sb
->nelems
, TRUE
);
180 grbrush_end(sb
->brush
);