aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gwin/gwin.mk3
-rw-r--r--src/gwin/gwin_mk.c1
-rw-r--r--src/gwin/gwin_options.h7
-rw-r--r--src/gwin/gwin_rules.h2
-rw-r--r--src/gwin/gwin_textedit.c113
-rw-r--r--src/gwin/gwin_textedit.h62
-rw-r--r--src/gwin/gwin_widget.h4
7 files changed, 190 insertions, 2 deletions
diff --git a/src/gwin/gwin.mk b/src/gwin/gwin.mk
index b4357328..d735c3e1 100644
--- a/src/gwin/gwin.mk
+++ b/src/gwin/gwin.mk
@@ -21,6 +21,7 @@ GFXSRC += $(GFXLIB)/src/gwin/gwin.c \
$(GFXLIB)/src/gwin/gwin_tabset.c \
$(GFXLIB)/src/gwin/gwin_gl3d.c \
$(GFXLIB)/src/gwin/gwin_keyboard.c \
- $(GFXLIB)/src/gwin/gwin_keyboard_layout.c
+ $(GFXLIB)/src/gwin/gwin_keyboard_layout.c \
+ $(GFXLIB)/src/gwin/gwin_textedit.c
GFXINC += $(GFXLIB)/3rdparty/tinygl-0.4-ugfx/include
diff --git a/src/gwin/gwin_mk.c b/src/gwin/gwin_mk.c
index 981eb6d2..2af501b5 100644
--- a/src/gwin/gwin_mk.c
+++ b/src/gwin/gwin_mk.c
@@ -24,3 +24,4 @@
#include "gwin_gl3d.c"
#include "gwin_keyboard.c"
#include "gwin_keyboard_layout.c"
+#include "gwin_textedit.c"
diff --git a/src/gwin/gwin_options.h b/src/gwin/gwin_options.h
index b69796c3..46bd92e7 100644
--- a/src/gwin/gwin_options.h
+++ b/src/gwin/gwin_options.h
@@ -142,6 +142,13 @@
#ifndef GWIN_NEED_KEYBOARD
#define GWIN_NEED_KEYBOARD FALSE
#endif
+ /**
+ * @brief Should the textedit widget be included.
+ * @details Defaults to FALSE
+ */
+ #ifndef GWIN_NEED_TEXTEDIT
+ #define GWIN_NEED_TEXTEDIT FALSE
+ #endif
/**
* @}
*
diff --git a/src/gwin/gwin_rules.h b/src/gwin/gwin_rules.h
index 7678ab7c..874c59b4 100644
--- a/src/gwin/gwin_rules.h
+++ b/src/gwin/gwin_rules.h
@@ -38,7 +38,7 @@
#endif
#endif
#if GWIN_NEED_BUTTON || GWIN_NEED_SLIDER || GWIN_NEED_CHECKBOX || GWIN_NEED_LABEL || GWIN_NEED_RADIO || GWIN_NEED_LIST || \
- GWIN_NEED_IMAGE || GWIN_NEED_CHECKBOX || GWIN_NEED_PROGRESSBAR || GWIN_NEED_KEYBOARD
+ GWIN_NEED_IMAGE || GWIN_NEED_CHECKBOX || GWIN_NEED_PROGRESSBAR || GWIN_NEED_KEYBOARD || GWIN_NEED_TEXTEDIT
#if !GWIN_NEED_WIDGET
#if GFX_DISPLAY_RULE_WARNINGS
#warning "GWIN: GWIN_NEED_WIDGET is required when a widget is used. It has been turned on for you."
diff --git a/src/gwin/gwin_textedit.c b/src/gwin/gwin_textedit.c
new file mode 100644
index 00000000..4aa41d61
--- /dev/null
+++ b/src/gwin/gwin_textedit.c
@@ -0,0 +1,113 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gwin/gwin_textedit.c
+ * @brief GWIN TextEdit widget header file
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GWIN && GWIN_NEED_TEXTEDIT
+
+#include "gwin_class.h"
+
+// Text padding (between edge and text) in pixels
+const int TEXT_PADDING = 3;
+
+// macros to assist in data type conversions
+#define gh2obj ((GTexteditObject *)gh)
+#define gw2obj ((GTexteditObject *)gw)
+
+#if GINPUT_NEED_KEYBOARD
+ static void _keyboardEvent(GWidgetObject* gw, GEventKeyboard* pke)
+ {
+ if (pke->bytecount = 1) {
+ //gw->text = pke->c[0];
+ gwinSetText((GHandle)gw, &(pke->c[0]), TRUE);
+ }
+
+ _gwinUpdate(&gw);
+ }
+#endif
+
+static void gwinTexteditDefaultDraw(GWidgetObject* gw, void* param);
+
+static const gwidgetVMT texteditVMT = {
+ {
+ "TextEdit", // The class name
+ sizeof(GTexteditObject), // The object size
+ _gwidgetDestroy, // The destroy routine
+ _gwidgetRedraw, // The redraw routine
+ 0, // The after-clear routine
+ },
+ gwinTexteditDefaultDraw, // default drawing routine
+ #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
+ #if GINPUT_NEED_KEYBOARD
+ {
+ _keyboardEvent, // Process keyboard key down events
+ },
+ #endif
+ #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
+};
+
+GHandle gwinGTexteditCreate(GDisplay* g, GTexteditObject* widget, GWidgetInit* pInit)
+{
+ uint16_t flags = 0;
+
+ if (!(widget = (GTexteditObject*)_gwidgetCreate(g, &widget->w, pInit, &texteditVMT))) {
+ return 0;
+ }
+
+ widget->w.g.flags |= flags;
+ gwinSetVisible(&widget->w.g, pInit->g.show);
+
+ return (GHandle)widget;
+}
+
+static void gwinTexteditDefaultDraw(GWidgetObject* gw, void* param)
+{
+ color_t textColor;
+ (void) param;
+
+ // Is it a valid handle?
+ if (gw->g.vmt != (gwinVMT*)&texteditVMT) {
+ return;
+ }
+
+ textColor = (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text;
+
+
+ gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, textColor, gw->pstyle->background, justifyLeft);
+}
+
+#undef gh2obj
+#undef gw2obj
+
+#endif // GFX_USE_GWIN && GWIN_NEED_TEXTEDIT
diff --git a/src/gwin/gwin_textedit.h b/src/gwin/gwin_textedit.h
new file mode 100644
index 00000000..84057df4
--- /dev/null
+++ b/src/gwin/gwin_textedit.h
@@ -0,0 +1,62 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gwin/gwin_textedit.h
+ * @brief GWIN textedit widget header file
+ *
+ * @defgroup TextEdit TextEdit
+ * @ingroup Widgets
+ *
+ * @details A GWIN TextEdit widget allows user input.
+ *
+ * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h
+ * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h
+ * @pre GDISP_NEED_TEXT must be set to TRUE in your gfxconf.h
+ * @pre GWIN_NEED_TEXTEDIT must be set to TRUE in your gfxconf.h
+ * @pre The fonts you want to use must be enabled in your gfxconf.h
+ *
+ * @{
+ */
+
+#ifndef _GWIN_TEXTEDIT_H
+#define _GWIN_TEXTEDIT_H
+
+// This file is included within "src/gwin/gwin_widget.h"
+
+// A TextEdit widget
+typedef struct GTexteditObject {
+ GWidgetObject w;
+} GTexteditObject;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Create a TextEdit widget.
+ * @details A TextEdit widget is a rectangular box which allows the user to input data through a keyboard.
+ * The keyboard can either be a physical one or a virtual on-screen keyboard as the keyboard driver
+ * is abstracted through the GINPUT module.
+ *
+ * @param[in] g The GDisplay on which the textedit should be displayed
+ * @param[in] widget The TextEdit structure to initialise. If this is NULL, the structure is dynamically allocated.
+ * @param[in] pInit The initialisation parameters to use.
+ *
+ * @return NULL if there is no resultat drawing area, otherwise the widget handle.
+ *
+ * @api
+ */
+GHandle gwinGTexteditCreate(GDisplay* g, GTexteditObject* widget, GWidgetInit* pInit);
+#define gwinTexteditCreate(w, pInit) gwinGTexteditCreate(GDISP, w, pInit)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _GWIN_TEXTEDIT_H
+/** @} */
diff --git a/src/gwin/gwin_widget.h b/src/gwin/gwin_widget.h
index 0ed80a84..1e97cdd2 100644
--- a/src/gwin/gwin_widget.h
+++ b/src/gwin/gwin_widget.h
@@ -381,5 +381,9 @@ bool_t gwinAttachListener(GListener *pl);
#include "gwin_keyboard.h"
#endif
+#if GWIN_NEED_TEXTEDIT || defined(__DOXYGEN__)
+ #include "gwin_textedit.h"
+#endif
+
#endif /* _GWIDGET_H */
/** @} */