File: s3dw.h

package info (click to toggle)
s3d 0.2.2-10
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,544 kB
  • ctags: 5,243
  • sloc: ansic: 20,861; python: 488; perl: 98; makefile: 39; sh: 29
file content (283 lines) | stat: -rw-r--r-- 9,450 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
 * s3dw.h
 *
 * Copyright (C) 2006-2011  Simon Wunderlich <sw@simonwunderlich.de>
 *
 * This file is part of the s3d Widgets, a Widget Library for s3d.
 * See http://s3d.berlios.de/ for more updates.
 *
 * s3d Widgets is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * s3d Widgets is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with the s3d Widgets; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef LIBS3DW_H
#define LIBS3DW_H
#ifndef LIBS3D_H
#include <s3d.h>
#endif
#include <stdint.h>  /* [u]intXX_t type definitions*/

#ifdef HAVE_GCCVISIBILITY
#define S3DWEXPORT_VISIBILITY __attribute__ ((visibility("default")))
#else
#define S3DWEXPORT_VISIBILITY
#endif

#ifdef HAVE_GCCEXTERNALLY
#define S3DWEXPORT_EXTERNAL __attribute__((externally_visible))
#else
#define S3DWEXPORT_EXTERNAL
#endif

#define S3DWEXPORT S3DWEXPORT_VISIBILITY S3DWEXPORT_EXTERNAL

#ifdef __GNUC_MINOR__
#define S3DW_WARN_UNUSED_RESULT  __attribute__ ((warn_unused_result))
#else
#define S3DW_WARN_UNUSED_RESULT
#endif

/* we want this widget visible, as long as the widgets below are also visible.
 * on for all widgets, except surfaces which have to be switched visible
 * with s3dw_show() */
#define  S3DW_VISIBLE 1
/* widget should accept input. that's on by default. */
#define  S3DW_ACTIVE  2
/* tells us if the widget is currently displayed */
#define  S3DW_ONSCREEN 256
/* if the surface (or widget) is already properly arranged */
#define  S3DW_ARRANGED 512
/* follow the camera */
#define  S3DW_FOLLOW_CAM 1024
/* turn to the camera */
#define  S3DW_TURN_CAM 2048
/* just a typecaster to beatify code. use it if you like */
#define  S3DWIDGET(x) ((s3dw_widget *)x)

enum {
	S3DW_TROOT,
	S3DW_TCAM,
	S3DW_TSURFACE,
	S3DW_TBUTTON,
	S3DW_TLABEL,
	S3DW_TINPUT,
	S3DW_TTEXTBOX,
	S3DW_TSCROLLBAR,
	S3DW_NTYPES
};
typedef struct _s3dw_widget  s3dw_widget;
typedef struct _s3dw_button  s3dw_button;
typedef struct _s3dw_label   s3dw_label;
typedef struct _s3dw_textbox   s3dw_textbox;
typedef struct _s3dw_scrollbar  s3dw_scrollbar;
typedef struct _s3dw_input   s3dw_input;
typedef struct _s3dw_surface   s3dw_surface;
typedef struct _s3dw_style   s3dw_style;

/** \brief style of s3d widget
 *
 * With s3dw_style you can change the colors/materials of your widgets.
 * materials are in the same as in s3d_push_materials_a, that means
 * red,green,blue and alpha float values (between 0.0 and 1.0) for ambience,
 * specular and diffuse color.
 */
struct _s3dw_style {
	const char *name;     /**< name of the style ... kind of redundant */
	const char *fontface;    /**< font face for all used fonts */
	float surface_mat[12];  /**< material for the surface background */
	float input_mat[12];  /**< material for button boxes and other widgets */
	float inputback_mat[12]; /**< material for input field background */
	float text_mat[12];   /**< material for the text on buttons and inputs */
	float title_mat[12];  /**< material for the title bar */
	float title_text_mat[12]; /**< material for the text on the title bar */
};

/** \brief s3d widget information
 *
 * This is the most basic widget type, it contains all the "general" widget
 * information. If you want to move a widget, you'd change x,y,z,s and rx,ry,rz
 * and call s3dw_moveit to turn your action reality. Every other widget has this
 * type as first entry, so a simple typecast to s3dw_widget will give you the
 * widgets "general" information. For typecast, you may use S3DWIDGET().
 *
 * The pointer ptr allows linking to user-specific data structures. That comes
 * in handy if the widget is called back by an event, and the program must now
 * find out on which data the user reacted.
 */
struct _s3dw_widget {
	/* private .. */
	int      type;
	s3dw_widget *parent;
	s3dw_style  *style;
	int       nobj; /* number of children objects */
	s3dw_widget    **pobj; /* pointer to list of children objects */
	int    focus;   /* index of the widget focused in pobj */
	int      flags;   /* flags like visibility */
	float    ax, ay, az;  /* current position for animation */
	float    as;   /* current scale factor */
	float    arx, ary, arz; /* current rotation */
	float    width, height; /* width and height of the widget, outer size */
	uint32_t  oid;   /* the main object which is used for transformations etc ...*/
	/* public */
	void  *ptr;   /* a pointer to a user structure, to use in callbacks etc */
	float    x, y, z; /* position, relative to the surface usually */
	float    s;    /* scale factor */
	float    rx, ry, rz;  /* rotation around the axis */
};

/**
 * The callback type. Receive the widget which is affected as argument.
 *
 * \code
 * // example
 * void my_handler(s3dw_widget *widget)
 * {
 *         // do something with the widget
 *         ...
 * }
 * \endcode
 */
typedef void (*s3dw_callback)(s3dw_widget *);

/** \brief button of s3d widget
 *
 * The buttons is just a button as you would expect it in a 2D widget library.
 * It only reacts on clicks.
 */
struct _s3dw_button {
	/* private */
	s3dw_widget   widget;
	char    *text;
	uint32_t      oid_text;
	/* public */
	s3dw_callback   onclick;
};

/** \brief label of s3d widget
 *
 * The labels is an label-field where a user may type things. onclick reacts on
 * click in the field.
 */
struct _s3dw_label {
	/* private */
	s3dw_widget   widget;
	char    *text;
	/* public */
	s3dw_callback   onclick;
};

/** \brief scrollbar of s3d widget
 *
 * The Scrollbar should be placed around scrollable content. Currently only the
 * left and right icons are clickable (lonclick and ronclick callbacks), in
 * vertical mode lonclick is the callback for the up icon, ronclick the callback
 * for the down icon.
 */
struct _s3dw_scrollbar {
	/* private */
	s3dw_widget   widget;
	float    pos, max;
	int     type; /* 0 = horizontal, 1 = vertical */
	int     loid, roid, baroid;
	/* public */
	s3dw_callback   lonclick;
	s3dw_callback   ronclick;

};

/** \brief textbox of s3d widget
 *
 * A textbox shows some text with scrollbars to scroll around. It can currently
 * only react to a click event.
 */
struct _s3dw_textbox {
	/* private */
	s3dw_widget   widget;
	s3dw_scrollbar *scroll_vertical,
	               *scroll_horizontal;
	char    *text;
	int    n_lineoids, *p_lineoids;
	int    window_x, window_y;
	/* public */
	s3dw_callback   onclick;

};

/** \brief input field of s3d widget
 *
 * The inputs is an input-field where a user may type things. onclick reacts on
 * click in the field, onedit notifies you when someone writes in the field.
 */
struct _s3dw_input {
	/* private */
	s3dw_widget   widget;
	char    *text;
	uint32_t     oid_text;
	/* public */
	s3dw_callback   onclick;
	s3dw_callback   onedit;
};

/** \brief root of s3d widget
 *
 * A surface is the window of this widget library, holding all of our elements
 * like buttons, input fields etc ...
 */
struct _s3dw_surface {
	/* private */
	s3dw_widget     widget;
	uint32_t     oid_title;
	uint32_t     oid_tbar;
	char     *title;
};

#if defined(__cplusplus) || defined(c_plusplus)
extern "C"
{
#endif

	/* button.c */
	S3DWEXPORT s3dw_button   *s3dw_button_new(const s3dw_surface *surface, const char *text, float posx, float posy);
	S3DWEXPORT s3dw_label    *s3dw_label_new(const s3dw_surface *surface, const char *text, float posx, float posy);
	S3DWEXPORT s3dw_input    *s3dw_input_new(const s3dw_surface *surface, float width, float posx, float posy);
	S3DWEXPORT s3dw_textbox   *s3dw_textbox_new(const s3dw_surface *surface, const char *text, float posx, float posy, float width, float height);
	S3DWEXPORT char     *s3dw_input_gettext(s3dw_input *input);
	S3DWEXPORT void      s3dw_input_change_text(s3dw_input *input, const char *text);
	S3DWEXPORT void      s3dw_label_change_text(s3dw_label *label, const char *text);
	S3DWEXPORT s3dw_surface   *s3dw_surface_new(const char *title, float width, float height) S3DW_WARN_UNUSED_RESULT;

	S3DWEXPORT s3dw_widget   *s3dw_getroot(void);
	S3DWEXPORT void     s3dw_moveit(s3dw_widget *widget);
	S3DWEXPORT void      s3dw_delete(s3dw_widget *widget);
	S3DWEXPORT void      s3dw_show(s3dw_widget *widget);
	S3DWEXPORT void      s3dw_focus(s3dw_widget *focus);

	S3DWEXPORT void      s3dw_textbox_scrollup(s3dw_textbox *textbox);
	S3DWEXPORT void      s3dw_textbox_scrolldown(s3dw_textbox *textbox);
	S3DWEXPORT void      s3dw_textbox_scrollleft(s3dw_textbox *textbox);
	S3DWEXPORT void      s3dw_textbox_scrollright(s3dw_textbox *textbox);
	S3DWEXPORT void      s3dw_textbox_scrollto(s3dw_textbox *textbox, int x, int y);
	S3DWEXPORT void      s3dw_textbox_change_text(s3dw_textbox *textbox, const char *text);

	S3DWEXPORT int      s3dw_handle_click(const struct s3d_evt *event);
	S3DWEXPORT int      s3dw_handle_key(const struct s3d_evt *event);
	S3DWEXPORT int      s3dw_object_info(struct s3d_evt *event);

	S3DWEXPORT void      s3dw_ani_mate(void);

#if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */
#endif

#endif