guiObject_t *GUI_CreateImageOffset(guiImage_t *image, u16 x, u16 y, u16 width, u16 height, u16 x_off, u16 y_off, const char *file, void (*CallBack)(guiObject_t *obj, s8 press_type, const void *data), const void *cb_data) { struct guiObject *obj = (guiObject_t *)image; struct guiBox *box; CLEAR_OBJ(image); box = &obj->box; image->file = file; image->x_off = x_off; image->y_off = y_off; image->callback = CallBack; image->cb_data = cb_data; image->crc = Crc(file, strlen(file)); box->x = x; box->y = y; box->width = width; box->height = height; obj->Type = Image; OBJ_SET_TRANSPARENT(obj, LCD_ImageIsTransparent(file)); OBJ_SET_SELECTABLE(obj, CallBack ? 1 :0); connect_object(obj); return obj; }
guiObject_t *GUI_CreateIcon(guiButton_t *button, u16 x, u16 y, const struct ImageMap *image, void (*CallBack)(struct guiObject *obj, const void *data), const void *cb_data) { struct guiHeader *obj = (guiObject_t *)button; struct guiBox *box; CLEAR_OBJ(button); box = &obj->box; button->image = image; box->x = x; box->y = y; box->width = button->image->width; box->height = button->image->height; obj->Type = Button; //Even though the image cannot be overlapped, the file can change under press and select states //So we need transparency set OBJ_SET_TRANSPARENT(obj, 1); OBJ_SET_SELECTABLE(obj, 1); connect_object(obj); button->strCallback = NULL; button->CallBack = CallBack; button->cb_data = cb_data; button->flags |= FLAG_ENABLE; return obj; }
guiObject_t *GUI_CreateButton(guiButton_t *button, u16 x, u16 y, enum ButtonType type, const char *(*strCallback)(struct guiObject *, const void *), u16 fontColor, void (*CallBack)(struct guiObject *obj, const void *data), const void *cb_data) { struct guiHeader *obj = (guiObject_t *)button; struct guiBox *box; CLEAR_OBJ(button); box = &obj->box; button->image = _button_image_map(type); box->x = x; box->y = y; box->width = button->image->width; box->height = button->image->height; obj->Type = Button; //Even though the image cannot be overlapped, the file can change under press and select states //So we need transparency set OBJ_SET_TRANSPARENT(obj, 1); OBJ_SET_SELECTABLE(obj, 1); connect_object(obj); // bug fix: must set a default font, otherwise language other than English might not be displayed in some dialogs button->desc.font = DEFAULT_FONT.font; button->fontColor = fontColor; button->strCallback = strCallback; button->CallBack = CallBack; button->cb_data = cb_data; button->flags |= FLAG_ENABLE; return obj; }
guiObject_t *GUI_CreateKeyboard(guiKeyboard_t *keyboard, enum KeyboardType type, char *text, s32 max_size, void (*CallBack)(struct guiObject *obj, void *data), void *cb_data) { struct guiObject *obj = (guiObject_t *)keyboard; CLEAR_OBJ(keyboard); obj->Type = Keyboard; OBJ_SET_MODAL(obj, 1); connect_object(obj); keyboard->type = type; keyboard->text = text; keyboard->flags = FLAG_BUTTON; keyboard->max_size = max_size; keyboard->last_row = 0; keyboard->last_col = 0; keyboard->lastchar = array[keyboard->type][0][0]; BUTTON_RegisterCallback(&keyboard->action, CHAN_ButtonMask(BUT_LEFT) | CHAN_ButtonMask(BUT_RIGHT) | CHAN_ButtonMask(BUT_UP) | CHAN_ButtonMask(BUT_DOWN) | CHAN_ButtonMask(BUT_ENTER) | CHAN_ButtonMask(BUT_EXIT), BUTTON_PRESS | BUTTON_LONGPRESS | BUTTON_PRIORITY, press_cb, obj); keyboard->CallBack = CallBack; keyboard->cb_data = cb_data; return obj; }
guiObject_t *GUI_CreateScrollable(guiScrollable_t *scrollable, u16 x, u16 y, u16 width, u16 height, u8 row_height, u8 item_count, int (*row_cb)(int absrow, int relrow, int x, void *data), guiObject_t * (*getobj_cb)(int relrow, int col, void *data), int (*size_cb)(int absrow, void *data), void *data) { struct guiObject *obj = (guiObject_t *)scrollable; struct guiBox *box = &obj->box; CLEAR_OBJ(scrollable); scrollable->row_cb = row_cb; scrollable->getobj_cb = getobj_cb; scrollable->row_height = row_height; scrollable->item_count = item_count; scrollable->max_visible_rows = (height + row_height / 2) / row_height; if (scrollable->max_visible_rows > item_count) scrollable->max_visible_rows = item_count; scrollable->size_cb = size_cb; scrollable->cb_data = data; scrollable->head = NULL; scrollable->cur_row = 0; box->x = x; box->y = y; box->width = width - ARROW_WIDTH; box->height = height; obj->Type = Scrollable; OBJ_SET_TRANSPARENT(obj, 0); OBJ_SET_SELECTABLE(obj, 1); //Scrollables aren't really selectable connect_object(obj); GUI_CreateScrollbar(&scrollable->scrollbar, x + width - ARROW_WIDTH, y, height, item_count, obj, scroll_cb, scrollable); create_scrollable_objs(scrollable, 0); //force selection to be current object-if there are no selectable contents if (! has_selectable(scrollable)) objSELECTED = obj; return obj; }
guiObject_t *GUI_CreateTextSelect(guiTextSelect_t *select, u16 x, u16 y, enum TextSelectType type, void (*select_cb)(guiObject_t *obj, void *data), const char *(*value_cb)(guiObject_t *obj, int value, void *data), void *cb_data) { struct guiObject *obj = (guiObject_t *)select; struct guiBox *box; CLEAR_OBJ(select); box = &obj->box; select->type = type; GUI_TextSelectEnablePress(select, select_cb ? 1 : 0); // only used for RTC config in Devo12 #if HAS_RTC if (type == TEXTSELECT_VERT_64) { box->height = select->button->height + 2 * ARROW_HEIGHT; box->width = select->button->width; } else #endif { box->height = select->button->height; box->width = select->button->width + 2 * ARROW_WIDTH; } box->x = x; box->y = y; obj->Type = TextSelect; //Even though the image cannot be overlapped, the file can change under press and select states //So we need transparency set OBJ_SET_TRANSPARENT(obj, 1); OBJ_SET_SELECTABLE(obj, 1); connect_object(obj); select->state = 0; select->ValueCB = value_cb; select->SelectCB = select_cb; select->InputValueCB = NULL; select->cb_data = cb_data; select->enable |= 0x01; return obj; }
guiObject_t *GUI_CreateTextSelectPlate(guiTextSelect_t *select, u16 x, u16 y, u16 width, u16 height, const struct LabelDesc *desc, void (*select_cb)(guiObject_t *obj, void *data), const char *(*value_cb)(guiObject_t *obj, int value, void *data), void *cb_data) { struct guiObject *obj = (guiObject_t *)select; struct guiBox *box; CLEAR_OBJ(select); box = &obj->box; select->type = TEXTSELECT_DEVO10; box->height = height; box->width = width; box->x = x; box->y = y; obj->Type = TextSelect; OBJ_SET_SELECTABLE(obj, 1); connect_object(obj); select->button = NULL; select->state = 0; select->desc = *desc; select->ValueCB = value_cb; select->SelectCB = select_cb; select->cb_data = cb_data; select->enable |= 0x01; select->InputValueCB = NULL; GUI_TextSelectEnablePress(select, select_cb ? 1 : 0); #if LCD_DEPTH == 1 int underline = select->desc.style == LABEL_UNDERLINE; #else const int underline = 0; #endif if ((width == 0 || height == 0) && ! underline) select->desc.style = LABEL_NO_BOX; return obj; }
guiObject_t *GUI_CreateXYGraph(guiXYGraph_t *graph, u16 x, u16 y, u16 width, u16 height, s16 min_x, s16 min_y, s16 max_x, s16 max_y, u16 gridx, u16 gridy, s32 (*Callback)(s32 xval, void *data), u8 (*point_cb)(s16 *x, s16 *y, u8 pos, void *data), u8 (*touch_cb)(s16 x, s16 y, void *data), void *cb_data) { struct guiObject *obj = (guiObject_t *)graph; struct guiBox *box; CLEAR_OBJ(graph); box = &obj->box; box->x = x; box->y = y; box->width = width; box->height = height; obj->Type = XYGraph; OBJ_SET_TRANSPARENT(obj, 0); connect_object(obj); graph->min_x = min_x; graph->min_y = min_y; graph->max_x = max_x; graph->max_y = max_y; graph->grid_x = gridx; graph->grid_y = gridy; graph->CallBack = Callback; graph->point_cb = point_cb; graph->touch_cb = touch_cb; graph->cb_data = cb_data; _GUI_CreateMappedItem_Helper(obj); return obj; }
// PRECONDITIONS: none // POSTCONDITION: The circuit of the room has been loaded from `filename' void GameEngine::load_circuit(string filename) { // Used for to make insertion easy, via the >> operator ifstream ifs; // The type of the current object being loaded from the file string current_type = ""; // Switches must specify their initial output value int output_value; // Dummy variables to pass by reference to drawing prep function int w = 0, h = 0; // Open the file for loading ifs.open(filename.c_str()); // Check that the file opened properly, exit on failure if(!ifs) { cerr << "Fatal error loading room file " << filename << endl; cerr << "Could not open file" << endl; exit(EXIT_FAILURE); } // Load circuit object while(ifs >> current_type) { if(current_type == "SWITCH") { // Import the output value ifs >> output_value; // Add to this room's list of switches _switches[_num_switches++] = (CircuitObject(current_type)); _switches[num_switches()-1].set_width(SWITCH_WIDTH); _switches[num_switches()-1].set_height(SWITCH_HEIGHT); _switches[num_switches()-1].set_output_value(output_value); // Connect the object to the rest of the circuit connect_object(_switches[num_switches()-1]); } else if(current_type == "BUTTON")
guiObject_t *GUI_CreateDialog(guiDialog_t *dialog, u16 x, u16 y, u16 width, u16 height, const char *title, const char *(*string_cb)(guiObject_t *obj, void *data), void (*CallBack)(u8 state, void *data), enum DialogType dgType, void *data) { struct guiHeader *obj = (guiObject_t *)dialog; struct guiBox *box ; CLEAR_OBJ(dialog); box = &obj->box; box->x = x; box->y = y; box->width = width; box->height = height; obj->Type = Dialog; OBJ_SET_TRANSPARENT(obj, 0); OBJ_SET_MODAL(obj, 1); connect_object(obj); dialog->string_cb = string_cb; dialog->title = title; dialog->CallBack = *CallBack; dialog->cbData = data; dialog->txtbox.x = x + 10; dialog->txtbox.y = 0; dialog->txtbox.width = 0; dialog->txtbox.height = 0; struct guiObject *but = NULL; int button_width = GUI_ButtonWidth(DIALOG_BUTTON); int button_height = GUI_ButtonHeight(DIALOG_BUTTON); switch (dgType) { case dtOk: case dtCancel: { but = GUI_CreateButton(&dialog->but1, x + (width - button_width) / 2, y + height - button_height - 1, DIALOG_BUTTON, dgType == dtOk ? dlgbut_strok_cb : dlgbut_strcancel_cb, 0x0000, dgType == dtOk ? dlgbut_pressok_cb : dlgbut_presscancel_cb, obj); } break; case dtOkCancel: { but = GUI_CreateButton(&dialog->but1, x + (width - button_width - button_width) / 2, y + height - button_height - 1, DIALOG_BUTTON, dlgbut_strok_cb, 0x0000, dlgbut_pressok_cb, obj); but = GUI_CreateButton(&dialog->but2, x + width/2, y + height - button_height - 1, DIALOG_BUTTON, dlgbut_strcancel_cb, 0x0000, dlgbut_presscancel_cb, obj); } break; case dtNone: break; } objDIALOG = obj; GUI_HandleModalButtons(1); objSELECTED = but; //bug fix: using objSELECTED for dialog is not safe in devo10 objModalButton = but; return obj; }