void draw_color_button(ui::Graphics* g, const Rect& rc, const app::Color& color, bool hot, bool drag) { SkinTheme* theme = SkinTheme::instance(); int scale = ui::guiscale(); // Draw background (the color) draw_color(g, Rect(rc.x+1*scale, rc.y+1*scale, rc.w-2*scale, rc.h-2*scale), color); // Draw opaque border theme->drawRect( g, rc, theme->parts.colorbar0()->getBitmapNW(), theme->parts.colorbar0()->getBitmapN(), theme->parts.colorbar1()->getBitmapNE(), theme->parts.colorbar1()->getBitmapE(), theme->parts.colorbar3()->getBitmapSE(), theme->parts.colorbar2()->getBitmapS(), theme->parts.colorbar2()->getBitmapSW(), theme->parts.colorbar0()->getBitmapW()); // Draw hot if (hot) { theme->drawRect( g, gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale), theme->parts.colorbarBorderHotfg().get()); } }
void ColorSpectrum::onPaint(ui::PaintEvent& ev) { ui::Graphics* g = ev.graphics(); SkinTheme* theme = static_cast<SkinTheme*>(this->theme()); theme->drawRect(g, clientBounds(), theme->parts.editorNormal().get(), bgColor()); gfx::Rect rc = clientChildrenBounds(); if (rc.isEmpty()) return; int vmid = (align() & HORIZONTAL ? rc.h/2 : rc.w/2); vmid = MAX(1, vmid); for (int y=0; y<rc.h; ++y) { for (int x=0; x<rc.w; ++x) { int u, v, umax; if (align() & HORIZONTAL) { u = x; v = y; umax = MAX(1, rc.w-1); } else { u = y; v = x; umax = MAX(1, rc.h-1); } double hue = 360.0 * u / umax; double sat = (v < vmid ? 100.0 * v / vmid : 100.0); double val = (v < vmid ? 100.0 : 100.0-(100.0 * (v-vmid) / vmid)); gfx::Color color = color_utils::color_for_ui( app::Color::fromHsv( MID(0.0, hue, 360.0), MID(0.0, sat, 100.0), MID(0.0, val, 100.0))); g->putPixel(color, rc.x+x, rc.y+y); } } if (m_color.getType() != app::Color::MaskType) { double hue = m_color.getHue(); double sat = m_color.getSaturation(); double val = m_color.getValue(); double lit = (200.0 - sat) * val / 200.0; gfx::Point pos(rc.x + int(hue * rc.w / 360.0), rc.y + rc.h - int(lit * rc.h / 100.0)); she::Surface* icon = theme->parts.colorWheelIndicator()->bitmap(0); g->drawColoredRgbaSurface( icon, lit > 50.0 ? gfx::rgba(0, 0, 0): gfx::rgba(255, 255, 255), pos.x-icon->width()/2, pos.y-icon->height()/2); } }
void EditorView::onPaint(PaintEvent& ev) { Graphics* g = ev.graphics(); SkinTheme* theme = static_cast<SkinTheme*>(this->theme()); bool selected = false; switch (m_type) { // Only show the view selected if it is the current editor case CurrentEditorMode: selected = (editor()->isActive()); break; // Always show selected case AlwaysSelected: selected = true; break; } theme->drawRect( g, clientBounds(), (selected ? theme->parts.editorSelected().get(): theme->parts.editorNormal().get()), bgColor()); }
void ColorWheel::onPaint(ui::PaintEvent& ev) { ui::Graphics* g = ev.getGraphics(); SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); theme->drawRect(g, getClientBounds(), theme->parts.editorNormal().get(), getBgColor()); const gfx::Rect& rc = m_clientBounds; for (int y=rc.y; y<rc.y+rc.h; ++y) { for (int x=rc.x; x<rc.x+rc.w; ++x) { app::Color appColor = ColorWheel::pickColor(gfx::Point(x, y)); gfx::Color color; if (appColor.getType() != app::Color::MaskType) { color = color_utils::color_for_ui(appColor); } else { color = theme->colors.editorFace(); } g->putPixel(color, x, y); } } if (m_mainColor.getAlpha() > 0) { int n = getHarmonies(); int boxsize = MIN(rc.w/10, rc.h/10); for (int i=0; i<n; ++i) { app::Color color = getColorInHarmony(i); int hue = color.getHue()-30; int sat = color.getSaturation(); gfx::Point pos = m_wheelBounds.getCenter() + gfx::Point(int(+std::cos(PI*hue/180)*double(m_wheelRadius)*sat/100.0), int(-std::sin(PI*hue/180)*double(m_wheelRadius)*sat/100.0)); she::Surface* icon = theme->parts.colorWheelIndicator()->getBitmap(0); g->drawRgbaSurface(icon, pos.x-icon->width()/2, pos.y-icon->height()/2); g->fillRect(gfx::rgba(color.getRed(), color.getGreen(), color.getBlue(), 255), gfx::Rect(rc.x+rc.w-(n-i)*boxsize, rc.y+rc.h-boxsize, boxsize, boxsize)); } } }
void BackgroundRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text) { SkinTheme* theme = static_cast<SkinTheme*>(ui::CurrentTheme::get()); if (m_part && m_part->countBitmaps() > 0) { if (m_part->countBitmaps() == 1) { if (!gfx::is_transparent(m_color)) g->fillRect(m_color, bounds); she::Surface* bmp = m_part->bitmap(0); if (m_repeat == BackgroundRepeat::NO_REPEAT) { g->drawRgbaSurface(bmp, bounds.x, bounds.y); } else { ui::IntersectClip clip(g, bounds); if (!clip) return; for (int y=bounds.y; y<bounds.y2(); y+=bmp->height()) { for (int x=bounds.x; x<bounds.x2(); x+=bmp->width()) { g->drawRgbaSurface(bmp, x, y); if (m_repeat == BackgroundRepeat::REPEAT_Y) break; } if (m_repeat == BackgroundRepeat::REPEAT_X) break; } } } else if (m_part->countBitmaps() == 8) { theme->drawRect(g, bounds, m_part.get(), m_color); } } else if (!gfx::is_transparent(m_color)) { g->fillRect(m_color, bounds); } }
void ButtonSet::Item::onPaint(ui::PaintEvent& ev) { SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); Graphics* g = ev.getGraphics(); gfx::Rect rc = getClientBounds(); gfx::Color fg, bg; SkinPartPtr nw; gfx::Rect boxRc, textRc, iconRc; gfx::Size iconSize; if (m_icon) iconSize = m_icon->getSize(); getTextIconInfo( &boxRc, &textRc, &iconRc, CENTER | (hasText() ? BOTTOM: MIDDLE), iconSize.w, iconSize.h); Grid::Info info = buttonSet()->getChildInfo(this); bool isLastCol = (info.col+info.hspan >= info.grid_cols); bool isLastRow = (info.row+info.vspan >= info.grid_rows); if (m_icon || isLastRow) { textRc.y -= 1*guiscale(); iconRc.y -= 1*guiscale(); } if (!gfx::is_transparent(getBgColor())) g->fillRect(getBgColor(), g->getClipBounds()); if (isSelected() || hasMouseOver()) { if (hasCapture()) { nw = theme->parts.toolbuttonPushed(); fg = theme->colors.buttonSelectedText(); bg = theme->colors.buttonSelectedFace(); } else { nw = (hasFocus() ? theme->parts.toolbuttonHotFocused(): theme->parts.toolbuttonHot()); fg = theme->colors.buttonHotText(); bg = theme->colors.buttonHotFace(); } } else { nw = (hasFocus() ? theme->parts.toolbuttonFocused(): theme->parts.toolbuttonLast()); fg = theme->colors.buttonNormalText(); bg = theme->colors.buttonNormalFace(); } if (!isLastCol) rc.w += 1*guiscale(); if (!isLastRow) { if (nw == theme->parts.toolbuttonHotFocused()) rc.h += 2*guiscale(); else rc.h += 3*guiscale(); } theme->drawRect(g, rc, nw.get(), bg); if (m_icon) { if (isSelected() && hasCapture()) g->drawColoredRgbaSurface(m_icon->getBitmap(0), theme->colors.buttonSelectedText(), iconRc.x, iconRc.y); else g->drawRgbaSurface(m_icon->getBitmap(0), iconRc.x, iconRc.y); } if (hasText()) { g->setFont(getFont()); g->drawUIString(getText(), fg, gfx::ColorNone, textRc.getOrigin(), false); } }
void ColorTintShadeTone::onPaint(ui::PaintEvent& ev) { ui::Graphics* g = ev.graphics(); SkinTheme* theme = static_cast<SkinTheme*>(this->theme()); theme->drawRect(g, clientBounds(), theme->parts.editorNormal().get(), bgColor()); gfx::Rect rc = clientChildrenBounds(); if (rc.isEmpty()) return; double hue = m_color.getHue(); int umax, vmax; int huebar = getHueBarSize(); umax = MAX(1, rc.w-1); vmax = MAX(1, rc.h-1-huebar); for (int y=0; y<rc.h-huebar; ++y) { for (int x=0; x<rc.w; ++x) { double sat = (100.0 * x / umax); double val = (100.0 - 100.0 * y / vmax); gfx::Color color = color_utils::color_for_ui( app::Color::fromHsv( hue, MID(0.0, sat, 100.0), MID(0.0, val, 100.0))); g->putPixel(color, rc.x+x, rc.y+y); } } if (huebar > 0) { for (int y=rc.h-huebar; y<rc.h; ++y) { for (int x=0; x<rc.w; ++x) { gfx::Color color = color_utils::color_for_ui( app::Color::fromHsv( (360.0 * x / rc.w), 100.0, 100.0)); g->putPixel(color, rc.x+x, rc.y+y); } } } if (m_color.getType() != app::Color::MaskType) { double sat = m_color.getSaturation(); double val = m_color.getValue(); gfx::Point pos(rc.x + int(sat * rc.w / 100.0), rc.y + int((100.0-val) * (rc.h-huebar) / 100.0)); she::Surface* icon = theme->parts.colorWheelIndicator()->bitmap(0); g->drawColoredRgbaSurface( icon, val > 50.0 ? gfx::rgba(0, 0, 0): gfx::rgba(255, 255, 255), pos.x-icon->width()/2, pos.y-icon->height()/2); if (huebar > 0) { pos.x = rc.x + int(rc.w * hue / 360.0); pos.y = rc.y + rc.h - huebar/2; g->drawColoredRgbaSurface( icon, gfx::rgba(0, 0, 0), pos.x-icon->width()/2, pos.y-icon->height()/2); } } }