µGFX  2.9
version 2.9
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.io/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  * The simplest container type - a container
78  *-----------------------------------------------
79  *
80  * @defgroup Containers Containers
81  * @ingroup GWIN
82  *
83  * @{
84  */
85 
86 #if GFX_USE_GWIN && GWIN_NEED_CONTAINER
87 
88 #if GWIN_CONTAINER_BORDER != GWIN_FIRST_CONTROL_FLAG
89  #error "GWIN Container: - Flag definitions don't match"
90 #endif
91 
92 #define BORDER_WIDTH 2
93 
94 static gCoord ContainerBorderSize(GHandle gh) { return (gh->flags & GWIN_CONTAINER_BORDER) ? BORDER_WIDTH : 0; }
95 
96 // The container VMT table
97 static const gcontainerVMT containerVMT = {
98  {
99  {
100  "Container", // The classname
101  sizeof(GContainerObject), // The object size
102  _gcontainerDestroy, // The destroy routine
103  _gcontainerRedraw, // The redraw routine
104  0, // The after-clear routine
105  },
106  gwinContainerDraw_Std, // The default drawing routine
107  #if GINPUT_NEED_MOUSE
108  {
109  0, 0, 0, // No mouse
110  },
111  #endif
112  #if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
113  {
114  0 // Process keyboard events
115  },
116  #endif
117  #if GINPUT_NEED_TOGGLE
118  {
119  0, 0, 0, 0, 0, // No toggles
120  },
121  #endif
122  #if GINPUT_NEED_DIAL
123  {
124  0, 0, 0, 0, // No dials
125  },
126  #endif
127  },
128  ContainerBorderSize, // The size of the left border (mandatory)
129  ContainerBorderSize, // The size of the top border (mandatory)
130  ContainerBorderSize, // The size of the right border (mandatory)
131  ContainerBorderSize, // The size of the bottom border (mandatory)
132  0, // A child has been added (optional)
133  0, // A child has been deleted (optional)
134 };
135 
136 GHandle gwinGContainerCreate(GDisplay *g, GContainerObject *gc, const GWidgetInit *pInit, gU32 flags) {
137  if (!(gc = (GContainerObject *)_gcontainerCreate(g, gc, pInit, &containerVMT)))
138  return 0;
139 
140  gc->g.flags |= (flags & GWIN_CONTAINER_BORDER);
141 
142  gwinSetVisible((GHandle)gc, pInit->g.show);
143  return (GHandle)gc;
144 }
145 
146 void gwinContainerDraw_Transparent(GWidgetObject *gw, void *param) {
147  (void)param;
148 
149  if (gw->g.vmt != (gwinVMT *)&containerVMT)
150  return;
151 
152  if ((gw->g.flags & GWIN_CONTAINER_BORDER))
153  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);
154 
155  // Don't touch the client area
156 }
157 
158 void gwinContainerDraw_Std(GWidgetObject *gw, void *param) {
159  (void)param;
160 
161  if (gw->g.vmt != (gwinVMT *)&containerVMT)
162  return;
163 
164  gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
166 }
167 
168 #if GDISP_NEED_IMAGE
169  void gwinContainerDraw_Image(GWidgetObject *gw, void *param) {
170  #define gi ((gImage *)param)
171  gCoord x, y, iw, ih, mx, my;
172 
173  if (gw->g.vmt != (gwinVMT *)&containerVMT)
174  return;
175 
176  // Draw the frame
178 
179  // Draw the client area by tiling the image
180  mx = gw->g.x+gw->g.width;
181  my = gw->g.y+gw->g.height;
182  y = gw->g.y;
183  if ((gw->g.flags & GWIN_CONTAINER_BORDER)) {
184  mx--;
185  my--;
186  y++;
187  }
188  for(ih=gi->height; y < my; y += ih) {
189  if (ih > my - y)
190  ih = my - y;
191  x = gw->g.x;
192  if ((gw->g.flags & GWIN_CONTAINER_BORDER))
193  x++;
194  for(iw=gi->width; x < mx; x += iw) {
195  if (iw > mx - x)
196  iw = mx - x;
197  gdispGImageDraw(gw->g.display, gi, x, y, iw, ih, 0, 0);
198  }
199  }
200 
201  #undef gi
202  }
203 #endif /* GDISP_NEED_IMAGE */
204 
205 /**
206  * @}
207  */
208 
209 #endif /* GFX_USE_GWIN && GWIN_NEED_CONTAINERS */
GHandle gwinGContainerCreate(GDisplay *g, GContainerObject *gw, const GWidgetInit *pInit, gU32 flags)
Create a simple container.
#define GWIN_CONTAINER_BORDER
Flags for gwinContainerCreate()
gCoord gwinGetInnerHeight(GHandle gh)
Get the inner height of a container window.
GWidgetObject GContainerObject
The GWIN Container structure.
GHandle gwinGetFirstChild(GHandle gh)
Get the first child window.
GHandle gwinGetSibling(GHandle gh)
Get the next child window in the z-order.
gCoord gwinGetInnerWidth(GHandle gh)
Get the inner width of a container window.
void gdispGFillArea(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, gColor color)
Fill an area with a color.
gI16 gCoord
The type for a coordinate or length on the screen.
Definition: gdisp.h:39
void gdispGDrawBox(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, gColor color)
Draw a rectangular box.
gdispImageError gdispGImageDraw(GDisplay *g, gImage *img, gCoord x, gCoord y, gCoord cx, gCoord cy, gCoord sx, gCoord sy)
Draw the image.
void gwinContainerDraw_Transparent(GWidgetObject *gw, void *param)
Renders the container but leaves the client area transparent.
void gwinContainerDraw_Image(GWidgetObject *gw, void *param)
Renders the container and uses the specified image for the client area.
void gwinContainerDraw_Std(GWidgetObject *gw, void *param)
The default rendering function for the container widget.
void gwinDestroy(GHandle gh)
Destroy a window (of any type). Releases any dynamically allocated memory.
void gwinSetVisible(GHandle gh, gBool visible)
Sets whether a window is visible or not.
GHandle gwinGetNextWindow(GHandle gh)
Get the next window in the z-order.
gColor edge
Definition: gwin_widget.h:39
The structure to initialise a widget.
Definition: gwin_widget.h:97
GWindowInit g
Definition: gwin_widget.h:98
The GWIN Widget structure.
Definition: gwin_widget.h:118
GWindowObject g
Definition: gwin_widget.h:119
const GWidgetStyle * pstyle
Definition: gwin_widget.h:123
gColor background
Definition: gwin_widget.h:53
GColorSet disabled
Definition: gwin_widget.h:56
GColorSet enabled
Definition: gwin_widget.h:55
gBool show
Definition: gwin.h:80
A window object structure.
Definition: gwin.h:40
GDisplay * display
Definition: gwin.h:46
gCoord x
Definition: gwin.h:47
gCoord width
Definition: gwin.h:49
const struct gwinVMT * vmt
Definition: gwin.h:45
gU32 flags
Definition: gwin.h:53
gCoord y
Definition: gwin.h:48
gCoord height
Definition: gwin.h:50
The Virtual Method Table for a container.
Definition: gwin_class.h:132
The Virtual Method Table for a GWIN window.
Definition: gwin_class.h:55