void UIContext::setActiveView(DocumentView* docView) { if (m_lastSelectedView == docView) // Do nothing case return; setActiveDocument(docView ? docView->getDocument(): NULL); if (docView != NULL) { App::instance()->getMainWindow()->getTabsBar()->selectTab(docView); if (App::instance()->getMainWindow()->getWorkspace()->activeView() != docView) App::instance()->getMainWindow()->getWorkspace()->setActiveView(docView); } current_editor = (docView ? docView->getEditor(): NULL); if (current_editor) current_editor->requestFocus(); App::instance()->getMainWindow()->getMiniEditor()->updateUsingEditor(current_editor); App::instance()->getMainWindow()->getTimeline()->updateUsingEditor(current_editor); // Change the image-type of color bar. ColorBar::instance()->setPixelFormat(app_get_current_pixel_format()); // Restore the palette of the selected document. app_refresh_screen(); // Change the main frame title. App::instance()->updateDisplayTitleBar(); m_lastSelectedView = docView; }
void UIContext::setActiveView(DocumentView* docView) { MainWindow* mainWin = App::instance()->getMainWindow(); // Prioritize workspace for user input. App::instance()->inputChain().prioritize(mainWin->getWorkspace()); // Do nothing cases: 1) the view is already selected, or 2) the view // is the a preview. if (m_lastSelectedView == docView || (docView && docView->isPreview())) return; if (docView) { mainWin->getTabsBar()->selectTab(docView); if (mainWin->getWorkspace()->activeView() != docView) mainWin->getWorkspace()->setActiveView(docView); } current_editor = (docView ? docView->getEditor(): NULL); if (current_editor) current_editor->requestFocus(); mainWin->getPreviewEditor()->updateUsingEditor(current_editor); mainWin->getTimeline()->updateUsingEditor(current_editor); // Change the image-type of color bar. ColorBar::instance()->setPixelFormat(app_get_current_pixel_format()); // Restore the palette of the selected document. app_refresh_screen(); // Change the main frame title. App::instance()->updateDisplayTitleBar(); m_lastSelectedView = docView; // TODO all the calls to functions like updateUsingEditor(), // setPixelFormat(), app_refresh_screen(), updateDisplayTitleBar() // Can be replaced with a ContextObserver listening to the // onActiveSiteChange() event. notifyActiveSiteChanged(); }
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 ColorShades::onPaint(ui::PaintEvent& ev) { auto theme = skin::SkinTheme::instance(); ui::Graphics* g = ev.graphics(); gfx::Rect bounds = clientBounds(); theme->paintWidget(g, this, style(), bounds); bounds.shrink(3*ui::guiscale()); gfx::Rect box(bounds.x, bounds.y, m_boxSize*ui::guiscale(), bounds.h); Shade colors = getShade(); if (colors.size() >= 2) { gfx::Rect hotBounds; int j = 0; for (int i=0; box.x<bounds.x2(); ++i, box.x += box.w) { // Make the last box a little bigger to just use all // available size if (i == int(colors.size())-1) { if (bounds.x+bounds.w-box.x <= m_boxSize+m_boxSize/2) box.w = bounds.x+bounds.w-box.x; } app::Color color; if (m_dragIndex >= 0 && m_hotIndex == i) { color = colors[m_dragIndex]; } else { if (j == m_dragIndex) { ++j; } if (j < int(colors.size())) color = colors[j++]; else color = app::Color::fromMask(); } draw_color(g, box, color, (doc::ColorMode)app_get_current_pixel_format()); if (m_hotIndex == i) hotBounds = box; } if (!hotBounds.isEmpty() && isHotEntryVisible()) { hotBounds.enlarge(3*ui::guiscale()); ui::PaintWidgetPartInfo info; theme->paintWidgetPart( g, theme->styles.shadeSelection(), hotBounds, info); } } else { g->fillRect(theme->colors.editorFace(), bounds); g->drawAlignedUIText(text(), theme->colors.face(), gfx::ColorNone, bounds, ui::CENTER | ui::MIDDLE); } }
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; }