2013-07-01 17:53:58 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2013-07-21 20:20:37 +00:00
|
|
|
* http://ugfx.org/license.html
|
2013-07-01 17:53:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-08-20 07:42:53 +00:00
|
|
|
* @file src/gwin/gwin_label.c
|
2014-05-20 16:05:38 +00:00
|
|
|
* @brief GWIN label widget header file
|
2013-07-01 17:53:58 +00:00
|
|
|
*/
|
|
|
|
|
2015-11-21 09:27:08 +00:00
|
|
|
#include "../../gfx.h"
|
2013-07-01 17:53:58 +00:00
|
|
|
|
|
|
|
#if GFX_USE_GWIN && GWIN_NEED_LABEL
|
|
|
|
|
2014-08-20 07:42:53 +00:00
|
|
|
#include "gwin_class.h"
|
2013-07-01 17:53:58 +00:00
|
|
|
|
2013-10-24 02:13:07 +00:00
|
|
|
// macros to assist in data type conversions
|
|
|
|
#define gh2obj ((GLabelObject *)gh)
|
2014-04-28 21:20:51 +00:00
|
|
|
#define gw2obj ((GLabelObject *)gw)
|
2013-07-02 17:26:48 +00:00
|
|
|
|
|
|
|
static const gwidgetVMT labelVMT = {
|
|
|
|
{
|
2015-11-06 23:51:23 +00:00
|
|
|
"Label", // The class name
|
|
|
|
sizeof(GLabelObject), // The object size
|
|
|
|
_gwidgetDestroy, // The destroy routine
|
|
|
|
_gwidgetRedraw, // The redraw routine
|
|
|
|
0, // The after-clear routine
|
2013-07-02 17:26:48 +00:00
|
|
|
},
|
2015-11-06 23:51:23 +00:00
|
|
|
gwinLabelDrawJustifiedLeft, // default drawing routine
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_MOUSE
|
|
|
|
{
|
|
|
|
0, // Process mose down events (NOT USED)
|
|
|
|
0, // Process mouse up events (NOT USED)
|
|
|
|
0, // Process mouse move events (NOT USED)
|
|
|
|
},
|
|
|
|
#endif
|
2015-08-16 14:18:54 +00:00
|
|
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
2015-08-12 15:32:38 +00:00
|
|
|
{
|
|
|
|
0 // Process keyboard key down events
|
|
|
|
},
|
|
|
|
#endif
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_TOGGLE
|
|
|
|
{
|
|
|
|
0, // No toggle role
|
|
|
|
0, // Assign Toggles (NOT USED)
|
|
|
|
0, // Get Toggles (NOT USED)
|
|
|
|
0, // Process toggle off event (NOT USED)
|
|
|
|
0, // Process toggle on event (NOT USED)
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if GINPUT_NEED_DIAL
|
|
|
|
{
|
|
|
|
0, // No dial roles
|
|
|
|
0, // Assign Dials (NOT USED)
|
|
|
|
0, // Get Dials (NOT USED)
|
|
|
|
0, // Procees dial move events (NOT USED)
|
|
|
|
},
|
|
|
|
#endif
|
2013-07-02 06:29:38 +00:00
|
|
|
};
|
|
|
|
|
2015-11-06 23:39:08 +00:00
|
|
|
GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit) {
|
2013-07-02 17:26:48 +00:00
|
|
|
|
2013-10-24 08:36:11 +00:00
|
|
|
if (!(widget = (GLabelObject *)_gwidgetCreate(g, &widget->w, pInit, &labelVMT)))
|
2013-07-02 06:29:38 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-04-28 21:20:51 +00:00
|
|
|
#if GWIN_LABEL_ATTRIBUTE
|
|
|
|
widget->tab = 0;
|
|
|
|
widget->attr = 0;
|
|
|
|
#endif
|
|
|
|
|
2013-07-03 14:20:32 +00:00
|
|
|
gwinSetVisible(&widget->w.g, pInit->g.show);
|
2013-10-24 02:13:07 +00:00
|
|
|
|
2013-07-02 06:29:38 +00:00
|
|
|
return (GHandle)widget;
|
2013-07-01 17:53:58 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
void gwinLabelSetBorder(GHandle gh, gBool border) {
|
2013-10-24 02:13:07 +00:00
|
|
|
// is it a valid handle?
|
|
|
|
if (gh->vmt != (gwinVMT *)&labelVMT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (border)
|
|
|
|
gh2obj->w.g.flags |= GLABEL_FLG_BORDER;
|
|
|
|
else
|
|
|
|
gh2obj->w.g.flags &=~ GLABEL_FLG_BORDER;
|
|
|
|
}
|
|
|
|
|
2014-04-28 21:20:51 +00:00
|
|
|
#if GWIN_LABEL_ATTRIBUTE
|
2018-07-08 00:54:19 +00:00
|
|
|
void gwinLabelSetAttribute(GHandle gh, gCoord tab, const char* attr) {
|
2014-04-28 21:20:51 +00:00
|
|
|
// is it a valid handle?
|
|
|
|
if (gh->vmt != (gwinVMT *)&labelVMT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gh2obj->tab = tab;
|
|
|
|
gh2obj->attr = attr;
|
|
|
|
|
|
|
|
gwinRedraw(gh);
|
|
|
|
}
|
|
|
|
#endif // GWIN_LABEL_ATTRIBUTE
|
|
|
|
|
2018-07-08 02:19:30 +00:00
|
|
|
static void gwinLabelDraw(GWidgetObject *gw, gJustify justify) {
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord w, h;
|
2018-07-08 01:19:43 +00:00
|
|
|
gColor c;
|
2014-05-01 06:45:26 +00:00
|
|
|
|
|
|
|
// is it a valid handle?
|
|
|
|
if (gw->g.vmt != (gwinVMT *)&labelVMT)
|
|
|
|
return;
|
|
|
|
|
2018-10-01 11:12:28 +00:00
|
|
|
w = gw->g.width;
|
|
|
|
h = gw->g.height;
|
2014-05-09 15:11:30 +00:00
|
|
|
c = (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text;
|
2014-05-01 06:45:26 +00:00
|
|
|
|
|
|
|
#if GWIN_LABEL_ATTRIBUTE
|
2014-05-09 11:36:14 +00:00
|
|
|
if (gw2obj->attr) {
|
2015-11-06 23:51:23 +00:00
|
|
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw2obj->tab, h, gw2obj->attr, gw->g.font, c, gw->pstyle->background, justify);
|
|
|
|
gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, gw->g.y, w-gw2obj->tab, h, gw->text, gw->g.font, c, gw->pstyle->background, justify);
|
2015-11-06 23:39:08 +00:00
|
|
|
} else
|
2015-11-06 23:51:23 +00:00
|
|
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justify);
|
2014-05-01 06:45:26 +00:00
|
|
|
#else
|
2015-11-06 23:51:23 +00:00
|
|
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justify);
|
2014-05-01 06:45:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// render the border (if any)
|
|
|
|
if (gw->g.flags & GLABEL_FLG_BORDER)
|
2014-05-09 15:11:30 +00:00
|
|
|
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, w, h, (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge);
|
2014-05-01 06:45:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-06 23:51:23 +00:00
|
|
|
void gwinLabelDrawJustifiedLeft(GWidgetObject *gw, void *param) {
|
|
|
|
(void)param;
|
|
|
|
|
2018-07-08 02:19:30 +00:00
|
|
|
gwinLabelDraw(gw, gJustifyLeft);
|
2015-11-06 23:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gwinLabelDrawJustifiedRight(GWidgetObject *gw, void *param) {
|
|
|
|
(void)param;
|
|
|
|
|
2018-07-08 02:19:30 +00:00
|
|
|
gwinLabelDraw(gw, gJustifyRight);
|
2015-11-06 23:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gwinLabelDrawJustifiedCenter(GWidgetObject *gw, void *param) {
|
|
|
|
(void)param;
|
|
|
|
|
2018-07-08 02:19:30 +00:00
|
|
|
gwinLabelDraw(gw, gJustifyCenter);
|
2015-11-06 23:51:23 +00:00
|
|
|
}
|
|
|
|
|
2015-06-08 04:14:40 +00:00
|
|
|
#undef gh2obj
|
|
|
|
#undef gw2obj
|
2013-07-01 17:53:58 +00:00
|
|
|
#endif // GFX_USE_GWIN && GFX_NEED_LABEL
|