Release s3d 0.2.2
[s3d.git] / libs3dw / s3dw.h
blobea00e36674d711abefbfa4c3d7ccb56070df00f2
1 /*
2 * s3dw.h
4 * Copyright (C) 2006-2011 Simon Wunderlich <dotslash@packetmixer.de>
6 * This file is part of the s3d Widgets, a Widget Library for s3d.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d Widgets is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * s3d Widgets is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the s3d Widgets; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #ifndef LIBS3DW_H
25 #define LIBS3DW_H
26 #ifndef LIBS3D_H
27 #include <s3d.h>
28 #endif
29 #include <stdint.h> /* [u]intXX_t type definitions*/
31 #ifdef HAVE_GCCVISIBILITY
32 #define S3DWEXPORT_VISIBILITY __attribute__ ((visibility("default")))
33 #else
34 #define S3DWEXPORT_VISIBILITY
35 #endif
37 #ifdef HAVE_GCCEXTERNALLY
38 #define S3DWEXPORT_EXTERNAL __attribute__((externally_visible))
39 #else
40 #define S3DWEXPORT_EXTERNAL
41 #endif
43 #define S3DWEXPORT S3DWEXPORT_VISIBILITY S3DWEXPORT_EXTERNAL
45 #ifdef __GNUC_MINOR__
46 #define S3DW_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
47 #else
48 #define S3DW_WARN_UNUSED_RESULT
49 #endif
51 /* we want this widget visible, as long as the widgets below are also visible.
52 * on for all widgets, except surfaces which have to be switched visible
53 * with s3dw_show() */
54 #define S3DW_VISIBLE 1
55 /* widget should accept input. that's on by default. */
56 #define S3DW_ACTIVE 2
57 /* tells us if the widget is currently displayed */
58 #define S3DW_ONSCREEN 256
59 /* if the surface (or widget) is already properly arranged */
60 #define S3DW_ARRANGED 512
61 /* follow the camera */
62 #define S3DW_FOLLOW_CAM 1024
63 /* turn to the camera */
64 #define S3DW_TURN_CAM 2048
65 /* just a typecaster to beatify code. use it if you like */
66 #define S3DWIDGET(x) ((s3dw_widget *)x)
68 enum {
69 S3DW_TROOT,
70 S3DW_TCAM,
71 S3DW_TSURFACE,
72 S3DW_TBUTTON,
73 S3DW_TLABEL,
74 S3DW_TINPUT,
75 S3DW_TTEXTBOX,
76 S3DW_TSCROLLBAR,
77 S3DW_NTYPES
79 typedef struct _s3dw_widget s3dw_widget;
80 typedef struct _s3dw_button s3dw_button;
81 typedef struct _s3dw_label s3dw_label;
82 typedef struct _s3dw_textbox s3dw_textbox;
83 typedef struct _s3dw_scrollbar s3dw_scrollbar;
84 typedef struct _s3dw_input s3dw_input;
85 typedef struct _s3dw_surface s3dw_surface;
86 typedef struct _s3dw_style s3dw_style;
88 /** \brief style of s3d widget
90 * With s3dw_style you can change the colors/materials of your widgets.
91 * materials are in the same as in s3d_push_materials_a, that means
92 * red,green,blue and alpha float values (between 0.0 and 1.0) for ambience,
93 * specular and diffuse color.
95 struct _s3dw_style {
96 const char *name; /**< name of the style ... kind of redundant */
97 const char *fontface; /**< font face for all used fonts */
98 float surface_mat[12]; /**< material for the surface background */
99 float input_mat[12]; /**< material for button boxes and other widgets */
100 float inputback_mat[12]; /**< material for input field background */
101 float text_mat[12]; /**< material for the text on buttons and inputs */
102 float title_mat[12]; /**< material for the title bar */
103 float title_text_mat[12]; /**< material for the text on the title bar */
106 /** \brief s3d widget information
108 * This is the most basic widget type, it contains all the "general" widget
109 * information. If you want to move a widget, you'd change x,y,z,s and rx,ry,rz
110 * and call s3dw_moveit to turn your action reality. Every other widget has this
111 * type as first entry, so a simple typecast to s3dw_widget will give you the
112 * widgets "general" information. For typecast, you may use S3DWIDGET().
114 * The pointer ptr allows linking to user-specific data structures. That comes
115 * in handy if the widget is called back by an event, and the program must now
116 * find out on which data the user reacted.
118 struct _s3dw_widget {
119 /* private .. */
120 int type;
121 s3dw_widget *parent;
122 s3dw_style *style;
123 int nobj; /* number of children objects */
124 s3dw_widget **pobj; /* pointer to list of children objects */
125 int focus; /* index of the widget focused in pobj */
126 int flags; /* flags like visibility */
127 float ax, ay, az; /* current position for animation */
128 float as; /* current scale factor */
129 float arx, ary, arz; /* current rotation */
130 float width, height; /* width and height of the widget, outer size */
131 uint32_t oid; /* the main object which is used for transformations etc ...*/
132 /* public */
133 void *ptr; /* a pointer to a user structure, to use in callbacks etc */
134 float x, y, z; /* position, relative to the surface usually */
135 float s; /* scale factor */
136 float rx, ry, rz; /* rotation around the axis */
140 * The callback type. Receive the widget which is affected as argument.
142 * \code
143 * // example
144 * void my_handler(s3dw_widget *widget)
146 * // do something with the widget
147 * ...
149 * \endcode
151 typedef void (*s3dw_callback)(s3dw_widget *);
153 /** \brief button of s3d widget
155 * The buttons is just a button as you would expect it in a 2D widget library.
156 * It only reacts on clicks.
158 struct _s3dw_button {
159 /* private */
160 s3dw_widget widget;
161 char *text;
162 uint32_t oid_text;
163 /* public */
164 s3dw_callback onclick;
167 /** \brief label of s3d widget
169 * The labels is an label-field where a user may type things. onclick reacts on
170 * click in the field.
172 struct _s3dw_label {
173 /* private */
174 s3dw_widget widget;
175 char *text;
176 /* public */
177 s3dw_callback onclick;
180 /** \brief scrollbar of s3d widget
182 * The Scrollbar should be placed around scrollable content. Currently only the
183 * left and right icons are clickable (lonclick and ronclick callbacks), in
184 * vertical mode lonclick is the callback for the up icon, ronclick the callback
185 * for the down icon.
187 struct _s3dw_scrollbar {
188 /* private */
189 s3dw_widget widget;
190 float pos, max;
191 int type; /* 0 = horizontal, 1 = vertical */
192 int loid, roid, baroid;
193 /* public */
194 s3dw_callback lonclick;
195 s3dw_callback ronclick;
199 /** \brief textbox of s3d widget
201 * A textbox shows some text with scrollbars to scroll around. It can currently
202 * only react to a click event.
204 struct _s3dw_textbox {
205 /* private */
206 s3dw_widget widget;
207 s3dw_scrollbar *scroll_vertical,
208 *scroll_horizontal;
209 char *text;
210 int n_lineoids, *p_lineoids;
211 int window_x, window_y;
212 /* public */
213 s3dw_callback onclick;
217 /** \brief input field of s3d widget
219 * The inputs is an input-field where a user may type things. onclick reacts on
220 * click in the field, onedit notifies you when someone writes in the field.
222 struct _s3dw_input {
223 /* private */
224 s3dw_widget widget;
225 char *text;
226 uint32_t oid_text;
227 /* public */
228 s3dw_callback onclick;
229 s3dw_callback onedit;
232 /** \brief root of s3d widget
234 * A surface is the window of this widget library, holding all of our elements
235 * like buttons, input fields etc ...
237 struct _s3dw_surface {
238 /* private */
239 s3dw_widget widget;
240 uint32_t oid_title;
241 uint32_t oid_tbar;
242 char *title;
245 #if defined(__cplusplus) || defined(c_plusplus)
246 extern "C"
248 #endif
250 /* button.c */
251 S3DWEXPORT s3dw_button *s3dw_button_new(const s3dw_surface *surface, const char *text, float posx, float posy);
252 S3DWEXPORT s3dw_label *s3dw_label_new(const s3dw_surface *surface, const char *text, float posx, float posy);
253 S3DWEXPORT s3dw_input *s3dw_input_new(const s3dw_surface *surface, float width, float posx, float posy);
254 S3DWEXPORT s3dw_textbox *s3dw_textbox_new(const s3dw_surface *surface, const char *text, float posx, float posy, float width, float height);
255 S3DWEXPORT char *s3dw_input_gettext(s3dw_input *input);
256 S3DWEXPORT void s3dw_input_change_text(s3dw_input *input, const char *text);
257 S3DWEXPORT void s3dw_label_change_text(s3dw_label *label, const char *text);
258 S3DWEXPORT s3dw_surface *s3dw_surface_new(const char *title, float width, float height) S3DW_WARN_UNUSED_RESULT;
260 S3DWEXPORT s3dw_widget *s3dw_getroot(void);
261 S3DWEXPORT void s3dw_moveit(s3dw_widget *widget);
262 S3DWEXPORT void s3dw_delete(s3dw_widget *widget);
263 S3DWEXPORT void s3dw_show(s3dw_widget *widget);
264 S3DWEXPORT void s3dw_focus(s3dw_widget *focus);
266 S3DWEXPORT void s3dw_textbox_scrollup(s3dw_textbox *textbox);
267 S3DWEXPORT void s3dw_textbox_scrolldown(s3dw_textbox *textbox);
268 S3DWEXPORT void s3dw_textbox_scrollleft(s3dw_textbox *textbox);
269 S3DWEXPORT void s3dw_textbox_scrollright(s3dw_textbox *textbox);
270 S3DWEXPORT void s3dw_textbox_scrollto(s3dw_textbox *textbox, int x, int y);
271 S3DWEXPORT void s3dw_textbox_change_text(s3dw_textbox *textbox, const char *text);
273 S3DWEXPORT int s3dw_handle_click(const struct s3d_evt *event);
274 S3DWEXPORT int s3dw_handle_key(const struct s3d_evt *event);
275 S3DWEXPORT int s3dw_object_info(struct s3d_evt *event);
277 S3DWEXPORT void s3dw_ani_mate(void);
279 #if defined(__cplusplus) || defined(c_plusplus)
280 } /* extern "C" */
281 #endif
283 #endif