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
|
#include <stdio.h>
#include <stdlib.h>
#include "iup.h"
#include "cd.h"
#include "cdiup.h"
#include "iupcontrols.h"
static Ihandle *canvas = NULL;
static cdCanvas *cdcanvas = NULL;
static int redraw_cb(Ihandle* ih)
{
if (!cdcanvas)
return IUP_DEFAULT;
/* Activates canvas cdcanvas */
cdActivate(cdcanvas);
cdClear();
/* Draws a rectangle on the canvas */
cdBegin(CD_FILL);
cdVertex(50, 50);
cdVertex(150, 50);
cdVertex(100, 150);
cdEnd();
/* Function executed sucessfully */
return IUP_DEFAULT;
}
static int extended_cb(Ihandle* ih, int cell)
{
printf("extended_cb(%d)\n", cell);
return IUP_DEFAULT;
}
static char* cell_cb(Ihandle* ih, int cell)
{
int ri, gi, bi;
static char str[30];
sprintf(str, "CELL%d", cell);
sscanf(IupGetAttribute(ih, str), "%d %d %d", &ri, &gi, &bi);
printf("cell_cb(%d): %d, %d, %d\n", cell, ri, gi, bi);
/*
unsigned char r, g, b;
r = (unsigned char)ri;
g = (unsigned char)gi;
b = (unsigned char)bi;
if (IupGetColor(IUP_MOUSEPOS, IUP_MOUSEPOS, &r, &g, &b))
{
sprintf(str, "%d %d %d", (int)r, (int)g, (int)b);
cdActivate( cdcanvas ) ;
cdForeground(cdEncodeColor(r, g, b));
redraw_cb(canvas);
return str;
}
*/
return NULL;
}
static int select_cb(Ihandle* ih, int cell, int type)
{
long cd_color;
char str[30];
int ri, gi, bi;
sprintf(str, "CELL%d", cell);
sscanf(IupGetAttribute(ih, str), "%d %d %d", &ri, &gi, &bi);
printf("select_cb(%d, %d): %d, %d, %d\n", cell, type, ri, gi, bi);
cd_color = cdEncodeColor((unsigned char)ri,(unsigned char)gi,(unsigned char)bi);
if (!cdcanvas)
return IUP_DEFAULT;
cdActivate( cdcanvas ) ;
if (type == -1)
cdForeground(cd_color);
else
cdBackground(cd_color);
redraw_cb(canvas);
return IUP_DEFAULT;
}
static int switch_cb(Ihandle* ih, int primcell, int seccell)
{
long fgcolor;
if (!cdcanvas)
return IUP_DEFAULT;
printf("switch_cb(%d, %d)\n", primcell, seccell);
cdActivate(cdcanvas) ;
fgcolor = cdForeground(CD_QUERY);
cdForeground(cdBackground(CD_QUERY));
cdBackground(fgcolor);
redraw_cb(canvas);
return IUP_DEFAULT;
}
void ColorbarTest(void)
{
Ihandle *dlg, *cb;
IupControlsOpen();
/* Creates a canvas associated with the redraw action */
canvas = IupCanvas(NULL) ;
IupSetCallback(canvas, "ACTION", (Icallback)redraw_cb);
IupSetAttribute(canvas, "RASTERSIZE", "200x300");
cb = IupColorbar();
IupSetAttribute(cb, "RASTERSIZE", "70x");
IupSetAttribute(cb, "EXPAND", "VERTICAL");
IupSetAttribute(cb, "NUM_PARTS", "2");
IupSetAttribute(cb, "SHOW_SECONDARY", "YES");
IupSetAttribute(cb, "PREVIEW_SIZE", "60");
// IupSetAttribute(cb, "ACTIVE", "NO");
// IupSetAttribute(cb, "BGCOLOR", "128 0 255");
IupSetCallback(cb, "SELECT_CB", (Icallback)select_cb);
IupSetCallback(cb, "CELL_CB", (Icallback)cell_cb);
IupSetCallback(cb, "SWITCH_CB", (Icallback)switch_cb);
IupSetCallback(cb, "EXTENDED_CB", (Icallback)extended_cb);
dlg = IupDialog(IupHbox(canvas, cb, NULL));
IupSetAttribute(dlg, "MARGIN", "5x5");
IupSetAttribute(dlg, "TITLE", "IupColorbar");
/* Maps the dlg. This must be done before the creation of the CD canvas.
Could also use MAP_CB callback. */
IupMap(dlg);
cdcanvas = cdCreateCanvas(CD_IUP, canvas);
IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
IupMainLoop();
IupDestroy(dlg);
IupClose();
}
#ifndef BIG_TEST
int main(int argc, char* argv[])
{
IupOpen(&argc, &argv);
ColorbarTest();
IupMainLoop();
IupClose();
return EXIT_SUCCESS;
}
#endif
|