Pushbutton ControlsPushbuttons are only slightly more difficult than static controls. Your pushbutton control needs to keep track of whether it's "pressed" (pushed down) or "unpressed." It does this by implementing two virtual functions, wm_mousedown() and wm_mouseup(), which your main calcall() function needs to call when appropriate. Basically, in wm_mousedown(), you set a boolean variable, which I call the "depressed flag," to true, and in wm_mouseup(), you set it back to false. Then, in your drawing code, if the depressed flag is set, you draw the button "pressed," otherwise, you draw it "unpressed." Next, add an additional condition -say, "only draw the button depressed if the depressed flag is set, AND, the mouse cursor is within my client coordinates, otherwise, set the depressed flag back to false." This will give you buttons that "pop out" if you move your mouse cursor off of them, and is very important for accurately determining when a button is clicked. In normal GUIs, when a button is clicked, it fires off an event to its parent window, which then does whatever the button represents - i.e., clicking the close button will close the window, clicking the save button will save the file, whatever. My GUI considers a button clicked if and only if, inside wm_mouseup(), the depressed flag is set. The only way the depressed flag can still be set inside mouseup() is if the user both pressed and released the mouse button while the pointer was inside the button. This allows users to "bail out" at the last minute by holding the button down and dragging the mouse pointer somewhere outside of the button to cancel the button click, just like in any other GUI system. That's pushbuttons. Now, let's take a peek at text boxes.
|
|