hc_menu_entry* hc_menu::execute(void) { if(active) { hc_menu_entry* tmp = active->execute(); if(tmp) { if(tmp->value == -1) { active = nullptr; } else { return tmp; } } else { return nullptr; } } mouse->get_state(&mouse_x, &mouse_y); for(int i = 0; i < counter; i++) { if(is_in_rect(mouse_x, mouse_y, x, y + i * 64, max_width + 32, 48)) { if(mouse->get_release() == 1) { active = next[i]; if(entries[i]->type == HC_MENU_ENTRY_TOOGLE) { entries[i]->value++; entries[i]->value %= explode(entries[i]->text_value, '|').size(); } return entries[i]; } } } return nullptr; }
void hc_menu::draw(void) { if(active) { active->draw(); return; } hc_box *tmp = nullptr; for(int i = 0; i < counter; i++) { if(is_in_rect(mouse_x, mouse_y, x, y + i * 64, max_width + 32, 48)) { tmp = box_active; if(mouse->get_state() == 1) { if(entries[i]->type == HC_MENU_ENTRY_SLIDER) { entries[i]->value = mouse_x - (x + entries[i]->width - 255 + 16); if(entries[i]->value > 255) { entries[i]->value = 255; } else if(entries[i]->value < 0) { entries[i]->value = 0; } } } } else { tmp = box_normal; } tmp->draw(x, y + i * 64, max_width + 32, 48); string label = entries[i]->label; if(entries[i]->type == HC_MENU_ENTRY_TEXT) { label += ": " + entries[i]->text_value; } else if(entries[i]->type == HC_MENU_ENTRY_TOOGLE) { vector<string> toogle = explode(entries[i]->text_value, '|'); label += ": " + toogle[entries[i]->value]; } else if(entries[i]->type == HC_MENU_ENTRY_PASSWORD) { label += ": "; for(uint8_t j = 0; j < entries[i]->text_value.length(); j++) // hide the password { label += "*"; } } else if(entries[i]->type == HC_MENU_ENTRY_SLIDER) { hlineRGBA(renderer, x + entries[i]->width - 255 + 16, x + entries[i]->width + 16, y + 24 + 64 * i, 0, 0, 0, 255); vlineRGBA(renderer, x + entries[i]->width - 255 + 16 + entries[i]->value, y + 24 + 64 * i - 5, y + 24 + 64 * i + 5, 0, 0, 0, 255); } text->print(x + width() / 2 - entries[i]->width / 2, y + 16 + 64 * i, 0, 0, label.c_str()); } }
void fgui_draw_point(uint16_t x, uint16_t y, uint32_t color, struct fgui_rect *clip) { if (clip == NULL || is_in_rect(x, y, clip)) { fgui_set_pixel(x, y, color); } }