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