9
rescol, dbobj, colbr, rs, gs, bs : PFL_OBJECT;
13
{ the RGB data file does not have a standard location on unix. }
14
{ You may need to edit this }
16
const rgbfile = '/usr/lib/X11/rgb.txt';
23
rgbdb : array [0..MAX_RGB] of TRGBdb;
26
procedure set_entry(i : longint);
35
fl_mapcolor(FL_FREE_COL4+i, db.r, db.g, db.b);
36
fl_mapcolor(FL_FREE_COL4, db.r, db.g, db.b);
37
fl_set_slider_value(rs, db.r);
38
fl_set_slider_value(gs, db.g);
39
fl_set_slider_value(bs, db.b);
40
fl_redraw_object(rescol);
44
procedure br_cb(ob : PFL_OBJECT; q :longint);cdecl;
49
r := fl_get_browser(ob);
50
if (r <= 0) then exit;
54
{ slow but straightforward }
55
function stripsp (s : string) : string;
61
for i:=1 to length(s) do
62
if pos(s[i],'0987654321')<>0 then temp:=temp+s[i];
67
function read_entry(Var r,g,b : longint;var name : string) : longint;
77
if buf[1]='!' then exit(0);
78
temp:=stripsp(copy(buf,1,4));delete(buf,1,4);
80
if code<>0 then exit(0);
81
temp:=stripsp(copy(buf,1,4));delete(buf,1,4);
83
if code<>0 then exit(0);
84
temp:=stripsp(copy(buf,1,4));delete(buf,1,4);
86
if code<>0 then exit(0);
87
{ strip leading spaces from name }
88
while (buf[code+1]=' ') or (buf[code+1]=#9) do inc(code);
89
if code<>0 then delete(buf,1,code);
95
function load_browser(fname : string) : longint;
102
assign (infile,fname);
109
fl_show_alert('Load', @fname[1], 'Can''t open', 0);
115
while not eof(infile) do
117
if read_entry(r, g, b, buf)<>0 then
120
rgbdb[numcol].r := r;
121
rgbdb[numcol].g := g;
122
rgbdb[numcol].b := b;
123
str (r,rr); if length(rr)<3 then rr:=copy(' ',1,3-length(rr))+rr;
124
str(g,gg);if length(gg)<3 then gg:=copy(' ',1,3-length(gg))+gg;
125
str(b,bb);if length(bb)<3 then bb:=copy(' ',1,3-length(bb))+bb;
126
buf:='('+rr+' '+gg+' '+bb+') '+buf;
127
fl_addto_browser(colbr, @buf[1]);
131
fl_set_browser_topline(colbr, 1);
132
fl_select_browser_line(colbr, 1);
134
fl_unfreeze_form(cl);
138
function search_entry(r,g,b : Longint) : Longint;
140
var i, j, diffr, diffg, diffb,diff, mindiff : longint;
146
for i:=0 to numcol do
148
diffr := abs(r - rgbdb[i].r);
149
diffg := abs(g - rgbdb[i].g);
150
diffb := abs(b - rgbdb[i].b);
151
diff := round((3.0 * diffr) +
154
if (mindiff > diff) then
163
procedure search_rgb(ob : PFL_OBJECT; q : longint);cdecl;
165
var r, g, b, i,top : longint;
168
top := fl_get_browser_topline(colbr);
169
r := round(fl_get_slider_value(rs));
170
g := round(fl_get_slider_value(gs));
171
b := round(fl_get_slider_value(bs));
174
fl_mapcolor(FL_FREE_COL4, r, g, b);
175
fl_redraw_object(rescol);
176
i := search_entry(r, g, b);
177
{ change topline only if necessary }
178
if (i < top) or (i > (top+15)) then
179
fl_set_browser_topline(colbr, i-8);
180
fl_select_browser_line(colbr, i + 1);
181
fl_unfreeze_form(cl);
185
procedure db_cb(ob : PFL_OBJECT; q : longint);cdecl;
191
p := fl_show_input('Enter New Database Name', @dbname[1]);
193
if buf=dbname then exit;
195
if (load_browser(buf)<>0) then
198
fl_set_object_label(ob, @dbname[1]);
201
procedure done_cb (ob : PFL_OBJECT; q : longint);cdecl;
206
procedure create_form_cl;
211
if (cl<>nil) then exit;
212
cl := fl_bgn_form(FL_NO_BOX, 330, 385);
213
obj := fl_add_box(FL_UP_BOX, 0, 0, 330, 385, '');
214
fl_set_object_color(obj, FL_INDIANRED, FL_COL1);
215
obj := fl_add_box(FL_NO_BOX, 40, 10, 250, 30, 'Color Browser');
216
fl_set_object_lcol(obj, FL_RED);
217
fl_set_object_lsize(obj, FL_HUGE_SIZE);
218
fl_set_object_lstyle(obj, FL_BOLD_STYLE + FL_SHADOW_STYLE);
219
obj := fl_add_button(FL_NORMAL_BUTTON, 40, 50, 250, 25, '');
221
fl_set_object_boxtype(obj, FL_BORDER_BOX);
222
{ if fl_get_visual_depth()=1 then
223
fl_set_object_color(obj, FL_WHITE,FL_INDIANRED)
225
fl_set_object_color(obj, FL_INDIANRED, FL_INDIANRED);
227
fl_set_object_callback(obj, PFL_CALLBACKPTR(@db_cb), 0);
229
obj:= fl_add_valslider(FL_VERT_FILL_SLIDER, 225, 130, 30, 200, '');
231
fl_set_object_color(obj, FL_INDIANRED, FL_RED);
232
fl_set_slider_bounds(obj, 0, 255);
233
fl_set_slider_precision(obj, 0);
234
fl_set_object_callback(obj, PFL_CALLBACKPTR(@search_rgb), 0);
235
fl_set_slider_return(obj, 0);
236
obj:= fl_add_valslider(FL_VERT_FILL_SLIDER, 255, 130, 30, 200, '');
238
fl_set_object_color(obj, FL_INDIANRED, FL_GREEN);
239
fl_set_slider_bounds(obj, 0.0, 255.0);
240
fl_set_slider_precision(obj, 0);
241
fl_set_object_callback(obj, PFL_CALLBACKPTR(@search_rgb), 1);
242
fl_set_slider_return(obj, 0);
243
obj := fl_add_valslider(FL_VERT_FILL_SLIDER, 285, 130, 30, 200, '');
245
fl_set_object_color(obj, FL_INDIANRED, FL_BLUE);
246
fl_set_slider_bounds(obj, double(0.0), double(255.0));
247
fl_set_slider_precision(obj, 0);
248
fl_set_object_callback(obj, PFL_CALLBACKPTR(@search_rgb), 2);
249
fl_set_slider_return(obj, 0);
250
obj := fl_add_browser(FL_HOLD_BROWSER, 10, 90, 205, 240, '');
252
fl_set_browser_fontstyle(obj, FL_FIXED_STYLE);
253
fl_set_object_callback(obj, PFL_CALLBACKPTR(@br_cb), 0);
255
obj := fl_add_button(FL_NORMAL_BUTTON, 135, 345, 80, 30, 'Done');
256
fl_set_object_callback(obj, PFL_CALLBACKPTR(@done_cb), 0);
257
obj := fl_add_box(FL_FLAT_BOX, 225, 90, 90, 35, '');
259
fl_set_object_color(obj, FL_FREE_COL4, FL_FREE_COL4);
260
fl_set_object_boxtype(obj, FL_BORDER_BOX);
263
{fl_scale_form (cl, 1.1, 1.0);}
267
fl_initialize(@argc, argv, 'FormDemo', nil, 0);
271
if (load_browser(dbname)<>0) then
272
fl_set_object_label(dbobj, @dbname[1])
274
fl_set_object_label(dbobj, 'None');
276
fl_set_form_minsize(cl, cl^.w , cl^.h);
277
fl_set_form_maxsize(cl, 2*cl^.w , 2*cl^.h);
278
fl_show_form(cl, FL_PLACE_FREE, FL_TRANSIENT, 'RGB Browser');
280
while (fl_do_forms()<>nil) do;