label work in progress - not working anymore

This commit is contained in:
Joel Bodenmann 2013-07-02 19:26:48 +02:00
parent ad57ab7967
commit 3f80e1f89d
6 changed files with 93 additions and 68 deletions

View File

@ -48,7 +48,7 @@ typedef uint16_t GEventType;
typedef union GEvent_u {
GEventType type; // The type of this event
char pad[GEVENT_MAXIMUM_SIZE]; // This is here to allow static initialisation of GEventObject's in the application.
} GEvent;
} GEvent;
// A special callback function
typedef void (*GEventCallbackFn)(void *param, GEvent *pe);

View File

@ -129,8 +129,16 @@ extern "C" {
* @api
*/
void gwinSetDefaultFont(font_t font);
#endif
/**
* @brief Get the current default font
*
* @return The current default font
*
* @api
*/
font_t gwinGetDefaultFont(void);
#endif
/*-------------------------------------------------
* Base functions

View File

@ -31,9 +31,7 @@
// An label window
typedef struct GLabelWidget_t {
GWindowObject g;
const char* text;
GWidgetObject w;
} GLabelWidget;
#ifdef __cplusplus
@ -51,12 +49,7 @@ extern "C" {
*
* @api
*/
GHandle gwinLabelCreate(GLabelWidget *widget, GWindowInit *pInit);
void gwinLabelSetColor(GHandle gh, color_t color);
void gwinLabelSetBgColor(GHandle gh, color_t bgColor);
void gwinLabelSetFont(GHandle gh, font_t font);
void gwinLabelSetText(GHandle gh, const char* text);
void gwinLabelDraw(GHandle gh);
GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit);
#ifdef __cplusplus
}

View File

@ -69,6 +69,20 @@
#ifndef GWIN_NEED_CHECKBOX
#define GWIN_NEED_CHECKBOX FALSE
#endif
/**
* @brief Should image functions be included.
* @details Defaults to FALSE
*/
#ifndef GWIN_NEED_IMAGE
#define GWIN_NEED_IMAGE FALSE
#endif
/**
* @brief Should label functions be included.
* @details Defaults to FALSE
*/
#ifndef GWIN_NEED_LABEL
#define GWIN_NEED_LABEL FALSE
#endif
/**
* @}
*

View File

@ -143,6 +143,10 @@ void gwinSetDefaultBgColor(color_t bgclr) {
void gwinSetDefaultFont(font_t font) {
defaultFont = font;
}
font_t gwinGetDefaultFont(void) {
return defaultFont;
}
#endif
/*-----------------------------------------------

View File

@ -21,74 +21,80 @@
#include "gwin/class_gwin.h"
#define widget(gh) ((GLabelWidget*)gh)
#define widget(gh) ((GLabelWidget*)gh)
#define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG<<0)
#define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG<<1)
static void _destroy(GWindowObject *gh) {
(void)gh;
static void gwinLabelDefaultDraw(GHandle gh) {
// if( check if auto flag is set )
// if( call current size != font size )
// gwinResize();
return;
gdispFillString( widget(gh)->w.g.x,
widget(gh)->w.g.y,
widget(gh)->w.txt,
widget(gh)->w.g.font,
widget(gh)->w.g.color,
widget(gh)->w.g.bgcolor
);
gdispFillArea( widget(gh)->w.g.x, widget(gh)->w.g.y, widget(gh)->w.g.width, widget(gh)->w.g.height, Green);
printf("Text: %s\r\n", widget(gh)->w.txt);
}
static void _redraw(GWindowObject *gh) {
(void)gh;
return;
}
static void _afterClear(GWindowObject *gh) {
(void)gh;
return;
}
static const gwinVMT labelVMT = {
"Label", // The class name
sizeof(GLabelWidget), // The object size
_destroy, // The destroy routine
0, // The redraw routine
_afterClear // The after-clear routine
static const gwidgetVMT labelVMT = {
{
"Label", // The class name
sizeof(GLabelWidget), // The object size
_gwidgetDestroy, // The destroy routine
_gwidgetRedraw, // The redraw routine
0, // The after-clear routine
},
gwinLabelDefaultDraw, // default drawing routine
{
0, // Process mose down events (NOT USED)
0, // Process mouse up events (NOT USED)
0, // Process mouse move events (NOT USED)
},
{
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)
},
{
0, // No dial roles
0, // Assign Dials (NOT USED)
0, // Get Dials (NOT USED)
0, // Procees dial move events (NOT USED)
}
};
GHandle gwinLabelCreate(GLabelWidget *widget, GWindowInit *pInit) {
if (!(widget = (GLabelWidget *)_gwindowCreate(&widget->g, pInit, &labelVMT, 0)))
GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) {
uint16_t flags = 0;
// auto assign width
if (pInit->g.width <= 0) {
flags |= GLABEL_FLG_WAUTO;
pInit->g.width = gdispGetStringWidth(pInit->text, gwinGetDefaultFont());
}
// auto assign height
if (pInit->g.height <= 0) {
flags |= GLABEL_FLG_HAUTO;
pInit->g.height = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight);
}
if (!(widget = (GLabelWidget *)_gwidgetCreate(&widget->w, pInit, &labelVMT)))
return 0;
widget->g.x = pInit->x;
widget->g.y = pInit->y;
widget->g.width = pInit->width;
widget->g.height = pInit->height;
gwinSetVisible((GHandle)widget, pInit->show);
gwinLabelDefaultDraw((GHandle)widget);
widget->w.g.flags |= flags;
return (GHandle)widget;
}
void gwinLabelSetColor(GHandle gh, color_t color) {
widget(gh)->g.color = color;
}
void gwinLabelSetBgColor(GHandle gh, color_t bgColor) {
widget(gh)->g.bgcolor = bgColor;
}
void gwinLabelSetFont(GHandle gh, font_t font) {
widget(gh)->g.font = font;
}
void gwinLabelSetText(GHandle gh, const char* text) {
widget(gh)->text = text;
gwinLabelDraw(gh);
}
void gwinLabelDraw(GHandle gh) {
gdispFillString( widget(gh)->g.x,
widget(gh)->g.y,
widget(gh)->text,
widget(gh)->g.font,
widget(gh)->g.color,
widget(gh)->g.bgcolor
);
}
#endif // GFX_USE_GWIN && GFX_NEED_LABEL