]> git.mxchange.org Git - flightgear.git/blob - PUI/puButton.cxx
612d09cbaebf0ed900c38e519153a897ed01ea9e
[flightgear.git] / PUI / puButton.cxx
1
2 #include "puLocal.h"
3
4 void puButton::draw ( int dx, int dy )
5 {
6   if ( !visible ) return ;
7
8   /* If button is pushed or highlighted - use inverse style for button itself */
9
10   abox . draw ( dx, dy, ( getValue() ^ highlighted ) ? -style : style, colour,
11                                             isReturnDefault() ) ;
12
13   /* If greyed out then halve the opacity when drawing the label and legend */
14
15   if ( active )
16     glColor4fv ( colour [ PUCOL_LEGEND ] ) ;
17   else
18     glColor4f ( colour [ PUCOL_LEGEND ][0],
19                 colour [ PUCOL_LEGEND ][1],
20                 colour [ PUCOL_LEGEND ][2],
21                 colour [ PUCOL_LEGEND ][3] / 2.0f ) ; /* 50% more transparent */
22
23   int xx = ( abox.max[0] - abox.min[0] - puGetStringWidth(legendFont,legend) ) / 2 ;
24   int yy = ( abox.max[1] - abox.min[1] - puGetStringHeight(legendFont) ) / 2 ;
25
26   puDrawString ( legendFont, legend,
27                   dx + abox.min[0] + xx,
28                   dy + abox.min[1] + yy ) ;
29
30   draw_label ( dx, dy ) ;
31 }
32
33
34 void puButton::doHit ( int button, int updown, int, int )
35 {
36   if ( button == PU_LEFT_BUTTON )
37   {
38     if ( updown == active_mouse_edge || active_mouse_edge == PU_UP_AND_DOWN )
39     {
40       lowlight () ;
41       setValue ( (int) ! getValue () ) ;
42       invokeCallback () ;
43     }
44     else
45       highlight () ;
46   }
47   else
48     lowlight () ;
49 }
50