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; }
void GUI_ChangeImage(struct guiImage *image, const char *file, u16 x_off, u16 y_off) { guiObject_t *obj = (guiObject_t *)image; //Use a CRC for comparison because the filename may change without the pointer changing u32 crc = Crc(file, strlen(file)); if (image->file != file || image->crc != crc || image->x_off != x_off || image->y_off != y_off) { image->crc = crc; image->file = file; image->x_off = x_off; image->y_off = y_off; OBJ_SET_TRANSPARENT(obj, LCD_ImageIsTransparent(file)); OBJ_SET_DIRTY(obj, 1); } }
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_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; }
void _GUI_ChangeImage(struct guiImage *image, const char *file, u16 x_off, u16 y_off, u8 replace) { guiObject_t *obj = (guiObject_t *)image; //Use a CRC for comparison because the filename may change without the pointer changing u32 crc = Crc(file, strlen(file)); if (image->file != file || image->crc != crc || image->x_off != x_off || image->y_off != y_off) { if (replace) { // draw background where the old picture was bigger struct guiBox *box = &obj->box; u16 w, h; LCD_ImageDimensions(file, &w, &h); if (h < box->height) GUI_DrawBackground(box->x, box->y + h, box->width, box->height - h); // remove lower left part of old image if (w < box->width) GUI_DrawBackground(box->x + w, box->y, box->width - w, h < box->height ? h : box->height); // remove upper right part of old image box->width = w; box->height = h; } image->crc = crc; image->file = file; image->x_off = x_off; image->y_off = y_off; OBJ_SET_TRANSPARENT(obj, LCD_ImageIsTransparent(file)); OBJ_SET_DIRTY(obj, 1); } }
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; }