1 /*
2  *  This file is part of the XForms library package.
3  *
4  *  XForms is free software; you can redistribute it and/or modify it
5  *  under the terms of the GNU Lesser General Public License as
6  *  published by the Free Software Foundation; either version 2.1, or
7  *  (at your option) any later version.
8  *
9  *  XForms is distributed in the hope that it will be useful, but
10  *  WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with XForms.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 /**
20  * \file roundbut.c
21  *
22  *  This file is part of the XForms library package.
23  *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
24  *  All rights reserved.
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #include <sys/types.h>
32 #include "include/forms.h"
33 #include "flinternal.h"
34 
35 
36 /***************************************
37  * Draws a round button
38  ***************************************/
39 
40 static void
draw_roundbutton(FL_OBJECT * ob)41 draw_roundbutton( FL_OBJECT * ob )
42 {
43     int c1;
44     FL_Coord xx,
45              yy,
46              rr;
47     FL_BUTTON_STRUCT *sp = ob->spec;
48 
49     if ( sp->event == FL_ENTER || sp->event == FL_LEAVE )
50         return;
51 
52     c1 = ob->belowmouse ? FL_ROUNDBUTTON_MCOL : FL_ROUNDBUTTON_TOPCOL;
53 
54     fl_draw_box( ob->boxtype, ob->x, ob->y, ob->w, ob->h, c1, ob->bw );
55 
56     rr = 0.3 * FL_min( ob->w, ob->h ) + 0.5;
57     xx = ob->x + rr + 4.1;
58     yy = ob->y + 0.5 * ob->h;
59 
60     fl_circf( xx, yy, rr, ob->col1 );
61     fl_circ( xx, yy, rr, FL_BLACK );
62 
63     if ( sp->val )
64     {
65         fl_circf( xx, yy, ( int ) ( 0.8 * rr ), ob->col2 );
66         fl_circ(  xx, yy, ( int ) ( 0.8 * rr ), FL_BLACK );
67     }
68 
69     if ( fl_is_center_lalign( ob->align ) )
70         fl_draw_text( FL_ALIGN_LEFT, xx + rr + 1, ob->y, 0, ob->h,
71                       ob->lcol, ob->lstyle, ob->lsize, ob->label );
72     else
73         fl_draw_object_label_outside( ob );
74 
75     if ( ob->type == FL_RETURN_BUTTON )
76         fl_draw_text( 0,
77                       ob->x + ob->w - 0.8 * ob->h, ob->y + 0.2 * ob->h,
78                       0.6 * ob->h, 0.6 * ob->h, ob->lcol, 0, 0,
79                       "@returnarrow" );
80 }
81 
82 
83 /***************************************
84  * Creates an object
85  ***************************************/
86 
87 FL_OBJECT *
fl_create_roundbutton(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)88 fl_create_roundbutton( int          type,
89                        FL_Coord     x,
90                        FL_Coord     y,
91                        FL_Coord     w,
92                        FL_Coord     h,
93                        const char * label )
94 {
95     FL_OBJECT *ob;
96 
97     fl_add_button_class( FL_ROUNDBUTTON, draw_roundbutton, 0 );
98     ob = fl_create_generic_button( FL_ROUNDBUTTON, type, x, y, w, h, label );
99 
100     ob->boxtype = FL_ROUNDBUTTON_BOXTYPE;
101     ob->col1    = FL_ROUNDBUTTON_COL1;
102     ob->col2    = FL_ROUNDBUTTON_COL2;
103     ob->align   = FL_ROUNDBUTTON_ALIGN;
104     ob->lcol    = FL_ROUNDBUTTON_LCOL;
105 
106     return ob;
107 }
108 
109 
110 /***************************************
111  * Adds an object
112  ***************************************/
113 
114 FL_OBJECT *
fl_add_roundbutton(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)115 fl_add_roundbutton( int          type,
116                     FL_Coord     x,
117                     FL_Coord     y,
118                     FL_Coord     w,
119                     FL_Coord     h,
120                     const char * label )
121 {
122     FL_OBJECT *ob = fl_create_roundbutton( type, x, y, w, h, label );
123 
124     fl_add_object( fl_current_form, ob );
125     return ob;
126 }
127 
128 
129 /*
130  * Local variables:
131  * tab-width: 4
132  * indent-tabs-mode: nil
133  * End:
134  */
135