[go: up one dir, main page]

File: colsel.c

package info (click to toggle)
libforms1 1.0-8
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,648 kB
  • ctags: 14,351
  • sloc: ansic: 90,441; makefile: 9,902; sh: 8
file content (156 lines) | stat: -rw-r--r-- 3,806 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
/*
 *
 *  This file is part of the XForms library package.
 *
 * XForms 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, or
 * (at your option) any later version.
 *
 * XForms 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 XForms; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 *
 */


/*
 * $Id: colsel.c,v 1.0 2002/05/08 05:16:30 zhao Release $
 *.
 *  This file is part of the XForms library package.
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *.
 *
 *  Select a color
 *
 */

#include "forms.h"

typedef struct
{
     FL_FORM *colorform;
     FL_OBJECT *col[64];
     FL_OBJECT *next, *prev, *cancel;
     FL_OBJECT *cindex;
} COLSEL;

static COLSEL colsel;
static COLSEL *cs = &colsel;

static void
create_colorform(void)
{
    int i, j;

    if (cs->colorform)
	return;

    cs->colorform = fl_bgn_form(FL_UP_BOX, 240, 220);

    for (i = 0; i < 8; i++)
    {
	for (j = 0; j < 8; j++)
	{
	    cs->col[8 * i + j] = fl_add_button(FL_NORMAL_BUTTON, 40 + j * 20,
					   10 + i * 20, 20, 20, "");
	    fl_set_object_boxtype(cs->col[8 * i + j], FL_BORDER_BOX);
	    fl_set_object_lcol(cs->col[8 * i + j], 7);
	}
    }
    cs->prev = fl_add_button(FL_NORMAL_BUTTON, 10, 10, 30, 160, "@4");
    cs->next = fl_add_button(FL_NORMAL_BUTTON, 200, 10, 30, 160, "@6");
    cs->cancel = fl_add_button(FL_NORMAL_BUTTON, 80, 180, 140, 30, "Cancel");
    cs->cindex = fl_add_text(FL_NORMAL_TEXT, 5, 180, 70, 30, "Cancel");
    fl_set_object_lsize(cs->cindex,FL_TINY_SIZE);
    fl_end_form();
}

extern int flrectboundcolor;
/* initializes the colors */
static void
init_colors(int cc, int thecol)
{
    int i;
    const char *cn;

    fl_freeze_form(cs->colorform);
    for (i = 0; i < 64; i++)
    {
	fl_set_object_color(cs->col[i], cc + i, cc + i);
	fl_set_object_label(cs->col[i], "");
	if (thecol == cc + i)
	    fl_set_object_label(cs->col[i], "@9plus");
    }
    cn = fl_query_colorname(thecol);
    fl_set_object_label(cs->cindex, cn + (cn[0]=='F' ? 3:0));
    fl_unfreeze_form(cs->colorform);
}

static int
atclose(FL_FORM * form, void *ev)
{
    fl_trigger_object(form->u_vdata);
    return FL_IGNORE;
}

/* Shows a colormap color selector from which the user can select a color. */
int
fl_show_colormap(int oldcol)
{
    FL_OBJECT *ob;
    int i, cc, ready = 0, thecol;
    int s =  flrectboundcolor;

    flrectboundcolor = FL_BOTTOM_BCOL;

    if (oldcol == FL_NoColor)
	oldcol = FL_COL1;

    cc = 64 * (oldcol / 64);
    thecol = oldcol;

    create_colorform();
    cs->colorform->u_vdata = cs->cancel;
    fl_set_form_atclose(cs->colorform, atclose, 0);
    init_colors(cc, thecol);
    fl_set_object_color(cs->cancel, thecol, thecol);
    fl_deactivate_all_forms();

    fl_show_form(cs->colorform, FL_PLACE_ASPECT, FL_TRANSIENT, "Colormap");

    while (!ready)
    {
	ob = fl_do_only_forms();
	if (ob == cs->prev && cc >= 64)
	{
	    cc -= 64;
	    init_colors(cc, thecol);
	}
	else if (ob == cs->next && (cc + 64) < FL_MAX_COLS)
	{
	    cc += 64;
	    init_colors(cc, thecol);
	}
	else if (ob == cs->cancel)
	    ready = 1;
	else
	    for (i = 0; i < 64; i++)
		if (ob == cs->col[i])
		{
		    ready = 1;
		    thecol = cc + i;
		}
    }
    fl_hide_form(cs->colorform);
    fl_activate_all_forms();
    flrectboundcolor = s;
    return thecol;
}