Version 1 (modified by 10 months ago) ( diff ) | ,
---|
FORM_ADD_BUTTON2 (825gen2)
Adds a button item to a form.
void FORM_ADD_BUTTON2(formName name, buttonName, CFormRect& rect, const char* pszText, char cShortcut, EVENT_FNC event, uint32 nFlag, const char* pszHelp, int nIDVal = 0, const char* pszBitmap, PALETTE_ITEM* pTrans = NULL);
Parameters
- formName - name of the form, this much match the name of the FORM_INIT
- buttonName - name of the input, this must be unique within this form
- rect - rectangle for button position and size
- pszText - Text to display in button
- cShortcut - Shortcut key to press to activate button
- event - Event to be called when button is activated, may be NULL to not call event
- nFlag - Flags such as FORM_UINT8_SEL to show selection data
- pszHelp - Help text to be displayed at the bottom of screen when field is selected
- nIDVal - optional ID that may be used for return value when button is pressed if event function is not used
- pszBitmap - optional bitmap filename for bitmap to display in button
- pTrans - optional color to designate for bitmap to appear as transparent
Return Value
This function does not return any value
Remarks
FORM_ADD_BUTTON2 is a macro to simplify the creation of buttons on forms. The preprocessor will replace this with two lines of code: The creation of the CFormButton with the specified name and then the call to the Add function of the specified form to add the button.
#define FORM_ADD_BUTTON2(f, name, rect, label, shortcut, func, nFlag, moreargs...) \ CFormButton btn##name((rect),(label),(shortcut),(func),(nFlag), ##moreargs); \ form##f.Add(btn##name)
The FORM_ADD_BUTTON2 macro should not be inserted in a condition. An entire form FORM_INIT .. FORM_HIDE may be in a condition. If any FORM_ADD_BUTTON macros are in conditions the form will then have an invalid pointer for each occurrence. The reason is that the FORM_ADD_BUTTON macro declares a CFormButton item and then adds the item to the specified form. The CFormButton item will go out of scope at the end of the condition. If conditional items are needed the FORM_FLAG_DISABLE may be used to make the item hidden. The CForm::EnableItem function may then be used to conditionally show the item.
Button Styles
- FORM_BUTTON
- FORM_BUTTON_BIG
- FORM_BUTTON_OUTLINE
- FORM_BUTTON_INVERT
- FORM_BUTTON_SHADOW (recommended for 825gen2)
- FORM_BUTTON_OWNERDRAW
FORM_BUTTON_SHADOW is recommended for new 825gen2 apps. This can be combined with FORM_OUTLINE_xLINE_WND (x = number of lines of extra text inside the button: can be from 1 to 15) flag and FORM_SHOW_EVENT flag to create buttons that show settings within the button.
Examples
void MenuScreen(void) { CFormRect rect; FORM_INIT(Menu, EventMenuShow, NULL, NULL, NULL, nFormFlgShowHelp); formMenu.SetFontSet(&formFontSet); FORM_ADD_BUTTON2(Menu, SetDateTime, rect, "Set Date/Time", '1', EventDateTime, FORM_BUTTON_SHADOW); rect += invertBtnAdvanceY; FORM_ADD_BUTTON2(Menu, ViewAccum, rect, "View Accumulators", '2', EventViewAccum, FORM_BUTTON_SHADOW); FORM_SHOW(Menu); FORM_RUN(Menu); FORM_HIDE(Menu); } EVENT(MenuShow) { ClearScreenAndShowTitle(pForm, "Menu Screen"); return 0; } EVENT(SetDateTime) { // Hide the parent form IN_EVENT_HIDE_FORM; DateTimeScreen(); // Show the parent form IN_EVENT_SHOW_FORM; return 0; } EVENT(ViewAccum) { // Hide the parent form IN_EVENT_HIDE_FORM; ViewAccumScreen(); // Show the parent form IN_EVENT_SHOW_FORM; return 0; }
This example is a program fragment showing how to use bitmaps in buttons.
const int ZERO_BTN_X = (FONT_WIDTH * 10); const int ZERO_BTN_Y = (FONT_HEIGHT * 19); const int ZERO_BTN_X2 = ZERO_BTN_X + FONT_WIDTH * 9; const int ZERO_BTN_Y2 = ZERO_BTN_Y + FONT_HEIGHT * 3; const char* const BMP_FILE_ZERO = "/usr/images/zero.bmp"; PALETTE_ITEM trans; trans.red = 128; trans.green = 192; trans.blue = 192; trans.alpha = 0; FORM_ADD_BUTTON2(Main, Zero, ZERO_BTN_X, ZERO_BTN_Y, "Zero", 'Z', EventZero, FORM_BUTTON_INVERT, NULL, 0, ZERO_BTN_X2, ZERO_BTN_Y2, BMP_FILE_ZERO, &trans);