void PopupWindow::onSizeHint(SizeHintEvent& ev) { ScreenGraphics g; g.setFont(font()); Size resultSize(0, 0); if (hasText()) resultSize = g.fitString(text(), (clientBounds() - border()).w, align()); resultSize.w += border().width(); resultSize.h += border().height(); if (!children().empty()) { Size maxSize(0, 0); Size reqSize; for (auto child : children()) { reqSize = child->sizeHint(); maxSize.w = MAX(maxSize.w, reqSize.w); maxSize.h = MAX(maxSize.h, reqSize.h); } resultSize.w = MAX(resultSize.w, maxSize.w + border().width()); resultSize.h += maxSize.h; } ev.setSizeHint(resultSize); }
void StandbyState::Decorator::postRenderDecorator(EditorPostRender* render) { Editor* editor = render->getEditor(); // Draw transformation handles (if the mask is visible and isn't frozen). if (editor->isActive() && editor->editorFlags() & Editor::kShowMask && editor->document()->isMaskVisible() && !editor->document()->mask()->isFrozen()) { // And draw only when the user has a selection tool as active tool. tools::Ink* ink = editor->getCurrentEditorInk(); if (ink->isSelection()) getTransformHandles(editor)->drawHandles(editor, m_standbyState->getTransformation(editor)); } // Draw transformation handles (if the mask is visible and isn't frozen). gfx::Rect box1, box2; if (StandbyState::Decorator::getSymmetryHandles(editor, box1, box2)) { skin::SkinTheme* theme = static_cast<skin::SkinTheme*>(CurrentTheme::get()); she::Surface* part = theme->parts.transformationHandle()->bitmap(0); ScreenGraphics g; g.drawRgbaSurface(part, box1.x, box1.y); g.drawRgbaSurface(part, box2.x, box2.y); } }
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); }
/** * Cleans the brush cursor from the specified editor. * * The mouse position is got from the last * call to @c drawBrushPreview. So you must * to use this routine only if you called * @c drawBrushPreview before with the specified * editor @a widget. * * @param widget The editor widget * * @see drawBrushPreview */ void Editor::clearBrushPreview(bool refresh) { ASSERT(m_cursorThick != 0); ASSERT(m_sprite != NULL); getDrawableRegion(clipping_region, kCutTopWindows); gfx::Point pos = m_cursorEditor; if (refresh) { // Restore pixels ScreenGraphics g; SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height())); forEachBrushPixel(&g, m_cursorScreen, pos, gfx::ColorNone, clearpixel); } // Clean pixel/brush preview if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) { m_document->destroyExtraCel(); if (refresh) { m_document->notifySpritePixelsModified (m_sprite, gfx::Region(lastBrushBounds)); } } m_cursorThick = 0; clipping_region.clear(); old_clipping_region.clear(); }
void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& transform) { ScreenGraphics g; fixmath::fixed angle = fixmath::ftofix(128.0 * transform.angle() / PI); gfx::Transformation::Corners corners; transform.transformBox(corners); std::vector<gfx::Point> screenPoints(corners.size()); for (size_t c=0; c<corners.size(); ++c) screenPoints[c] = editor->editorToScreen( gfx::Point((int)corners[c].x, (int)corners[c].y)); // TODO DO NOT COMMIT #if 0 // Uncomment this if you want to see the bounds in red (only for debugging purposes) // ----------------------------------------------- { gfx::Point a(transform.bounds().getOrigin()), b(transform.bounds().getPoint2()); a = editor->editorToScreen(a); b = editor->editorToScreen(b); g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a, b)); a = transform.pivot(); a = editor->editorToScreen(a); g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a.x-2, a.y-2, 5, 5)); } // ----------------------------------------------- #endif // Draw corner handle for (size_t c=0; c<HANDLES; ++c) { drawHandle(&g, (screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2, (screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2, angle + handles_info[c].angle); } // Draw the pivot if (visiblePivot(angle)) { gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners); SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); she::Surface* part = theme->parts.pivotHandle()->getBitmap(0); g.drawRgbaSurface(part, pivotBounds.x, pivotBounds.y); } }
void Editor::moveBrushPreview(const gfx::Point& pos, bool refresh) { ASSERT(m_sprite != NULL); gfx::Point oldScreenPos = m_cursorScreen; gfx::Point oldEditorPos = m_cursorEditor; clearBrushPreview(false); drawBrushPreview(pos, false); gfx::Point newEditorPos = m_cursorEditor; if (refresh) { // Restore pixels { ScreenGraphics g; SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height())); forEachBrushPixel(&g, oldScreenPos, oldEditorPos, gfx::ColorNone, clearpixel); } if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) { Brush* brush = get_current_brush(); gfx::Rect newBrushBounds = brush->bounds(); newBrushBounds.offset(newEditorPos); m_document->notifySpritePixelsModified (m_sprite, gfx::Region(lastBrushBounds.createUnion(newBrushBounds))); lastBrushBounds = newBrushBounds; } // Save area and draw the cursor ScreenGraphics g; forEachBrushPixel(&g, m_cursorScreen, newEditorPos, ui_cursor_color, savepixel); forEachBrushPixel(&g, m_cursorScreen, newEditorPos, ui_cursor_color, drawpixel); } }
void ComboBox::updateMaxItemSize(const String& text) { ScreenGraphics g; g.setFont(getFont()); m_maxItemSize = m_maxItemSize.createUnion(g.measureString(text)); }
// Draws the brush cursor inside the specified editor. // Warning: You should clean the cursor before to use // this routine with other editor. // // Note: x and y params are absolute positions of the mouse. void Editor::drawBrushPreview(const gfx::Point& pos, bool refresh) { ASSERT(m_cursorThick == 0); ASSERT(m_sprite != NULL); // Get drawable region getDrawableRegion(clipping_region, kCutTopWindows); // Get cursor color cursor_negative = is_cursor_mask; // Cursor in the screen (view) m_cursorScreen = pos; // Get cursor position in the editor gfx::Point spritePos = screenToEditor(pos); // Get the current tool tools::Tool* tool = getCurrentEditorTool(); tools::Ink* ink = getCurrentEditorInk(); // Setup the cursor type debrushding of several factors (current tool, // foreground color, and layer transparency). color_t brush_color = get_brush_color(m_sprite, m_layer); color_t mask_color = m_sprite->transparentColor(); if (ink->isSelection() || ink->isSlice()) { cursor_type = CURSOR_THICKCROSS; } else if ( // Use cursor bounds for inks that are effects (eraser, blur, etc.) (ink->isEffect()) || // or when the brush color is transparent and we are not in the background layer (m_layer && !m_layer->isBackground() && brush_color == mask_color)) { cursor_type = CURSOR_BRUSHBOUNDS; } else { cursor_type = CURSOR_THINCROSS; } // For cursor type 'bounds' we have to generate cursor boundaries if (cursor_type & CURSOR_BRUSHBOUNDS) generate_cursor_boundaries(this); // Draw pixel/brush preview if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) { IToolSettings* tool_settings = UIContext::instance() ->settings() ->getToolSettings(tool); Brush* brush = get_current_brush(); gfx::Rect brushBounds = brush->bounds(); brushBounds.offset(spritePos); // Create the extra cel to show the brush preview Site site = getSite(); Cel* cel = site.cel(); m_document->prepareExtraCel( brushBounds, cel ? cel->opacity(): 255); m_document->setExtraCelType(render::ExtraType::NONE); m_document->setExtraCelBlendMode( m_layer ? static_cast<LayerImage*>(m_layer)->getBlendMode(): BLEND_MODE_NORMAL); // In 'indexed' images, if the current color is 0, we have to use // a different mask color (different from 0) to draw the extra layer if (brush_color == mask_color) mask_color = (mask_color == 0 ? 1: 0); Image* extraImage = m_document->getExtraCelImage(); extraImage->setMaskColor(mask_color); clear_image(extraImage, mask_color); if (m_layer) { render::Render().renderLayer( extraImage, m_layer, m_frame, gfx::Clip(0, 0, brushBounds), BLEND_MODE_COPY); // This extra cel is a patch for the current layer/frame m_document->setExtraCelType(render::ExtraType::PATCH); } tools::ToolLoop* loop = create_tool_loop_preview( this, UIContext::instance(), extraImage, -gfx::Point(brushBounds.x, brushBounds.y)); if (loop) { loop->getInk()->prepareInk(loop); loop->getIntertwine()->prepareIntertwine(); loop->getController()->prepareController(); loop->getPointShape()->preparePointShape(loop); loop->getPointShape()->transformPoint( loop, -brush->bounds().x, -brush->bounds().y); delete loop; } if (refresh) { m_document->notifySpritePixelsModified (m_sprite, gfx::Region(lastBrushBounds = brushBounds)); } } // Save area and draw the cursor if (refresh) { ScreenGraphics g; SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height())); forEachBrushPixel(&g, m_cursorScreen, spritePos, ui_cursor_color, savepixel); forEachBrushPixel(&g, m_cursorScreen, spritePos, ui_cursor_color, drawpixel); } // Cursor thickness m_cursorThick = 1; // Cursor in the editor (model) m_cursorEditor = spritePos; // Save the clipping-region to know where to clean the pixels old_clipping_region = clipping_region; }