void PopupWindow::onPreferredSize(PreferredSizeEvent& ev) { ScreenGraphics g; g.setFont(getFont()); Size resultSize(0, 0); if (hasText()) resultSize = g.fitString(getText(), (getClientBounds() - getBorder()).w, getAlign()); resultSize.w += border_width.l + border_width.r; resultSize.h += border_width.t + border_width.b; if (!getChildren().empty()) { Size maxSize(0, 0); Size reqSize; UI_FOREACH_WIDGET(getChildren(), it) { Widget* child = *it; reqSize = child->getPreferredSize(); maxSize.w = MAX(maxSize.w, reqSize.w); maxSize.h = MAX(maxSize.h, reqSize.h); }
GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds, GHOST_TInt32 mouse_ungrab_xy[2]) { if (m_cursorGrab == mode) return GHOST_kSuccess; /* override with new location */ if (mouse_ungrab_xy) { assert(mode == GHOST_kGrabDisable); m_cursorGrabInitPos[0] = mouse_ungrab_xy[0]; m_cursorGrabInitPos[1] = mouse_ungrab_xy[1]; } if (setWindowCursorGrab(mode)) { if (mode == GHOST_kGrabDisable) m_cursorGrabBounds.m_l = m_cursorGrabBounds.m_r = -1; else if (bounds) { m_cursorGrabBounds = *bounds; } else { /* if bounds not defined, use window */ getClientBounds(m_cursorGrabBounds); } m_cursorGrab = mode; return GHOST_kSuccess; } else { return GHOST_kFailure; } }
GHOST_TSuccess GHOST_WindowCarbon::setClientWidth(GHOST_TUns32 width) { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setClientWidth(): window invalid") GHOST_Rect cBnds, wBnds; getClientBounds(cBnds); if (((GHOST_TUns32)cBnds.getWidth()) != width) { ::SizeWindow(m_windowRef, width, cBnds.getHeight(), true); } return GHOST_kSuccess; }
void ImageView::onPaint(PaintEvent& ev) { Graphics* g = ev.getGraphics(); gfx::Rect bounds = getClientBounds(); gfx::Rect icon; getTextIconInfo(NULL, NULL, &icon, getAlign(), m_bmp->w, m_bmp->h); g->fillRect(getBgColor(), bounds); g->blit(m_bmp, 0, 0, icon.x, icon.y, icon.w, icon.h); }
void ImageView::onPaint(PaintEvent& ev) { Graphics* g = ev.getGraphics(); gfx::Rect bounds = getClientBounds(); gfx::Rect icon; getTextIconInfo(NULL, NULL, &icon, getAlign(), m_sur->width(), m_sur->height()); g->fillRect(getBgColor(), bounds); g->drawRgbaSurface(m_sur, icon.x, icon.y); }
GHOST_TSuccess GHOST_WindowCarbon::setClientHeight(GHOST_TUns32 height) { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setClientHeight(): window invalid") GHOST_Rect cBnds, wBnds; getClientBounds(cBnds); #ifdef GHOST_DRAW_CARBON_GUTTER if (((GHOST_TUns32)cBnds.getHeight()) != height+s_sizeRectSize) { ::SizeWindow(m_windowRef, cBnds.getWidth(), height+s_sizeRectSize, true); } #else //GHOST_DRAW_CARBON_GUTTER if (((GHOST_TUns32)cBnds.getHeight()) != height) { ::SizeWindow(m_windowRef, cBnds.getWidth(), height, true); } #endif //GHOST_DRAW_CARBON_GUTTER return GHOST_kSuccess; }
GHOST_TSuccess GHOST_WindowWin32::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height) { GHOST_TSuccess success; GHOST_Rect cBnds, wBnds; getClientBounds(cBnds); if ((cBnds.getWidth() != (GHOST_TInt32)width) || (cBnds.getHeight() != (GHOST_TInt32)height)) { getWindowBounds(wBnds); int cx = wBnds.getWidth() + width - cBnds.getWidth(); int cy = wBnds.getHeight() + height - cBnds.getHeight(); success = ::SetWindowPos(m_hWnd, HWND_TOP, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER) ? GHOST_kSuccess : GHOST_kFailure; } else { success = GHOST_kSuccess; } return success; }
GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds) { if(m_cursorGrab == mode) return GHOST_kSuccess; if (setWindowCursorGrab(mode)) { if(mode==GHOST_kGrabDisable) m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1; else if (bounds) { m_cursorGrabBounds= *bounds; } else { /* if bounds not defined, use window */ getClientBounds(m_cursorGrabBounds); } m_cursorGrab = mode; return GHOST_kSuccess; } else { return GHOST_kFailure; } }
void GHOST_WindowWayland::getWindowBounds(GHOST_Rect& bounds) const { getClientBounds(bounds); }
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(); }