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
  
284
  
285
  
286
  
287
  
288
  
289
  
290
  
291
  
292
  
293
  
294
  
295
  
296
  
297
  
298
  
299
  
300
  
301
  
302
  
303
  
304
  
305
  
306
  
307
  
/* -*- C -*- */ 
require gtkdatabox; 
 
class GTK2.Databox; 
inherit GTK2.Vbox; 
 
%{ 
#include <gtkdatabox.h> 
%} 
add_global { 
#include <gtkdatabox.h> 
}; 
 
//! GtkDatabox is designed to display large amounts of numerical data 
//! fast and easy. Thousands of data points (X and Y coordinate) may be 
//! displayed without any problems, zooming and scrolling as well as 
//! optional rulers are already included. 
//! <p> 
//! The widget may be used as display for oscilloscopes or other 
//! applications that need to display fast changes in their data. 
//! </p> 
//! IMG:   GTK2.Databox x=GTK2.Databox(); x->data_add_x_y(3, ({ 1.0, 0.5, 0.0 }), ({1.0, -1.0, 0.0}),GTK2.GdkColor(Image.Color.red), GTK2.DataboxLines,2); x->rescale(); x->set_size_request(300,300); return x; 
 
constant int GTK_DATABOX_NOT_DISPLAYED; 
constant int GTK_DATABOX_POINTS; 
constant int GTK_DATABOX_LINES; 
constant int GTK_DATABOX_BARS; 
constant int GTK_DATABOX_CROSS_SIMPLE; 
constant int GTK_DATABOX_GRID; 
 
signal zoomed; 
signal marked; 
signal selection_started; 
signal selection_changed; 
signal selection_stopped; 
signal selection_canceled; 
 
void create(); 
//! Create a new databox widget 
 
void redraw(); 
//! Redraw. 
 
%{ 
struct data_wrapper { 
  gfloat *X,*Y; 
}; 
%} 
 
/* 
void data_add(array(float) X, array(float) Y, GDK2.Color color, 
              int type, int dot_size) 
//! Add data to the box. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct array *a1,*a2; 
    struct object *o1; 
    INT_TYPE type,dot_size; 
    GdkColor *color; 
    struct data_wrapper *dw; 
    int i,len; 
    int ind; 
    get_all_args(NULL,args,"%A%A%o%i%i",&a1,&a2,&o1,&type,&dot_size); 
    if (a1==NULL || a2==NULL || a1->size<1 || a2->size<1) 
      Pike_error("Not arrays!\n"); 
    color=(GdkColor *)get_gdkobject(o1,color); 
    dw=(struct data_wrapper *)g_malloc(sizeof(struct data_wrapper)); 
    if (dw==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("data_add",sizeof(struct data_wrapper)); 
    len=MAX(a1->size,a2->size); 
    dw->X=(gfloat *)g_malloc(sizeof(gfloat)*len); 
    dw->Y=(gfloat *)g_malloc(sizeof(gfloat)*len); 
    if (dw->X==NULL || dw->Y==NULL) { 
      if(dw->X) g_free(dw->X); 
      g_free(dw); 
      SIMPLE_OUT_OF_MEMORY_ERROR("data_add",sizeof(gfloat)*len*2); 
    } 
    for (i=0; i<len; i++) { 
      dw->X[i]=pgtk2_get_float(ITEM(a1)+i); 
      dw->Y[i]=pgtk2_get_float(ITEM(a2)+i); 
    } 
    if (THIS->extra_data) { 
      if (THIS->extra_data->X) 
        g_free(THIS->extra_data->X); 
      if (THIS->extra_data->Y) 
        g_free(THIS->extra_data->Y); 
      g_free(THIS->extra_data); 
    } 
    THIS->extra_data=dw; 
    ind=gtk_databox_data_add(GTK_DATABOX(THIS->obj),len,dw->X,dw->Y, 
                         *color,type,dot_size); 
    pgtk2_pop_n_elems(args); 
    push_int(ind); 
  } 
} 
*/ 
 
void set_rulers_enable(int setting); 
//! Set whether rulers will be displayed. 
 
void get_rulers_enable(); 
//! Get whether rulers will be displayed. 
 
void set_selection_enable(int setting); 
//! Set whether selection is enabled. 
 
int get_selection_enable(); 
//! Get whether selection is enabled. 
 
void set_selection_fill_enable(int setting); 
//! Set whether the selection will be filled. 
 
int get_selection_fill_enable(); 
//! Get whether the selection will be filled. 
 
void set_scrollbars_enable(int setting); 
//! Set whether scrollbars will be displayed. 
 
void get_scrollbars_enable(); 
//! Get whether scrollbars will be displayed. 
 
void set_zoom_enable(int setting); 
//! Set whether zoom is enabled. 
 
void get_zoom_enable(); 
//! Get whether zoom is enabled. 
 
void set_zoom_limit(float limit); 
//! Set the zoom limit.  Default is 0.01, which is 100 times. 
 
float get_zoom_limit(); 
//! Get the zoom limit. 
 
%{ 
static GtkDataboxCoord get_coord(int offset, int args) { 
  GtkDataboxCoord c; 
  if (args<offset+2) 
    Pike_error("too few arguments\n"); 
  if (TYPEOF(Pike_sp[-args+offset]) != PIKE_T_INT) 
    Pike_error("Bad argument %d\n",offset); 
  else 
    c.x=Pike_sp[-args+offset].u.integer; 
  if (TYPEOF(Pike_sp[-args+offset+1]) != PIKE_T_INT) 
    Pike_error("Bad argument %d\n",offset); 
  else 
    c.y=Pike_sp[-args+offset+1].u.integer; 
  return c; 
} 
 
static GtkDataboxValue get_value(int offset, int args) { 
  GtkDataboxValue c; 
  if (args<offset+2) 
    Pike_error("too few arguments\n"); 
  if (TYPEOF(Pike_sp[-args+offset]) != PIKE_T_FLOAT) 
    Pike_error("Bad argument %d\n",offset); 
  else 
    c.x=Pike_sp[-args+offset].u.float_number; 
  if (TYPEOF(Pike_sp[-args+offset+1]) != PIKE_T_FLOAT) 
    Pike_error("Bad argument %d\n",offset); 
  else 
    c.y=Pike_sp[-args+offset+1].u.float_number; 
  return c; 
} 
 
static void push_value(GtkDataboxValue v) { 
  push_static_text("x"); push_float(v.x); 
  push_static_text("y"); push_float(v.y); 
  f_aggregate_mapping(4); 
} 
%} 
 
mapping(string:float) data_get_value(int x, int y) 
//! Get the value at the given coordinates. 
{ 
  GtkDataboxValue v; 
  gtk_databox_data_get_value(GTK_DATABOX(THIS->obj),get_coord(0,args),&v); 
  pgtk2_pop_n_elems(args); 
  push_value(v); 
} 
 
array(mapping(string:float)) data_get_visible_extrema() 
//! Get the positions of the edges of the display. 
{ 
  GtkDataboxValue v1,v2; 
  pgtk2_pop_n_elems(args); 
  gtk_databox_data_get_visible_extrema(GTK_DATABOX(THIS->obj), &v1, &v2 ); 
  push_value( v1 ); 
  push_value( v2 ); 
  f_aggregate(2); 
} 
 
array(mapping(string:float)) data_get_extrema() 
//! Get the bounds of the data set (?) 
{ 
  GtkDataboxValue v1,v2; 
  pgtk2_pop_n_elems(args); 
  gtk_databox_data_get_extrema(GTK_DATABOX(THIS->obj),&v1,&v2); 
  push_value(v1); 
  push_value(v2); 
  f_aggregate(2); 
} 
 
void rescale(); 
//! Rescale with automatically-calculated extrema. 
 
void rescale_with_values(float minx, float miny, float maxx, float maxy) 
//! Rescale with specific data extrema. 
{ 
  gtk_databox_rescale_with_values(GTK_DATABOX(THIS->obj), 
                                  get_value(0,args), 
                                  get_value(2,args)); 
  RETURN_THIS(); 
} 
 
void rescale_inverted(int invertX, int invertY); 
//! Rescale with an inverted x and/or y direction. 
 
int data_set_color(int index, *GDK2.Color color); 
//! Set the color at index. 
 
void set_background_color(*GDK2.Color color); 
//! Set the background color. 
 
GDK2.Color data_get_color(int index) 
//! Get the color at index. 
{ 
  pgtk2_verify_inited(); 
  { 
    INT_TYPE index; 
    GdkColor *col; 
    get_all_args(NULL,args,"%i",&index); 
    col=(GdkColor *)g_malloc(sizeof(GdkColor)); 
    if (col==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("get_color",sizeof(GdkColor)); 
    gtk_databox_data_get_color(GTK_DATABOX(THIS->obj),index,col); 
    pgtk2_pop_n_elems(args); 
    push_gdkobject(col,color,1); 
  } 
} 
 
int data_set_type(int index, int type, int dot_size); 
//! Type is one of CONST(GTK_DATABOX_) 
 
array(int) data_get_type(int index) 
//! Return type and dot size at index. 
{ 
  pgtk2_verify_inited(); 
  { 
    INT_TYPE index; 
    guint dot_size; 
    GtkDataboxDataType type; 
    get_all_args(NULL,args,"%i",&index); 
    pgtk2_pop_n_elems(args); 
    gtk_databox_data_get_type(GTK_DATABOX(THIS->obj),index,&type,&dot_size); 
    push_int(type); 
    push_int(dot_size); 
    f_aggregate(2); 
  } 
} 
int data_add(int nelems, array(float,nofree) x, array(float,nofree) y, 
                 *GDK2.Color color, int type, int dot_size); 
//! Type is one of CONST(GTK_DATABOX_) 
 
/* 
int data_add_x(int nelems, array(float,nofree) x, 
               int shared_Y_index, *GDK2.Color color, 
               int type, int dot_size); 
//! Type is one of CONST(GTK_DATABOX_) 
 
int data_add_y(int nelems, array(float,nofree) y, int shared_X_index, 
               *GDK2.Color color, int type, int dot_size); 
//! Type is one of CONST(GTK_DATABOX_) 
*/ 
 
int data_remove(int index); 
//! Remove data at index. 
 
int data_remove_all(); 
//! Remove all data. 
 
/* 
int data_destroy(int index); 
 
int data_destroy_all(); 
*/ 
 
int data_set_grid_config(int index, int hlines, int vlines); 
//! Not useful unless the data type is GTK2.DATABOX_GRID. 
 
int data_get_grid_config(int index) 
//! See data_set_grid_config(). 
{ 
  pgtk2_verify_inited(); 
  { 
    INT_TYPE index; 
    unsigned int hlines,vlines; 
    get_all_args(NULL,args,"%i",&index); 
    pgtk2_pop_n_elems(args); 
    gtk_databox_data_get_grid_config(GTK_DATABOX(THIS->obj),index, 
                        &hlines,&vlines); 
    push_int(hlines); 
    push_int(vlines); 
    f_aggregate(2); 
  } 
}