| 104 | */ |
| 105 | public: |
| 106 | win( |
| 107 | ) : // All widgets take their parent window as an argument to their constructor. |
| 108 | c(*this), |
| 109 | b(*this), |
| 110 | cb(*this,rectangle(100,100,200,200),0,0,255), // the color_box will be blue and 101 pixels wide and tall |
| 111 | mbar(*this) |
| 112 | { |
| 113 | // tell our button to put itself at the position (10,60). |
| 114 | b.set_pos(10,60); |
| 115 | b.set_name("button"); |
| 116 | |
| 117 | // let's put the label 5 pixels below the button |
| 118 | c.set_pos(b.left(),b.bottom()+5); |
| 119 | |
| 120 | |
| 121 | // set which function should get called when the button gets clicked. In this case we want |
| 122 | // the on_button_clicked member to be called on *this. |
| 123 | b.set_click_handler(*this,&win::on_button_clicked); |
| 124 | // Alternatively, if you have a compiler which supports the lambda functions from the |
| 125 | // new C++ standard then you can use a lambda function instead of telling the click |
| 126 | // handler to call one of the member functions. So for example, you could do this |
| 127 | // instead (uncomment the code if you have C++0x support): |
| 128 | /* |
| 129 | b.set_click_handler([&](){ |
| 130 | ++counter; |
| 131 | ostringstream sout; |
| 132 | sout << "Counter: " << counter; |
| 133 | c.set_text(sout.str()); |
| 134 | }); |
| 135 | */ |
| 136 | // In general, all the functions which register events can take either member |
| 137 | // functions or lambda functions. |
| 138 | |
| 139 | |
| 140 | // Let's also make a simple menu bar. |
| 141 | // First we say how many menus we want in our menu bar. In this example we only want 1. |
| 142 | mbar.set_number_of_menus(1); |
| 143 | // Now we set the name of our menu. The 'M' means that the M in Menu will be underlined |
| 144 | // and the user will be able to select it by hitting alt+M |
| 145 | mbar.set_menu_name(0,"Menu",'M'); |
| 146 | |
| 147 | // Now we add some items to the menu. Note that items in a menu are listed in the |
| 148 | // order in which they were added. |
| 149 | |
| 150 | // First let's make a menu item that does the same thing as our button does when it is clicked. |
| 151 | // Again, the 'C' means the C in Click is underlined in the menu. |
| 152 | mbar.menu(0).add_menu_item(menu_item_text("Click Button!",*this,&win::on_button_clicked,'C')); |
| 153 | // let's add a separator (i.e. a horizontal separating line) to the menu |
| 154 | mbar.menu(0).add_menu_item(menu_item_separator()); |
| 155 | // Now let's make a menu item that calls show_about when the user selects it. |
| 156 | mbar.menu(0).add_menu_item(menu_item_text("About",*this,&win::show_about,'A')); |
| 157 | |
| 158 | |
| 159 | // set the size of this window |
| 160 | set_size(430,380); |
| 161 | |
| 162 | counter = 0; |
| 163 |
nothing calls this directly
no test coverage detected