Course list http://www.c-jump.com/bcc/
A set of radio button widgets allows the user to choose only one of the predefined set of options. In FLTK the radio button is implemented by Fl_Round_Button class.
To ensure mutually exclusive operation (only one button is selected at a time), the radio buttons must be arranged in groups (FLTK class Fl_Group). It's possible that initially none of the radio buttons in a group are selected.
In this lab we implement a set of radio buttons and use a new CRadioSelector class to detect user choice when the callback function handles the user interaction with the widget.
The prototype for this project is Lab 4, an empty window:
c255labs\labs\c255_lab04
Make a copy of Lab 4 subfolder, or download and unzip c255_lab04.zip
Rename the new folder as c255_lab12_radio_btn.
Open solution file in Visual Studio and finish the usual steps to rename the project.
Start FLUID program and open project
c255labs\labs\c255_lab12_radio_btn\fluid_project\CFluidWindow.fl
Select Window win_app object in FLUID tree view. Use menu
New/Buttons/Round button
Change properties/C++ class type from Normal to Radio.
Add two more radio buttons (tip: once you add one radio button, you can then copy and paste the rest.)
Name the widgets in Properties/C++
rdo_line rdo_circle rdo_rectangle
Create a group:
Select all three radio buttons in the project tree view by using shift/down-arrow keys.
Hit F7.
Save FLUID project and generate C++ code by
File/Write Code...
Open solution
c255labs\labs\c255_lab12_radio_btn\c255_lab12.sln
in Visual Studio.
Download the new versions of
Compile and test the program.
Open CMainWindow.h in the text editor and examine the code:
It is using a set of enumerated constants to uniquely identify each radio button.
The click_radio_button() member function implements the user selection.
The static callback_radio_button() is the callback function. This function is attached to each radio button on the screen.
The CRadioSelector class remembers
button id, which is one of the enumerated constants
The pointer to the window class CMainWindow *
Both of the data are needed when the callback is called for one of the radio buttons.
Open CMainWindow.cpp in the text editor. Examine the code. Notice that CMainWindow::show() attaches the same callback to each radio button object.
Using Visual Studio debugger, trace calls resulting from a mouse click that selects a radio button. What is the sequence of the invoked functions?
Hint: specify a breakpoint in CMainWindow::callback_radio_button() and use the debugger to step into the calls.
This is a self-learning lab. There are no files to submit. Make sure to complete all required steps to build and test the project on your own home computer.