File: sp_dial.c

package info (click to toggle)
libforms1 1.0-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,648 kB
  • ctags: 14,351
  • sloc: ansic: 90,441; makefile: 9,902; sh: 8
file content (249 lines) | stat: -rw-r--r-- 6,356 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
/*
 *
 * This file is part of XForms.
 *
 * 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: sp_dial.c,v 1.0 2002/05/08 05:27:39 zhao Release $
 *
 *.
 *  This file is part of XForms package
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *.
 *
 *  Settting dial class specific attributes. We hang the spec
 *  structure on ob->u_vdata. The real spec ob->spec is affected
 *  by testing and can't be used.
 *
 */

#include "forms.h"
#include "fd_main.h"
#include "fd_spec.h"
#include "pdial.h"
#include "spec/dial_spec.h"

extern FD_dialattrib *create_form_dialattrib(void);

static FD_dialattrib *dial_attrib;
static SuperSPEC *dial_spec;
static void show_spec(SuperSPEC *);

#define VN(a)  {a,#a}

static VN_pair dial_dir[] =
{
    VN(FL_DIAL_CW),
    VN(FL_DIAL_CCW),
    VN(-1)
};

int
get_direction_value(const char *s)
{
    return get_vn_val(dial_dir, s);
}


void *
get_dial_spec_fdform(void)
{
    if (!dial_attrib)
    {
	dial_attrib = create_form_dialattrib();
	fl_addto_choice(dial_attrib->dir, dial_dir[0].name);
	fl_addto_choice(dial_attrib->dir, dial_dir[1].name);
	fl_addto_choice(dial_attrib->returnsetting, get_how_return_str());
    }

    return dial_attrib;
}


void
dial_spec_restore(FL_OBJECT * ob, long data)
{
    FL_OBJECT *edited = dial_attrib->vdata;

    superspec_to_spec(edited);
    show_spec(get_superspec(edited));
    redraw_the_form(0);
}


static void
show_spec(SuperSPEC * spec)
{
    set_finput_value(dial_attrib->minval, spec->min, -1);
    set_finput_value(dial_attrib->maxval, spec->max, -1);
    set_finput_value(dial_attrib->initialval, spec->val, -1);
    set_finput_value(dial_attrib->thetai, spec->thetai, -1);
    set_finput_value(dial_attrib->thetaf, spec->thetaf, -1);
    set_finput_value(dial_attrib->step, spec->step, -1);

    fl_set_choice_text(dial_attrib->dir, get_vn_name(dial_dir, spec->direction));
    fl_set_choice_text(dial_attrib->returnsetting,
		       get_how_return_str_name(spec->how_return));
}

int
set_dial_attrib(FL_OBJECT * ob)
{
    dial_attrib->vdata = ob;
    dial_spec = get_superspec(ob);
    show_spec(dial_spec);
    return 0;
}

void
emit_dial_code(FILE * fp, FL_OBJECT * ob)
{
    FL_OBJECT *defobj;
    SuperSPEC *sp, *defspec;

    if (ob->objclass != FL_DIAL)
	return;

    /* create a default object */
    defobj = fl_create_dial(ob->type, 0, 0, 0, 0, "");

    defspec = get_superspec(defobj);
    sp = get_superspec(ob);

    if (sp->min != defspec->min || sp->max != defspec->max)
	fprintf(fp, "    fl_set_dial_bounds(obj, %g, %g);\n", sp->min, sp->max);

    if (sp->thetai != defspec->thetai || sp->thetaf != defspec->thetaf)
	fprintf(fp, "    fl_set_dial_angles(obj, %g, %g);\n",
		sp->thetai, sp->thetaf);

    if (sp->val != defspec->val)
	fprintf(fp, "    fl_set_dial_value(obj, %g);\n", sp->val);

    if (sp->step != defspec->step)
	fprintf(fp, "    fl_set_dial_step(obj, %g);\n", sp->step);

    if (sp->direction != defspec->direction)
	fprintf(fp, "    fl_set_dial_direction(obj, %s);\n",
		get_vn_name(dial_dir, sp->direction));

    if (sp->how_return != defspec->how_return)
	fprintf(fp, "    fl_set_dial_return(obj, %s);\n",
		get_how_return_name(sp->how_return));

    fl_free_object(defobj);
}

void
save_dial_attrib(FILE * fp, FL_OBJECT * ob)
{
    FL_OBJECT *defobj;
    SuperSPEC *defspec, *spec;

    if (ob->objclass != FL_DIAL)
	return;

    /* create a default object */
    defobj = fl_create_dial(ob->type, 0, 0, 0, 0, "");

    defspec = get_superspec(defobj);
    spec = get_superspec(ob);

    if (spec->min != defspec->min || spec->max != defspec->max)
	fprintf(fp, "  bounds: %g %g\n", spec->min, spec->max);
    if (spec->thetai != defspec->thetai || spec->thetaf != defspec->thetaf)
	fprintf(fp, "  angles: %g %g\n", spec->thetai, spec->thetaf);
    if (spec->val != defspec->val)
	fprintf(fp, "  value: %g\n", spec->val);
    if (spec->step != defspec->step)
	fprintf(fp, "  step: %g\n", spec->step);
    if (spec->direction != defspec->direction)
	fprintf(fp, "  dir: %s\n", get_vn_name(dial_dir, spec->direction));
    if (spec->how_return != defspec->how_return)
	fprintf(fp, "  return: %s\n", get_how_return_name(spec->how_return));

    fl_free_object(defobj);
}


void
dial_minmax_change(FL_OBJECT * ob, long data)
{
    double min = get_finput_value(dial_attrib->minval, -1);
    double max = get_finput_value(dial_attrib->maxval, -1);

    fl_set_dial_bounds(dial_attrib->vdata, min, max);
    if (auto_apply)
	redraw_the_form(0);
}

void
dial_thetachange_cb(FL_OBJECT * ob, long data)
{
    double t1 = get_finput_value(dial_attrib->thetai, -1);
    double t2 = get_finput_value(dial_attrib->thetaf, -1);

    fl_set_dial_angles(dial_attrib->vdata, t1, t2);
    if (auto_apply)
	redraw_the_form(0);
}

void
dial_stepchange_cb(FL_OBJECT * ob, long data)
{
    float s = get_finput_value(dial_attrib->step, -1);
    fl_set_dial_step(dial_attrib->vdata, s);
    if (auto_apply)
	redraw_the_form(0);
}

void
dial_initialvalue_change(FL_OBJECT * ob, long data)
{
    double val = get_finput_value(dial_attrib->initialval, -1);
    fl_set_dial_value(dial_attrib->vdata, val);
    if (auto_apply)
	redraw_the_form(0);
}

/* direction change */
void
dir_cb(FL_OBJECT * ob, long data)
{
    int dir = fl_get_choice(ob) - 1;

    if (dir >= 0)
    {
	fl_set_dial_direction(dial_attrib->vdata, dial_dir[dir].val);
	if (auto_apply)
	    redraw_the_form(0);
    }
}

void
dial_returnsetting_change(FL_OBJECT * ob, long data)
{
    const char *s = fl_get_choice_text(dial_attrib->returnsetting);
    fl_set_dial_return(dial_attrib->vdata,
		       get_how_return_str_value(s));
}

#include "spec/dial_spec.c"