version 2.8
gwin_container.c
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.org/license.html
6  */
7 
8 /**
9  * @file src/gwin/gwin_container.c
10  * @brief GWIN sub-system container code
11  */
12 
13 #include "../../gfx.h"
14 
15 #if GFX_USE_GWIN && GWIN_NEED_CONTAINERS
16 
17 #include "gwin_class.h"
18 
19 void _gcontainerInit(void)
20 {
21 }
22 
23 void _gcontainerDeinit(void)
24 {
25 }
26 
27 GHandle _gcontainerCreate(GDisplay *g, GContainerObject *pgc, const GWidgetInit *pInit, const gcontainerVMT *vmt) {
28  if (!(pgc = (GContainerObject *)_gwidgetCreate(g, (GWidgetObject *)pgc, pInit, &vmt->gw)))
29  return 0;
30 
31  pgc->g.flags |= GWIN_FLG_CONTAINER;
32 
33  return &pgc->g;
34 }
35 
36 void _gcontainerDestroy(GHandle gh) {
37  GHandle child;
38 
39  while((child = gwinGetFirstChild(gh)))
40  gwinDestroy(child);
41  _gwidgetDestroy(gh);
42 }
43 
45  GHandle child;
46 
47  for(child = gwinGetNextWindow(0); child; child = gwinGetNextWindow(child))
48  if (child->parent == gh)
49  return child;
50  return 0;
51 }
52 
54  GHandle child;
55 
56  for(child = gwinGetNextWindow(gh), gh = gh->parent; child; child = gwinGetNextWindow(child))
57  if (child->parent == gh)
58  return child;
59  return 0;
60 }
61 
63  if (!(gh->flags & GWIN_FLG_CONTAINER))
64  return 0;
65  return gh->width - ((const gcontainerVMT *)gh->vmt)->LeftBorder(gh) - ((const gcontainerVMT *)gh->vmt)->RightBorder(gh);
66 }
67 
69  if (!(gh->flags & GWIN_FLG_CONTAINER))
70  return 0;
71  return gh->height - ((const gcontainerVMT *)gh->vmt)->TopBorder(gh) - ((const gcontainerVMT *)gh->vmt)->BottomBorder(gh);
72 }
73 
74 #endif /* GFX_USE_GWIN && GWIN_NEED_CONTAINERS */
75 /** @} */
76 
77 /*-----------------------------------------------
78  * The simplest container type - a container
79  *-----------------------------------------------
80  *
81  * @defgroup Containers Containers
82  * @ingroup GWIN
83  *
84  * @{
85  */
86 
87 #if GFX_USE_GWIN && GWIN_NEED_CONTAINER
88 
89 #if GWIN_CONTAINER_BORDER != GWIN_FIRST_CONTROL_FLAG
90  #error "GWIN Container: - Flag definitions don't match"
91 #endif
92 
93 #define BORDER_WIDTH 2
94 
95 static coord_t ContainerBorderSize(GHandle gh) { return (gh->flags & GWIN_CONTAINER_BORDER) ? BORDER_WIDTH : 0; }
96 
97 // The container VMT table
98 static const gcontainerVMT containerVMT = {
99  {
100  {
101  "Container", // The classname
102  sizeof(GContainerObject), // The object size
103  _gcontainerDestroy, // The destroy routine
104  _gcontainerRedraw, // The redraw routine
105  0, // The after-clear routine
106  },
107  gwinContainerDraw_Std, // The default drawing routine
109  {
110  0, 0, 0, // No mouse
111  },
112  #endif
113  #if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
114  {
115  0 // Process keyboard events
116  },
117  #endif
118  #if GINPUT_NEED_TOGGLE
119  {
120  0, 0, 0, 0, 0, // No toggles
121  },
122  #endif
123  #if GINPUT_NEED_DIAL
124  {
125  0, 0, 0, 0, // No dials
126  },
127  #endif
128  },
129  ContainerBorderSize, // The size of the left border (mandatory)
130  ContainerBorderSize, // The size of the top border (mandatory)
131  ContainerBorderSize, // The size of the right border (mandatory)
132  ContainerBorderSize, // The size of the bottom border (mandatory)
133  0, // A child has been added (optional)
134  0, // A child has been deleted (optional)
135 };
136 
137 GHandle gwinGContainerCreate(GDisplay *g, GContainerObject *gc, const GWidgetInit *pInit, uint32_t flags) {
138  if (!(gc = (GContainerObject *)_gcontainerCreate(g, gc, pInit, &containerVMT)))
139  return 0;
140 
141  gc->g.flags |= (flags & GWIN_CONTAINER_BORDER);
142 
143  gwinSetVisible((GHandle)gc, pInit->g.show);
144  return (GHandle)gc;
145 }
146 
147 void gwinContainerDraw_Transparent(GWidgetObject *gw, void *param) {
148  (void)param;
149 
150  if (gw->g.vmt != (gwinVMT *)&containerVMT)
151  return;
152 
153  if ((gw->g.flags & GWIN_CONTAINER_BORDER))
154  gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge);
155 
156  // Don't touch the client area
157 }
158 
159 void gwinContainerDraw_Std(GWidgetObject *gw, void *param) {
160  (void)param;
161 
162  if (gw->g.vmt != (gwinVMT *)&containerVMT)
163  return;
164 
165  gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
167 }
168 
169 #if GDISP_NEED_IMAGE
170  void gwinContainerDraw_Image(GWidgetObject *gw, void *param) {
171  #define gi ((gdispImage *)param)
172  coord_t x, y, iw, ih, mx, my;
173 
174  if (gw->g.vmt != (gwinVMT *)&containerVMT)
175  return;
176 
177  // Draw the frame
179 
180  // Draw the client area by tiling the image
181  mx = gw->g.x+gw->g.width;
182  my = gw->g.y+gw->g.height;
183  y = gw->g.y;
184  if ((gw->g.flags & GWIN_CONTAINER_BORDER)) {
185  mx--;
186  my--;
187  y++;
188  }
189  for(ih=gi->height; y < my; y += ih) {
190  if (ih > my - y)
191  ih = my - y;
192  x = gw->g.x;
193  if ((gw->g.flags & GWIN_CONTAINER_BORDER))
194  x++;
195  for(iw=gi->width; x < mx; x += iw) {
196  if (iw > mx - x)
197  iw = mx - x;
198  gdispGImageDraw(gw->g.display, gi, x, y, iw, ih, 0, 0);
199  }
200  }
201 
202  #undef gi
203  }
204 #endif
205 
206 #endif
coord_t gwinGetInnerHeight(GHandle gh)
Get the inner height of a container window.
const struct gwinVMT * vmt
Definition: gwin.h:45
GHandle gwinGetNextWindow(GHandle gh)
Get the next window in the z-order.
uint32_t flags
Definition: gwin.h:53
int16_t coord_t
The type for a coordinate or length on the screen.
Definition: gdisp.h:39
void gwinContainerDraw_Image(GWidgetObject *gw, void *param)
Renders the container and uses the specified image for the client area.
The structure to initialise a widget.
Definition: gwin_widget.h:97
The Virtual Method Table for a container.
Definition: gwin_class.h:132
color_t background
Definition: gwin_widget.h:53
coord_t y
Definition: gwin.h:48
coord_t x
Definition: gwin.h:47
#define GWIN_CONTAINER_BORDER
Flags for gwinContainerCreate()
GWindowInit g
Definition: gwin_widget.h:98
#define GINPUT_NEED_MOUSE
Should mouse/touch functions be included.
GHandle gwinGContainerCreate(GDisplay *g, GContainerObject *gw, const GWidgetInit *pInit, uint32_t flags)
Create a simple container.
GWindowObject g
Definition: gwin_widget.h:119
void gwinContainerDraw_Transparent(GWidgetObject *gw, void *param)
Renders the container but leaves the client area transparent.
GColorSet disabled
Definition: gwin_widget.h:56
void gwinDestroy(GHandle gh)
Destroy a window (of any type). Releases any dynamically allocated memory.
void gdispGFillArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color)
Fill an area with a color.
GColorSet enabled
Definition: gwin_widget.h:55
void gwinSetVisible(GHandle gh, bool_t visible)
Sets whether a window is visible or not.
const GWidgetStyle * pstyle
Definition: gwin_widget.h:123
The GWIN Widget structure.
Definition: gwin_widget.h:118
bool_t show
Definition: gwin.h:80
GDisplay * display
Definition: gwin.h:46
void gwinContainerDraw_Std(GWidgetObject *gw, void *param)
The default rendering function for the container widget.
GHandle gwinGetFirstChild(GHandle gh)
Get the first child window.
coord_t height
Definition: gwin.h:50
GWidgetObject GContainerObject
The GWIN Container structure.
GHandle gwinGetSibling(GHandle gh)
Get the next child window in the z-order.
coord_t width
Definition: gwin.h:49
gdispImageError gdispGImageDraw(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy)
Draw the image.
coord_t gwinGetInnerWidth(GHandle gh)
Get the inner width of a container window.
void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color)
Draw a rectangular box.
The Virtual Method Table for a GWIN window.
Definition: gwin_class.h:55
A window object structure.
Definition: gwin.h:40
color_t edge
Definition: gwin_widget.h:39