4 puButtonBox::puButtonBox ( int minx, int miny, int maxx, int maxy,
5 char **labels, int one_button ) :
6 puObject ( minx, miny, maxx, maxy )
8 type |= PUCLASS_BUTTONBOX ;
9 one_only = one_button ;
11 button_labels = labels ;
13 for ( num_kids = 0 ; button_labels [ num_kids ] != NULL ; num_kids++ )
14 /* Count number of labels */ ;
18 int puButtonBox::checkKey ( int key, int updown )
20 if ( updown == PU_UP ||
21 ! isReturnDefault() ||
22 ( key != '\r' && key != '\n' ) )
39 int puButtonBox::checkHit ( int button, int updown, int x, int y )
41 if ( ! isHit ( x, y ) ||
42 ( updown != active_mouse_edge &&
43 active_mouse_edge != PU_UP_AND_DOWN ) )
46 int i = num_kids - 1 - (( y - abox.min[1] - PUSTR_BGAP ) * num_kids ) /
47 ( abox.max[1] - abox.min[1] - PUSTR_BGAP - PUSTR_TGAP ) ;
50 if ( i >= num_kids ) i = num_kids - 1 ;
55 setValue ( getValue () ^ ( 1 << i ) ) ;
62 void puButtonBox::draw ( int dx, int dy )
64 if ( !visible ) return ;
66 abox . draw ( dx, dy, style, colour, isReturnDefault() ) ;
68 for ( int i = 0 ; i < num_kids ; i++ )
72 tbox . min [ 0 ] = abox.min [ 0 ] + PUSTR_LGAP + PUSTR_LGAP ;
73 tbox . min [ 1 ] = abox.min [ 1 ] + ((abox.max[1]-abox.min[1]-PUSTR_TGAP-PUSTR_BGAP)/num_kids) * (num_kids-1-i) ;
74 tbox . max [ 0 ] = tbox.min [ 0 ] ;
75 tbox . max [ 1 ] = tbox.min [ 1 ] ;
77 if (( one_only && i == getValue() ) ||
78 ( !one_only && ((1<<i) & getValue() ) != 0 ) )
79 tbox . draw ( dx, dy + PUSTR_BGAP + PUSTR_BGAP, -PUSTYLE_RADIO, colour, FALSE ) ;
81 tbox . draw ( dx, dy + PUSTR_BGAP + PUSTR_BGAP, PUSTYLE_RADIO, colour, FALSE ) ;
83 /* If greyed out then halve the opacity when drawing the label and legend */
86 glColor4fv ( colour [ PUCOL_LEGEND ] ) ;
88 glColor4f ( colour [ PUCOL_LEGEND ][0],
89 colour [ PUCOL_LEGEND ][1],
90 colour [ PUCOL_LEGEND ][2],
91 colour [ PUCOL_LEGEND ][3] / 2.0f ) ; /* 50% more transparent */
93 puDrawString ( legendFont, button_labels[i],
94 dx + tbox.min[0] + PU_RADIO_BUTTON_SIZE + PUSTR_LGAP,
95 dy + tbox.min[1] + puGetStringDescender(legendFont) + PUSTR_BGAP + PUSTR_BGAP) ;
98 draw_label ( dx, dy ) ;