FLTK Summer Course - Part VI - Sixth Impact - Exercises

Preview:

Citation preview

1 #include <iostream>2 #include <FL/Fl.H>3 #include <FL/Fl_Window.H>4 #include <FL/Fl_Button.H>5 6 /*Declaração de namespace para uso das funções de i ostream*/7 using namespace std ;8 9 /**

10 * Classe para verificação de eventos em um botão . ..11 **/12 class MyButton : public Fl_Button13 {14 /*Variável estática para contagem de eventos*/15 static int count ;16 17 public :18 19 /*Construtor*/20 MyButton ( int x , int y , int w , int h , const char * l =0): Fl_Button ( x, y, w, h, l ){};21 22 /*Sobreposição do método manipulador de eventos*/23 int handle ( int event )24 {25 int retorno = Fl_Button :: handle ( event );26 cout << endl << count ++ << " ******** button " << this -> label () << " receives " ;27 28 switch ( event )29 {30 case FL_PUSH:31 cout << "push" << " event and returns:" << retorno << endl ;32 break ;33 34 case FL_RELEASE:35 cout << "release" << " event and returns:" << retorno << endl ;36 break ;37 38 case FL_ENTER:39 color ( FL_CYAN);40 cout << "enter" << " event and returns:" << retorno << endl ;41 redraw ();42 break ;43 44 case FL_LEAVE :45 color ( FL_BACKGROUND_COLOR);46 cout << "leave" << " event and returns:" << retorno << endl ;47 redraw ();48 break ;49 50 case FL_DRAG:51 cout << "drag" << " event and returns:" << retorno << endl ;52 break ;53 54 case FL_FOCUS:55 cout << "focus" << " event and returns:" << retorno << endl ;56 break ;57 58 case FL_UNFOCUS:59 cout << "unfocus" << " event and returns:" << retorno << endl ;60 break ;61 62 case FL_KEYDOWN:63 cout << "keydown" << " event and returns:" << retorno << endl ;64 break ;65 66 case FL_KEYUP:67 if ( Fl :: event_key () == shortcut () )68 {69 box ( FL_UP_BOX);70 redraw ();71 retorno = 1; //return handled so keyup event stops72 } //being sent to ALL other buttons unecessarily

73 74 cout << "keyup" << " event and returns:" << retorno << endl ;75 break ;76 77 case FL_CLOSE:78 cout << "close" << " event and returns:" << retorno << endl ;79 break ;80 81 case FL_MOVE:82 cout << "move" << " event and returns:" << retorno << endl ;83 break ;84 85 case FL_SHORTCUT:86 if ( Fl :: event_key () == shortcut () )87 {88 box ( FL_DOWN_BOX);89 redraw ();90 }91 cout << "shortcut" << " event and returns:" << retorno << endl ;92 break ;93 94 case FL_DEACTIVATE :95 cout << "deactivate" << " event and returns:" << retorno << endl ;96 break ;97 98 case FL_ACTIVATE :99 cout << "activate" << " event and returns:" << retorno << endl ;

100 break ;101 102 case FL_HIDE :103 cout << "hide" << " event and returns:" << retorno << endl ;104 break ;105 106 case FL_SHOW:107 cout << "show" << " event and returns:" << retorno << endl ;108 break ;109 110 case FL_PASTE :111 cout << "paste" << " event and returns:" << retorno << endl ;112 break ;113 114 case FL_SELECTIONCLEAR:115 cout << "selectionclear" << " event and returns:" << retorno << endl ;116 break ;117 118 case FL_MOUSEWHEEL:119 cout << "mousewheel" << " event and returns:" << retorno << endl ;120 break ;121 122 case FL_NO_EVENT:123 cout << "no event" << " and returns:" << retorno << endl ;124 break ;125 }126 127 /*Retorno do método ...*/128 return ( retorno );129 }130 };131 132 /**133 * Atribuição inicial da variável estática ...134 */135 int MyButton :: count =0;136 137 /**138 * Funções que respondem aos callbacks139 */140 void but_a_cb ( Fl_Widget * w , void * v )141 {142 cout << endl << "Button A callback!" << endl ;143 }144

145 void but_b_cb ( Fl_Widget * w , void * v )146 {147 cout << endl << "Button B callback!" << endl ;148 }149 150 void but_c_cb ( Fl_Widget * w , void * v )151 {152 cout << endl << "Button C callback!" << endl ;153 }154 155 /**156 * Função principal do programa.157 */158 int main ( int argc , char * argv [])159 {160 Fl_Window win ( 120 , 150 );161 win . begin ();162 MyButton but_a ( 10, 10, 100 , 25, "A" );163 but_a . shortcut ( 'a' );164 but_a . callback ( but_a_cb );165 MyButton but_b ( 10, 50, 100 , 25, "B" );166 but_b . shortcut ( 'b' );167 but_b . callback ( but_b_cb );168 MyButton but_c ( 10, 90, 100 , 25, "C" );169 but_c . shortcut ( 'c' );170 but_c . callback ( but_c_cb );171 win . end ();172 win . show();173 return ( Fl :: run ());174 }175

Recommended