now using absolute coordinates inside the window
This commit is contained in:
parent
a6b81192eb
commit
bd3109851b
3 changed files with 20 additions and 55 deletions
|
@ -42,7 +42,7 @@ typedef struct GWindowObject {
|
||||||
#endif
|
#endif
|
||||||
const struct gwinVMT *vmt; // @< The VMT for this GWIN
|
const struct gwinVMT *vmt; // @< The VMT for this GWIN
|
||||||
GDisplay * display; // @< The display this window is on.
|
GDisplay * display; // @< The display this window is on.
|
||||||
coord_t x, y; // @< Screen relative position
|
coord_t x, y; // @< Position relative to parent
|
||||||
coord_t width, height; // @< Dimensions of this window
|
coord_t width, height; // @< Dimensions of this window
|
||||||
color_t color, bgcolor; // @< The current drawing colors
|
color_t color, bgcolor; // @< The current drawing colors
|
||||||
uint16_t flags; // @< Window flags (the meaning is private to the GWIN class)
|
uint16_t flags; // @< Window flags (the meaning is private to the GWIN class)
|
||||||
|
@ -336,17 +336,6 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
bool_t gwinGetEnabled(GHandle gh);
|
bool_t gwinGetEnabled(GHandle gh);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get absolute coordinates of a window
|
|
||||||
*
|
|
||||||
* @param[in] gh The window
|
|
||||||
* @param[out] x The absolut x coordinate
|
|
||||||
* @param[out] y The absolut y coordinate
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void gwinGetAbsoluteCoordinates(GHandle gh, coord_t *x, coord_t *y);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Move a window
|
* @brief Move a window
|
||||||
*
|
*
|
||||||
|
|
|
@ -153,52 +153,44 @@ static const GColorSet *getDrawColors(GWidgetObject *gw) {
|
||||||
|
|
||||||
void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param) {
|
void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param) {
|
||||||
#define gcw ((GCheckboxObject *)gw)
|
#define gcw ((GCheckboxObject *)gw)
|
||||||
coord_t ld, df, abs_x, abs_y;
|
coord_t ld, df;
|
||||||
const GColorSet * pcol;
|
const GColorSet * pcol;
|
||||||
(void) param;
|
(void) param;
|
||||||
|
|
||||||
if (gw->g.vmt != (gwinVMT *)&checkboxVMT)
|
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
|
||||||
return;
|
|
||||||
|
|
||||||
gwinGetAbsoluteCoordinates((GHandle)gw, &abs_x, &abs_y);
|
|
||||||
|
|
||||||
pcol = getDrawColors(gw);
|
pcol = getDrawColors(gw);
|
||||||
|
|
||||||
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
|
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
|
||||||
gdispGFillArea(gw->g.display, abs_x+1, abs_y+1, ld, ld-2, gw->pstyle->background);
|
gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+1, ld, ld-2, gw->pstyle->background);
|
||||||
gdispGDrawBox(gw->g.display, abs_x, abs_y, ld, ld, pcol->edge);
|
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, ld, ld, pcol->edge);
|
||||||
|
|
||||||
df = ld < 4 ? 1 : 2;
|
df = ld < 4 ? 1 : 2;
|
||||||
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
|
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
|
||||||
gdispGFillArea(gw->g.display, abs_x+df, abs_y+df, ld-2*df, ld-2*df, pcol->fill);
|
gdispGFillArea(gw->g.display, gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill);
|
||||||
|
|
||||||
gdispGFillStringBox(gw->g.display, abs_x+ld+1, abs_y, gw->g.width-ld-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyLeft);
|
gdispGFillStringBox(gw->g.display, gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyLeft);
|
||||||
#undef gcw
|
#undef gcw
|
||||||
}
|
}
|
||||||
|
|
||||||
void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param) {
|
void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param) {
|
||||||
#define gcw ((GCheckboxObject *)gw)
|
#define gcw ((GCheckboxObject *)gw)
|
||||||
coord_t ep, ld, df, abs_x, abs_y;
|
coord_t ep, ld, df;
|
||||||
const GColorSet * pcol;
|
const GColorSet * pcol;
|
||||||
(void) param;
|
(void) param;
|
||||||
|
|
||||||
if (gw->g.vmt != (gwinVMT *)&checkboxVMT)
|
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
|
||||||
return;
|
|
||||||
|
|
||||||
gwinGetAbsoluteCoordinates((GHandle)gw, &abs_x, &abs_y);
|
|
||||||
|
|
||||||
pcol = getDrawColors(gw);
|
pcol = getDrawColors(gw);
|
||||||
|
|
||||||
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
|
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
|
||||||
ep = gw->g.width-ld-1;
|
ep = gw->g.width-ld-1;
|
||||||
gdispGFillArea(gw->g.display, abs_x+ep-1, abs_y+1, ld, ld-2, gw->pstyle->background);
|
gdispGFillArea(gw->g.display, gw->g.x+ep-1, gw->g.y+1, ld, ld-2, gw->pstyle->background);
|
||||||
gdispGDrawBox(gw->g.display, abs_x+ep, abs_y, ld, ld, pcol->edge);
|
gdispGDrawBox(gw->g.display, gw->g.x+ep, gw->g.y, ld, ld, pcol->edge);
|
||||||
|
|
||||||
df = ld < 4 ? 1 : 2;
|
df = ld < 4 ? 1 : 2;
|
||||||
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
|
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
|
||||||
gdispGFillArea(gw->g.display, abs_x+ep+df, abs_y+df, ld-2*df, ld-2*df, pcol->fill);
|
gdispGFillArea(gw->g.display, gw->g.x+ep+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill);
|
||||||
|
|
||||||
gdispGFillStringBox(gw->g.display, abs_x, abs_y, ep-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyRight);
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, ep-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyRight);
|
||||||
#undef gcw
|
#undef gcw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,22 +274,6 @@ bool_t gwinGetEnabled(GHandle gh) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void gwinGetAbsoluteCoordinates(GHandle gh, coord_t *x, coord_t *y) {
|
|
||||||
#if GWIN_NEED_HIERARCHY
|
|
||||||
GHandle tmp;
|
|
||||||
|
|
||||||
// sum up all relative coordinates up to the root parent
|
|
||||||
for (*x = 0, *y = 0, tmp = gh; tmp; tmp = tmp->parent) {
|
|
||||||
*x += tmp->x;
|
|
||||||
*y += tmp->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
*x = gh->x;
|
|
||||||
*y = gh->y;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void gwinMove(GHandle gh, coord_t x, coord_t y) {
|
void gwinMove(GHandle gh, coord_t x, coord_t y) {
|
||||||
_gwm_redim(gh, x, y, gh->width, gh->height);
|
_gwm_redim(gh, x, y, gh->width, gh->height);
|
||||||
}
|
}
|
||||||
|
@ -335,14 +319,14 @@ void gwinRedraw(GHandle gh) {
|
||||||
parent->child = child;
|
parent->child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GDISP_NEED_CLIP
|
// clear the area of the current child position as it will be moved
|
||||||
gdispGSetClip(child->display, child->x, child->y, child->width, child->height);
|
gwinClear(child);
|
||||||
#endif
|
|
||||||
gdispGFillArea(child->display, child->x, child->y, child->width, child->height, child->bgcolor);
|
|
||||||
#if GDISP_NEED_CLIP
|
|
||||||
gdispGUnsetClip(child->display);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
// window coordinates until now are relative, make them absolute now.
|
||||||
|
child->x += parent->x;
|
||||||
|
child->y += parent->y;
|
||||||
|
|
||||||
|
// redraw the window
|
||||||
gwinClear(parent);
|
gwinClear(parent);
|
||||||
gwinRedraw(parent);
|
gwinRedraw(parent);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue