int Tabs::calcTabWidth(Tab* tab) { int border = 4*jguiscale(); #ifdef CLOSE_BUTTON_IN_EACH_TAB SkinTheme* theme = static_cast<SkinTheme*>(this->theme); int close_icon_w = theme->get_part(PART_WINDOW_CLOSE_BUTTON_NORMAL)->w; return (border + text_length(getFont(), tab->text.c_str()) + border + close_icon_w + border); #else return (border + text_length(getFont(), tab->text.c_str()) + border); #endif }
void StatusBar::onResize(ResizeEvent& ev) { setBoundsQuietly(ev.getBounds()); Rect rc = ev.getBounds(); rc.x = rc.x2() - m_notificationsBox->getPreferredSize().w; rc.w = m_notificationsBox->getPreferredSize().w; m_notificationsBox->setBounds(rc); rc = ev.getBounds(); rc.w -= rc.w/4 + 4*jguiscale(); m_commandsBox->setBounds(rc); }
// Refresh the UI display, font, etc. void gui_setup_screen(bool reload_font) { bool regen = false; bool reinit = false; main_display->setScale(screen_scaling); ui::set_display(main_display); // Update guiscale factor int old_guiscale = jguiscale(); CurrentTheme::get()->guiscale = (screen_scaling == 1 && ui::display_w() > 512 && ui::display_h() > 256) ? 2: 1; // If the guiscale have changed if (old_guiscale != jguiscale()) { reload_font = true; regen = true; } if (reload_font) { reload_default_font(); reinit = true; } // Regenerate the theme if (regen) { CurrentTheme::get()->regenerate(); reinit = true; } if (reinit) reinitThemeForAllWidgets(); // Set the configuration save_gui_config(); }
HexColorEntry::HexColorEntry() : Box(JI_HORIZONTAL) , m_label("#") , m_entry(6, "") { addChild(&m_label); addChild(&m_entry); m_entry.EntryChange.connect(&HexColorEntry::onEntryChange, this); initTheme(); setBorder(gfx::Border(2*jguiscale(), 0, 0, 0)); child_spacing = 0; }
void Entry::onPreferredSize(PreferredSizeEvent& ev) { int w = + border_width.l + getFont()->charWidth('w') * MIN(m_maxsize, 6) + 2*jguiscale() + border_width.r; w = MIN(w, ui::display_w()/2); int h = + border_width.t + getFont()->height() + border_width.b; ev.setPreferredSize(w, h); }
void ColorButton::onPaint(PaintEvent& ev) // TODO use "ev.getGraphics()" { struct jrect box, text, icon; jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0); int bg = getBgColor(); if (bg < 0) bg = ji_color_face(); jdraw_rectfill(this->rc, bg); Color color; // When the button is pushed, show the negative if (isSelected()) { color = Color::fromRgb(255-m_color.getRed(), 255-m_color.getGreen(), 255-m_color.getBlue()); } // When the button is not pressed, show the real color else color = this->m_color; draw_color_button (ji_screen, this->getBounds(), true, true, true, true, true, true, true, true, this->m_imgtype, color, this->hasMouseOver(), false); // Draw text std::string str = m_color.toFormalString(this->m_imgtype, false); setTextQuiet(str.c_str()); jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0); int textcolor = makecol(255, 255, 255); if (color.isValid()) textcolor = color_utils::blackandwhite_neg(color.getRed(), color.getGreen(), color.getBlue()); jdraw_text(ji_screen, getFont(), getText(), text.x1, text.y1, textcolor, -1, false, jguiscale()); }
bool Tabs::onProcessMessage(Message* msg) { SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme()); switch (msg->type) { case JM_REQSIZE: msg->reqsize.w = 0; // msg->reqsize.h = 4 + jwidget_get_text_height(widget) + 5; msg->reqsize.h = theme->get_part(PART_TAB_FILLER)->h + theme->get_part(PART_TAB_BOTTOM_NORMAL)->h; return true; case JM_SETPOS: jrect_copy(this->rc, &msg->setpos.rect); setScrollX(m_scrollX); return true; case JM_DRAW: { BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect), jrect_h(&msg->draw.rect)); JRect rect = jwidget_get_rect(this); jrect_displace(rect, -msg->draw.rect.x1, -msg->draw.rect.y1); JRect box = jrect_new(rect->x1-m_scrollX, rect->y1, rect->x1-m_scrollX+2*jguiscale(), rect->y1+theme->get_part(PART_TAB_FILLER)->h); clear_to_color(doublebuffer, theme->get_window_face_color()); theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, box->x2-1, box->y2-1, PART_TAB_FILLER); theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, box->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL); box->x1 = box->x2; // For each tab... TabsListIterator it, end = m_list_of_tabs.end(); for (it = m_list_of_tabs.begin(); it != end; ++it) { Tab* tab = *it; box->x2 = box->x1 + tab->width; int x_delta = 0; int y_delta = 0; // Y-delta for animating tabs (intros and outros) if (m_ani == ANI_ADDING_TAB && m_selected == tab) { y_delta = (box->y2 - box->y1) * (ANI_ADDING_TAB_TICKS - m_ani_t) / ANI_ADDING_TAB_TICKS; } else if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == tab) { x_delta += m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS)); x_delta = MID(0, x_delta, m_removedTab->width); // Draw deleted tab if (m_removedTab) { JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2); drawTab(doublebuffer, box2, m_removedTab, 0, false); jrect_free(box2); } } box->x1 += x_delta; box->x2 += x_delta; drawTab(doublebuffer, box, tab, y_delta, (tab == m_selected)); box->x1 = box->x2; } if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == NULL) { // Draw deleted tab if (m_removedTab) { int x_delta = m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS)); x_delta = MID(0, x_delta, m_removedTab->width); JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2); drawTab(doublebuffer, box2, m_removedTab, 0, false); jrect_free(box2); box->x1 += x_delta; box->x2 = box->x1; } } /* fill the gap to the right-side */ if (box->x1 < rect->x2) { theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, rect->x2-1, box->y2-1, PART_TAB_FILLER); theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, rect->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL); } jrect_free(rect); jrect_free(box); blit(doublebuffer, ji_screen, 0, 0, msg->draw.rect.x1, msg->draw.rect.y1, doublebuffer->w, doublebuffer->h); destroy_bitmap(doublebuffer); return true; } case JM_MOUSEENTER: case JM_MOTION: calculateHot(); return true; case JM_MOUSELEAVE: if (m_hot != NULL) { m_hot = NULL; invalidate(); } return true; case JM_BUTTONPRESSED: if (m_hot != NULL) { if (m_selected != m_hot) { m_selected = m_hot; invalidate(); } if (m_selected && m_delegate) m_delegate->clickTab(this, m_selected->data, msg->mouse.flags); } return true; case JM_WHEEL: { int dx = (jmouse_z(1) - jmouse_z(0)) * jrect_w(this->rc)/6; // setScrollX(m_scrollX+dx); m_begScrollX = m_scrollX; if (m_ani != ANI_SMOOTH_SCROLL) m_endScrollX = m_scrollX + dx; else m_endScrollX += dx; // Limit endScrollX position (to improve animation ending to the correct position) { int max_x = getMaxScrollX(); m_endScrollX = MID(0, m_endScrollX, max_x); } startAni(ANI_SMOOTH_SCROLL); return true; } case JM_TIMER: { switch (m_ani) { case ANI_NONE: // Do nothing break; case ANI_SCROLL: { int dir = (getManager()->getCapture() == m_button_left ? -1: 1); setScrollX(m_scrollX + dir*8*msg->timer.count); break; } case ANI_SMOOTH_SCROLL: { if (m_ani_t == ANI_SMOOTH_SCROLL_TICKS) { stopAni(); setScrollX(m_endScrollX); } else { // Lineal //setScrollX(m_begScrollX + m_endScrollX - m_begScrollX) * m_ani_t / 10); // Exponential setScrollX(m_begScrollX + (m_endScrollX - m_begScrollX) * (1.0-std::exp(-10.0 * m_ani_t / (double)ANI_SMOOTH_SCROLL_TICKS))); } break; } case ANI_ADDING_TAB: { if (m_ani_t == ANI_ADDING_TAB_TICKS) stopAni(); invalidate(); break; } case ANI_REMOVING_TAB: { if (m_ani_t == ANI_REMOVING_TAB_TICKS) stopAni(); invalidate(); break; } } ++m_ani_t; break; } case JM_SIGNAL: if (msg->signal.num == JI_SIGNAL_INIT_THEME) { m_button_left->setBgColor(theme->get_tab_selected_face_color()); m_button_right->setBgColor(theme->get_tab_selected_face_color()); } else if (msg->signal.num == JI_SIGNAL_SET_FONT) { TabsListIterator it, end = m_list_of_tabs.end(); for (it = m_list_of_tabs.begin(); it != end; ++it) { Tab* tab = *it; tab->width = calcTabWidth(tab); } } else if (msg->signal.num == JI_SIGNAL_INIT_THEME) { /* setup the background color */ jwidget_set_bg_color(this, ji_color_face()); } break; } return Widget::onProcessMessage(msg); }
void Alert::processString(char* buf, std::vector<Widget*>& labels, std::vector<Widget*>& buttons) { Box* box1, *box2, *box3, *box4, *box5; Grid* grid; bool title = true; bool label = false; bool separator = false; bool button = false; int align = 0; char *beg; int c, chr; // Process buffer c = 0; beg = buf; for (; ; c++) { if ((!buf[c]) || ((buf[c] == buf[c+1]) && ((buf[c] == '<') || (buf[c] == '=') || (buf[c] == '>') || (buf[c] == '-') || (buf[c] == '|')))) { if (title || label || separator || button) { chr = buf[c]; buf[c] = 0; if (title) { setText(beg); } else if (label) { Label* label = new Label(beg); label->setAlign(align); labels.push_back(label); } else if (separator) { labels.push_back(new Separator(NULL, JI_HORIZONTAL)); } else if (button) { char button_name[256]; Button* button_widget = new Button(beg); jwidget_set_min_size(button_widget, 60*jguiscale(), 0); buttons.push_back(button_widget); usprintf(button_name, "button-%d", buttons.size()); button_widget->setName(button_name); button_widget->Click.connect(Bind<void>(&Frame::closeWindow, this, button_widget)); } buf[c] = chr; } /* done */ if (!buf[c]) break; /* next widget */ else { title = label = separator = button = false; beg = buf+c+2; align = 0; switch (buf[c]) { case '<': label=true; align=JI_LEFT; break; case '=': label=true; align=JI_CENTER; break; case '>': label=true; align=JI_RIGHT; break; case '-': separator=true; break; case '|': button=true; break; } c++; } } } box1 = new Box(JI_VERTICAL); box2 = new Box(JI_VERTICAL); grid = new Grid(1, false); box3 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS); // To identify by the user box2->setName("labels"); box3->setName("buttons"); // Pseudo separators (only to fill blank space) box4 = new Box(0); box5 = new Box(0); box4->setExpansive(true); box5->setExpansive(true); jwidget_noborders(box4); jwidget_noborders(box5); // Setup parent <-> children relationship addChild(box1); box1->addChild(box4); // Filler box1->addChild(box2); // Labels box1->addChild(box5); // Filler box1->addChild(grid); // Buttons grid->addChildInCell(box3, 1, 1, JI_CENTER | JI_BOTTOM); for (std::vector<Widget*>::iterator it = labels.begin(); it != labels.end(); ++it) box2->addChild(*it); for (std::vector<Widget*>::iterator it = buttons.begin(); it != buttons.end(); ++it) box3->addChild(*it); // Default button is the last one if (!buttons.empty()) buttons[buttons.size()-1]->setFocusMagnet(true); }
void Graphics::drawString(const std::string& str, Color fg, Color bg, bool fillbg, const gfx::Point& pt) { _draw_text(m_bmp, m_currentFont, str.c_str(), m_dx+pt.x, m_dy+pt.y, fg, bg, fillbg, 1 * jguiscale()); }
ColorBar::ColorBar(int align) : Box(align) , m_paletteButton("Edit Palette", JI_BUTTON) , m_paletteView(false) , m_fgColor(Color::fromIndex(15), IMAGE_INDEXED) , m_bgColor(Color::fromIndex(0), IMAGE_INDEXED) , m_lock(false) { setBorder(gfx::Border(1*jguiscale())); child_spacing = 1*jguiscale(); m_paletteView.setBoxSize(6*jguiscale()); m_paletteView.setColumns(4); m_fgColor.setPreferredSize(0, m_fgColor.getPreferredSize().h); m_bgColor.setPreferredSize(0, m_bgColor.getPreferredSize().h); m_scrollableView.attachToView(&m_paletteView); int w = (m_scrollableView.getBorder().getSize().w + m_scrollableView.getViewport()->getBorder().getSize().w + m_paletteView.getPreferredSize().w + getTheme()->scrollbar_size); jwidget_set_min_size(&m_scrollableView, w, 0); m_scrollableView.setExpansive(true); addChild(&m_paletteButton); addChild(&m_scrollableView); addChild(&m_fgColor); addChild(&m_bgColor); this->border_width.l = 2*jguiscale(); this->border_width.t = 2*jguiscale(); this->border_width.r = 2*jguiscale(); this->border_width.b = 2*jguiscale(); this->child_spacing = 2*jguiscale(); m_paletteView.IndexChange.connect(&ColorBar::onPaletteIndexChange, this); m_fgColor.Change.connect(&ColorBar::onFgColorButtonChange, this); m_bgColor.Change.connect(&ColorBar::onBgColorButtonChange, this); // Set background color reading its value from the configuration. setBgColor(get_config_color("ColorBar", "BG", getBgColor())); // Clear the selection of the BG color in the palette. m_paletteView.clearSelection(); // Set foreground color reading its value from the configuration. setFgColor(get_config_color("ColorBar", "FG", getFgColor())); // Change color-bar background color (not ColorBar::setBgColor) Widget::setBgColor(((SkinTheme*)getTheme())->get_tab_selected_face_color()); m_paletteView.setBgColor(((SkinTheme*)getTheme())->get_tab_selected_face_color()); // Change labels foreground color setup_mini_look(&m_paletteButton); m_paletteButton.setFont(((SkinTheme*)getTheme())->getMiniFont()); m_paletteButton.Click.connect(Bind<void>(&ColorBar::onPaletteButtonClick, this)); setDoubleBuffered(true); onColorButtonChange(getFgColor()); }
void StatusBar::onPaint(ui::PaintEvent& ev) { SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme()); ui::Color textColor = theme->getColorById(kStatusBarText); Rect rc = getClientBounds(); Graphics* g = ev.getGraphics(); g->fillRect(getBgColor(), rc); rc.shrink(Border(2, 1, 2, 2)*jguiscale()); int x = rc.x + 4*jguiscale(); // Color if (m_state == SHOW_COLOR) { // Draw eyedropper icon BITMAP* icon = theme->get_toolicon("eyedropper"); if (icon) { g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2); x += icon->w + 4*jguiscale(); } // Draw color draw_color_button(g, gfx::Rect(x, rc.y, 32*jguiscale(), rc.h), true, true, true, true, true, true, true, true, app_get_current_pixel_format(), m_color, false, false); x += (32+4)*jguiscale(); // Draw color description std::string str = m_color.toHumanReadableString(app_get_current_pixel_format(), app::Color::LongHumanReadableString); if (m_alpha < 255) { char buf[512]; usprintf(buf, ", Alpha %d", m_alpha); str += buf; } g->drawString(str, textColor, ColorNone, false, gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2)); x += ji_font_text_len(getFont(), str.c_str()) + 4*jguiscale(); } // Show tool if (m_state == SHOW_TOOL) { // Draw eyedropper icon BITMAP* icon = theme->get_toolicon(m_tool->getId().c_str()); if (icon) { g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2); x += icon->w + 4*jguiscale(); } } // Status bar text if (getTextLength() > 0) { g->drawString(getText(), textColor, ColorNone, false, gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2)); x += ji_font_text_len(getFont(), getText().c_str()) + 4*jguiscale(); } // Draw progress bar if (!m_progress.empty()) { int width = 64; int x = rc.x2() - (width+4); for (ProgressList::iterator it = m_progress.begin(); it != m_progress.end(); ++it) { Progress* progress = *it; theme->paintProgressBar(g, gfx::Rect(x, rc.y, width, rc.h), progress->getPos()); x -= width+4; } } updateSubwidgetsVisibility(); }
void StatusBar::onPreferredSize(PreferredSizeEvent& ev) { int s = 4*jguiscale() + getTextHeight() + 4*jguiscale(); ev.setPreferredSize(Size(s, s)); }
StatusBar::StatusBar() : Widget(statusbar_type()) , m_color(app::Color::fromMask()) { m_instance = this; setDoubleBuffered(true); SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme()); setBgColor(theme->getColorById(kStatusBarFace)); #define BUTTON_NEW(name, text, action) \ { \ (name) = new Button(text); \ (name)->user_data[0] = this; \ setup_mini_look(name); \ (name)->Click.connect(Bind<void>(&ani_button_command, (name), action)); \ } #define ICON_NEW(name, icon, action) \ { \ BUTTON_NEW((name), "", (action)); \ set_gfxicon_to_button((name), icon, icon##_SELECTED, icon##_DISABLED, JI_CENTER | JI_MIDDLE); \ } this->setFocusStop(true); m_timeout = 0; m_state = SHOW_TEXT; m_tipwindow = NULL; // The extra pixel in left and right borders are necessary so // m_commandsBox and m_movePixelsBox do not overlap the upper-left // and upper-right pixels drawn in onPaint() event (see putpixels) setBorder(gfx::Border(1*jguiscale(), 0, 1*jguiscale(), 0)); // Construct the commands box { Box* box1 = new Box(JI_HORIZONTAL); Box* box2 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS); Box* box3 = new Box(JI_HORIZONTAL); Box* box4 = new Box(JI_HORIZONTAL); m_slider = new Slider(0, 255, 255); m_currentFrame = new GotoFrameEntry(); m_newFrame = new Button("+"); m_newFrame->Click.connect(Bind<void>(&StatusBar::newFrame, this)); setup_mini_look(m_slider); setup_mini_look(m_currentFrame); setup_mini_look(m_newFrame); ICON_NEW(m_b_first, PART_ANI_FIRST, ACTION_FIRST); ICON_NEW(m_b_prev, PART_ANI_PREVIOUS, ACTION_PREV); ICON_NEW(m_b_play, PART_ANI_PLAY, ACTION_PLAY); ICON_NEW(m_b_next, PART_ANI_NEXT, ACTION_NEXT); ICON_NEW(m_b_last, PART_ANI_LAST, ACTION_LAST); m_slider->Change.connect(Bind<void>(&slider_change_hook, m_slider)); jwidget_set_min_size(m_slider, JI_SCREEN_W/5, 0); box1->setBorder(gfx::Border(2, 1, 2, 2)*jguiscale()); box2->noBorderNoChildSpacing(); box3->noBorderNoChildSpacing(); box3->setExpansive(true); box4->addChild(m_currentFrame); box4->addChild(m_newFrame); box2->addChild(m_b_first); box2->addChild(m_b_prev); box2->addChild(m_b_play); box2->addChild(m_b_next); box2->addChild(m_b_last); box1->addChild(box3); box1->addChild(box4); box1->addChild(box2); box1->addChild(m_slider); m_commandsBox = box1; } // Create the box to show notifications. { Box* box1 = new Box(JI_HORIZONTAL); Box* box2 = new Box(JI_VERTICAL); box1->setBorder(gfx::Border(2, 1, 2, 2)*jguiscale()); box2->noBorderNoChildSpacing(); box2->setExpansive(true); m_linkLabel = new LinkLabel((std::string(WEBSITE) + "donate/").c_str(), "Support This Project"); box1->addChild(box2); box1->addChild(m_linkLabel); m_notificationsBox = box1; } addChild(m_notificationsBox); App::instance()->CurrentToolChange.connect(&StatusBar::onCurrentToolChange, this); }
static Widget* convert_xmlelement_to_widget(TiXmlElement* elem, Widget* root) { const char *elem_name = elem->Value(); JWidget widget = NULL; JWidget child; /* TODO error handling: add a message if the widget is bad specified */ // Boxes if (ustrcmp(elem_name, "box") == 0) { bool horizontal = bool_attr_is_true(elem, "horizontal"); bool vertical = bool_attr_is_true(elem, "vertical"); bool homogeneous = bool_attr_is_true(elem, "homogeneous"); widget = new Box((horizontal ? JI_HORIZONTAL: vertical ? JI_VERTICAL: 0) | (homogeneous ? JI_HOMOGENEOUS: 0)); } else if (ustrcmp(elem_name, "vbox") == 0) { bool homogeneous = bool_attr_is_true(elem, "homogeneous"); widget = new VBox(); if (homogeneous) widget->setAlign(widget->getAlign() | JI_HOMOGENEOUS); } else if (ustrcmp(elem_name, "hbox") == 0) { bool homogeneous = bool_attr_is_true(elem, "homogeneous"); widget = new HBox(); if (homogeneous) widget->setAlign(widget->getAlign() | JI_HOMOGENEOUS); } else if (ustrcmp(elem_name, "boxfiller") == 0) { widget = new BoxFiller(); } // Button else if (ustrcmp(elem_name, "button") == 0) { const char *text = elem->Attribute("text"); widget = new Button(text ? TRANSLATE_ATTR(text): NULL); if (widget) { bool left = bool_attr_is_true(elem, "left"); bool right = bool_attr_is_true(elem, "right"); bool top = bool_attr_is_true(elem, "top"); bool bottom = bool_attr_is_true(elem, "bottom"); bool closewindow = bool_attr_is_true(elem, "closewindow"); const char *_bevel = elem->Attribute("bevel"); widget->setAlign((left ? JI_LEFT: (right ? JI_RIGHT: JI_CENTER)) | (top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE))); if (_bevel != NULL) { char* bevel = base_strdup(_bevel); int c, b[4]; char *tok; for (c=0; c<4; ++c) b[c] = 0; for (tok=ustrtok(bevel, " "), c=0; tok; tok=ustrtok(NULL, " "), ++c) { if (c < 4) b[c] = ustrtol(tok, NULL, 10); } base_free(bevel); setup_bevels(widget, b[0], b[1], b[2], b[3]); } if (closewindow) { static_cast<Button*>(widget) ->Click.connect(Bind<void>(&Widget::closeWindow, widget)); } } } // Check else if (ustrcmp(elem_name, "check") == 0) { const char *text = elem->Attribute("text"); const char *looklike = elem->Attribute("looklike"); text = (text ? TRANSLATE_ATTR(text): NULL); if (looklike != NULL && strcmp(looklike, "button") == 0) { widget = new CheckBox(text, JI_BUTTON); } else { widget = new CheckBox(text); } if (widget) { bool center = bool_attr_is_true(elem, "center"); bool right = bool_attr_is_true(elem, "right"); bool top = bool_attr_is_true(elem, "top"); bool bottom = bool_attr_is_true(elem, "bottom"); widget->setAlign((center ? JI_CENTER: (right ? JI_RIGHT: JI_LEFT)) | (top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE))); } } /* combobox */ else if (ustrcmp(elem_name, "combobox") == 0) { widget = new ComboBox(); } /* entry */ else if (ustrcmp(elem_name, "entry") == 0) { const char *maxsize = elem->Attribute("maxsize"); const char *text = elem->Attribute("text"); if (maxsize != NULL) { bool readonly = bool_attr_is_true(elem, "readonly"); widget = new Entry(ustrtol(maxsize, NULL, 10), text ? TRANSLATE_ATTR(text): NULL); if (readonly) ((Entry*)widget)->setReadOnly(true); } } /* grid */ else if (ustrcmp(elem_name, "grid") == 0) { const char *columns = elem->Attribute("columns"); bool same_width_columns = bool_attr_is_true(elem, "same_width_columns"); if (columns != NULL) { widget = new Grid(ustrtol(columns, NULL, 10), same_width_columns); } } /* label */ else if (ustrcmp(elem_name, "label") == 0) { const char *text = elem->Attribute("text"); widget = new Label(text ? TRANSLATE_ATTR(text): NULL); if (widget) { bool center = bool_attr_is_true(elem, "center"); bool right = bool_attr_is_true(elem, "right"); bool top = bool_attr_is_true(elem, "top"); bool bottom = bool_attr_is_true(elem, "bottom"); widget->setAlign((center ? JI_CENTER: (right ? JI_RIGHT: JI_LEFT)) | (top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE))); } } /* listbox */ else if (ustrcmp(elem_name, "listbox") == 0) { widget = new ListBox(); } /* listitem */ else if (ustrcmp(elem_name, "listitem") == 0) { const char *text = elem->Attribute("text"); widget = new ListBox::Item(text ? TRANSLATE_ATTR(text): NULL); } /* splitter */ else if (ustrcmp(elem_name, "splitter") == 0) { bool horizontal = bool_attr_is_true(elem, "horizontal"); bool vertical = bool_attr_is_true(elem, "vertical"); widget = new Splitter(horizontal ? JI_HORIZONTAL: vertical ? JI_VERTICAL: 0); } /* radio */ else if (ustrcmp(elem_name, "radio") == 0) { const char* text = elem->Attribute("text"); const char* group = elem->Attribute("group"); const char *looklike = elem->Attribute("looklike"); text = (text ? TRANSLATE_ATTR(text): NULL); int radio_group = (group ? ustrtol(group, NULL, 10): 1); if (looklike != NULL && strcmp(looklike, "button") == 0) { widget = new RadioButton(text, radio_group, JI_BUTTON); } else { widget = new RadioButton(text, radio_group); } if (widget) { bool center = bool_attr_is_true(elem, "center"); bool right = bool_attr_is_true(elem, "right"); bool top = bool_attr_is_true(elem, "top"); bool bottom = bool_attr_is_true(elem, "bottom"); widget->setAlign((center ? JI_CENTER: (right ? JI_RIGHT: JI_LEFT)) | (top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE))); } } /* separator */ else if (ustrcmp(elem_name, "separator") == 0) { const char *text = elem->Attribute("text"); bool center = bool_attr_is_true(elem, "center"); bool right = bool_attr_is_true(elem, "right"); bool middle = bool_attr_is_true(elem, "middle"); bool bottom = bool_attr_is_true(elem, "bottom"); bool horizontal = bool_attr_is_true(elem, "horizontal"); bool vertical = bool_attr_is_true(elem, "vertical"); widget = new Separator(text ? TRANSLATE_ATTR(text): NULL, (horizontal ? JI_HORIZONTAL: 0) | (vertical ? JI_VERTICAL: 0) | (center ? JI_CENTER: (right ? JI_RIGHT: JI_LEFT)) | (middle ? JI_MIDDLE: (bottom ? JI_BOTTOM: JI_TOP))); } /* slider */ else if (ustrcmp(elem_name, "slider") == 0) { const char *min = elem->Attribute("min"); const char *max = elem->Attribute("max"); int min_value = min != NULL ? ustrtol(min, NULL, 10): 0; int max_value = max != NULL ? ustrtol(max, NULL, 10): 0; widget = new Slider(min_value, max_value, min_value); } /* textbox */ else if (ustrcmp(elem_name, "textbox") == 0) { //bool wordwrap = bool_attr_is_true(elem, "wordwrap"); /* TODO add translatable support */ /* TODO here we need jxmlelem_get_text(elem) */ /* widget = jtextbox_new(tag->text, wordwrap ? JI_WORDWRAP: 0); */ ASSERT(false); } /* view */ else if (ustrcmp(elem_name, "view") == 0) { widget = new View(); } /* window */ else if (ustrcmp(elem_name, "window") == 0) { const char *text = elem->Attribute("text"); if (text) { bool desktop = bool_attr_is_true(elem, "desktop"); if (desktop) widget = new Frame(true, NULL); else widget = new Frame(false, TRANSLATE_ATTR(text)); } } /* colorpicker */ else if (ustrcmp(elem_name, "colorpicker") == 0) { widget = new ColorButton(Color::fromMask(), app_get_current_pixel_format()); } // Was the widget created? if (widget) { const char *name = elem->Attribute("name"); const char *tooltip = elem->Attribute("tooltip"); bool selected = bool_attr_is_true(elem, "selected"); bool disabled = bool_attr_is_true(elem, "disabled"); bool expansive = bool_attr_is_true(elem, "expansive"); bool magnetic = bool_attr_is_true(elem, "magnetic"); bool noborders = bool_attr_is_true(elem, "noborders"); const char *width = elem->Attribute("width"); const char *height = elem->Attribute("height"); const char *minwidth = elem->Attribute("minwidth"); const char *minheight = elem->Attribute("minheight"); const char *maxwidth = elem->Attribute("maxwidth"); const char *maxheight = elem->Attribute("maxheight"); const char *childspacing = elem->Attribute("childspacing"); if (name != NULL) widget->setName(name); if (tooltip != NULL) jwidget_add_tooltip_text(widget, tooltip, JI_LEFT); if (selected) widget->setSelected(selected); if (disabled) widget->setEnabled(false); if (expansive) widget->setExpansive(true); if (magnetic) widget->setFocusMagnet(true); if (noborders) jwidget_noborders(widget); if (childspacing) widget->child_spacing = ustrtol(childspacing, NULL, 10); if (width || minwidth || height || minheight) { int w = (width || minwidth) ? ustrtol(width ? width: minwidth, NULL, 10): 0; int h = (height || minheight) ? ustrtol(height ? height: minheight, NULL, 10): 0; jwidget_set_min_size(widget, w*jguiscale(), h*jguiscale()); } if (width || maxwidth || height || maxheight) { int w = (width || maxwidth) ? strtol(width ? width: maxwidth, NULL, 10): INT_MAX; int h = (height || maxheight) ? strtol(height ? height: maxheight, NULL, 10): INT_MAX; jwidget_set_max_size(widget, w*jguiscale(), h*jguiscale()); } if (!root) root = widget; // Children TiXmlElement* child_elem = elem->FirstChildElement(); while (child_elem) { child = convert_xmlelement_to_widget(child_elem, root); if (child) { // Attach the child in the view if (widget->type == JI_VIEW) { static_cast<View*>(widget)->attachToView(child); break; } // Add the child in the grid else if (widget->type == JI_GRID) { const char* cell_hspan = child_elem->Attribute("cell_hspan"); const char* cell_vspan = child_elem->Attribute("cell_vspan"); const char* cell_align = child_elem->Attribute("cell_align"); int hspan = cell_hspan ? ustrtol(cell_hspan, NULL, 10): 1; int vspan = cell_vspan ? ustrtol(cell_vspan, NULL, 10): 1; int align = cell_align ? convert_align_value_to_flags(cell_align): 0; Grid* grid = dynamic_cast<Grid*>(widget); ASSERT(grid != NULL); grid->addChildInCell(child, hspan, vspan, align); } // Just add the child in any other kind of widget else widget->addChild(child); } child_elem = child_elem->NextSiblingElement(); } if (widget->type == JI_VIEW) { bool maxsize = bool_attr_is_true(elem, "maxsize"); if (maxsize) static_cast<View*>(widget)->makeVisibleAllScrollableArea(); } } return widget; }
ColorSelector::ColorSelector() : PopupFramePin("Color Selector", false) , m_color(Color::fromMask()) , m_vbox(JI_VERTICAL) , m_topBox(JI_HORIZONTAL) , m_colorPalette(false) , m_indexButton("Index", 1, JI_BUTTON) , m_rgbButton("RGB", 1, JI_BUTTON) , m_hsvButton("HSB", 1, JI_BUTTON) , m_grayButton("Gray", 1, JI_BUTTON) , m_maskButton("Mask", 1, JI_BUTTON) , m_maskLabel("Transparent Color Selected") , m_disableHexUpdate(false) { m_topBox.setBorder(gfx::Border(0)); m_topBox.child_spacing = 0; m_colorPalette.setColumns(40); m_colorPalette.setBoxSize(6*jguiscale()); m_colorPaletteContainer.attachToView(&m_colorPalette); m_colorPaletteContainer.setExpansive(true); setup_mini_look(&m_indexButton); setup_mini_look(&m_rgbButton); setup_mini_look(&m_hsvButton); setup_mini_look(&m_grayButton); setup_mini_look(&m_maskButton); m_topBox.addChild(&m_indexButton); m_topBox.addChild(&m_rgbButton); m_topBox.addChild(&m_hsvButton); m_topBox.addChild(&m_grayButton); m_topBox.addChild(&m_maskButton); m_topBox.addChild(&m_hexColorEntry); { Box* miniVbox = new Box(JI_VERTICAL); miniVbox->addChild(getPin()); m_topBox.addChild(new BoxFiller); m_topBox.addChild(miniVbox); } m_vbox.addChild(&m_topBox); m_vbox.addChild(&m_colorPaletteContainer); m_vbox.addChild(&m_rgbSliders); m_vbox.addChild(&m_hsvSliders); m_vbox.addChild(&m_graySlider); m_vbox.addChild(&m_maskLabel); addChild(&m_vbox); m_indexButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_rgbButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_hsvButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_grayButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_maskButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_colorPalette.IndexChange.connect(&ColorSelector::onColorPaletteIndexChange, this); m_rgbSliders.ColorChange.connect(&ColorSelector::onColorSlidersChange, this); m_hsvSliders.ColorChange.connect(&ColorSelector::onColorSlidersChange, this); m_graySlider.ColorChange.connect(&ColorSelector::onColorSlidersChange, this); m_hexColorEntry.ColorChange.connect(&ColorSelector::onColorHexEntryChange, this); selectColorType(Color::RgbType); setPreferredSize(gfx::Size(300*jguiscale(), getPreferredSize().h)); m_onPaletteChangeSlot = App::instance()->PaletteChange.connect(&ColorSelector::onPaletteChange, this); initTheme(); }