void dlgAirspaceWarningInit(SingleWindow &parent) { wf = LoadDialog(CallBackTable, parent, _T("IDR_XML_AIRSPACEWARNING")); if (wf == NULL) return; wf->SetKeyDownNotify(OnKeyDown); wf->SetTimerNotify(OnTimer); hBrushInsideBk.set(Color(254,50,50)); hBrushNearBk.set(Color(254,254,50)); hBrushInsideAckBk.set(Color(254,100,100)); hBrushNearAckBk.set(Color(254,254,100)); wAirspaceList = (WndListFrame*)wf->FindByName(_T("frmAirspaceWarningList")); wAirspaceList->SetPaintItemCallback(OnAirspaceListItemPaint); wAirspaceList->SetCursorCallback(AirspaceWarningCursorCallback); if (!has_pointer()) /* on platforms without a pointing device (e.g. ALTAIR), allow "focusing" an airspace by pressing enter */ wAirspaceList->SetActivateCallback(OnAirspaceListEnter); }
/** * Draw a line using either drawSoftLine or drawHardLine, depending on * the subpixel hint of the brush. * @param context drawing context id (needed for indirect drawing) */ void Layer::drawLine(int contextId, const Brush& brush, const Point& from, const Point& to, StrokeState &state) { Brush effective_brush = brush; Layer *l = this; if(!brush.incremental()) { // Indirect brush: use a sublayer l = getSubLayer(contextId, brush.blendingMode(), brush.opacity(1) * 255); effective_brush.setOpacity(1.0); effective_brush.setOpacity2(brush.isOpacityVariable() ? 0.0 : 1.0); effective_brush.setBlendingMode(BlendMode::MODE_NORMAL); } else if(contextId<0) { // Special case: negative context IDs are temporary overlay strokes l = getSubLayer(contextId, brush.blendingMode(), 255); effective_brush.setBlendingMode(BlendMode::MODE_NORMAL); } if(effective_brush.subpixel()) l->drawSoftLine(effective_brush, from, to, state); else l->drawHardLine(effective_brush, from, to, state); if(_owner) _owner->notifyAreaChanged(); }
/** * This function is optimized for drawing with subpixel precision. * @param brush brush to draw the line with * @param from starting point * @param to ending point * @param distance distance from previous dab. */ void Layer::drawSoftLine(const Brush& brush, const Point& from, const Point& to, StrokeState &state) { qreal dx = to.x() - from.x(); qreal dy = to.y() - from.y(); const qreal dist = hypot(dx, dy); dx = dx / dist; dy = dy / dist; const qreal dp = (to.pressure() - from.pressure()) / dist; const qreal spacing0 = qMax(1.0, brush.spacingDist(from.pressure())); qreal i; if(state.distance>=spacing0) i = 0; else if(state.distance==0) i = spacing0; else i = state.distance; Point p(from.x() + dx*i, from.y() + dy*i, qBound(0.0, from.pressure() + dp*i, 1.0)); while(i<=dist) { const qreal spacing = qMax(1.0, brush.spacingDist(p.pressure())); directDab(brush, p, state); p.rx() += dx * spacing; p.ry() += dy * spacing; p.setPressure(qBound(0.0, p.pressure() + dp * spacing, 1.0)); i += spacing; } state.distance = i-dist; }
void Layer::dab(int contextId, const Brush &brush, const Point &point, StrokeState &state) { Brush effective_brush = brush; Layer *l = this; if(!brush.incremental()) { // Indirect brush: use a sublayer l = getSubLayer(contextId, brush.blendingMode(), brush.opacity(1) * 255); effective_brush.setOpacity(1.0); effective_brush.setOpacity2(brush.isOpacityVariable() ? 0.0 : 1.0); effective_brush.setBlendingMode(BlendMode::MODE_NORMAL); } else if(contextId<0) { // Special case: negative context IDs are temporary overlay strokes l = getSubLayer(contextId, brush.blendingMode(), 255); effective_brush.setBlendingMode(BlendMode::MODE_NORMAL); } Point p = point; if(!effective_brush.subpixel()) { p.setX(qFloor(p.x())); p.setY(qFloor(p.y())); } l->directDab(effective_brush, p, state); if(_owner) _owner->notifyAreaChanged(); }
void DrawFilledRectangle(int left, int top, int right, int bottom, const Brush &brush) { if (brush.IsHollow()) return; DrawFilledRectangle(left, top, right, bottom, brush.GetColor()); }
/** * @brief Creates a cube out of the given mins and maxs of the axis aligned bounding box * @param[out] The brush to creates the planes for * @param[in] bounds The mins and maxs of the cube * @param[in] shader The path of the texture relative to the base dir * @param[in] projection The texture projection that is used (shift, scale and rotate values) */ void Cuboid::generate (Brush& brush, const AABB& bounds, std::size_t sides, const TextureProjection& projection, const std::string& shader) { const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } }; Vector3 mins(bounds.origin - bounds.extents); Vector3 maxs(bounds.origin + bounds.extents); brush.clear(); brush.reserve(6); { for (int i = 0; i < 3; ++i) { Vector3 planepts1(maxs); Vector3 planepts2(maxs); planepts2[box[i][0]] = mins[box[i][0]]; planepts1[box[i][1]] = mins[box[i][1]]; brush.addPlane(maxs, planepts1, planepts2, shader, projection); } } { for (int i = 0; i < 3; ++i) { Vector3 planepts1(mins); Vector3 planepts2(mins); planepts1[box[i][0]] = maxs[box[i][0]]; planepts2[box[i][1]] = maxs[box[i][1]]; brush.addPlane(mins, planepts1, planepts2, shader, projection); } } }
void mergeSelectedBrushes(const cmd::ArgumentList& args) { // Get the current selection BrushPtrVector brushes = selection::algorithm::getSelectedBrushes(); if (brushes.empty()) { rMessage() << _("CSG Merge: No brushes selected.") << std::endl; wxutil::Messagebox::ShowError(_("CSG Merge: No brushes selected.")); return; } if (brushes.size() < 2) { rMessage() << "CSG Merge: At least two brushes have to be selected.\n"; wxutil::Messagebox::ShowError("CSG Merge: At least two brushes have to be selected."); return; } rMessage() << "CSG Merge: Merging " << brushes.size() << " brushes." << std::endl; UndoableCommand undo("mergeSelectedBrushes"); // Take the last selected node as reference for layers and parent scene::INodePtr merged = GlobalSelectionSystem().ultimateSelected(); scene::INodePtr parent = merged->getParent(); assert(parent != NULL); // Create a new BrushNode scene::INodePtr node = GlobalBrushCreator().createBrush(); // Insert the newly created brush into the (same) parent entity parent->addChildNode(node); // Move the new brush to the same layers as the merged one node->assignToLayers(merged->getLayers()); // Get the contained brush Brush* brush = Node_getBrush(node); // Attempt to merge the selected brushes into the new one if (!Brush_merge(*brush, brushes, true)) { rWarning() << "CSG Merge: Failed - result would not be convex." << std::endl; return; } ASSERT_MESSAGE(!brush->empty(), "brush left with no faces after merge"); // Remove the original brushes for (BrushPtrVector::iterator i = brushes.begin(); i != brushes.end(); ++i) { scene::removeNodeFromParent(*i); } // Select the new brush Node_setSelected(node, true); rMessage() << "CSG Merge: Succeeded." << std::endl; SceneChangeNotify(); }
void Brush_ConstructCuboid(Brush& brush, const AABB& bounds, const char* shader, const TextureProjection& projection) { const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } }; Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents)); Vector3 maxs(vector3_added(bounds.origin, bounds.extents)); brush.undoSave(); brush.clear(); brush.reserve(6); { for(int i=0; i < 3; ++i) { Vector3 planepts1(maxs); Vector3 planepts2(maxs); planepts2[box[i][0]] = mins[box[i][0]]; planepts1[box[i][1]] = mins[box[i][1]]; brush.addPlane(maxs, planepts1, planepts2, shader, projection); } } { for(int i=0; i < 3; ++i) { Vector3 planepts1(mins); Vector3 planepts2(mins); planepts1[box[i][0]] = maxs[box[i][0]]; planepts2[box[i][1]] = maxs[box[i][1]]; brush.addPlane(mins, planepts1, planepts2, shader, projection); } } }
void MenuImageItem::onDraw() { Brush* brush = Brush::getSingletonPtr(); brush->setFilterMode(mDesc->widget_brushFilterMode); brush->drawSkinElement(Rect(mTexturePosition,mWidgetDesc->widget_dimensions.size),mSkinElement); }
void DrawFilledRectangle(PixelScalar left, PixelScalar top, PixelScalar right, PixelScalar bottom, const Brush &brush) { if (brush.IsHollow()) return; DrawFilledRectangle(left, top, right, bottom, brush.GetColor()); }
//------------------------------------------------------------------------------ void Canvas::DrawFilledRectangle(int left, int top, int right, int bottom, const Brush &brush) { if (!brush.IsHollow()) this->DrawFilledRectangle(left, top, right, bottom, brush.GetColor()); }
void MenuPanel::onDraw() { Brush* brush = Brush::getSingletonPtr(); brush->setFilterMode(mDesc->widget_brushFilterMode); brush->drawSkinElement(Rect(Point::ZERO,mWidgetDesc->widget_dimensions.size),mSkinElement); }
void Border::Render (cairo_t *cr, Region *region, bool path_only) { Brush *background = GetBackground (); Brush *border_brush = GetBorderBrush (); cairo_save (cr); if (!path_only) RenderLayoutClip (cr); CornerRadius r = *GetCornerRadius (); CornerRadius *round = &r; Thickness thickness = *GetBorderThickness (); Rect paint_border = extents; Rect paint_background = paint_border.GrowBy (-thickness); CornerRadius inner_adjusted = *round; inner_adjusted.topLeft = MAX (round->topLeft - MAX (thickness.left, thickness.top) * .5, 0); inner_adjusted.topRight = MAX (round->topRight - MAX (thickness.right, thickness.top) * .5, 0); inner_adjusted.bottomRight = MAX (round->bottomRight - MAX (thickness.right, thickness.bottom) * .5, 0); inner_adjusted.bottomLeft = MAX (round->bottomLeft - MAX (thickness.left, thickness.bottom) * .5, 0); CornerRadius outer_adjusted = *round; outer_adjusted.topLeft = outer_adjusted.topLeft ? MAX (round->topLeft + MAX (thickness.left, thickness.top) * .5, 0) : 0; outer_adjusted.topRight = outer_adjusted.topRight ? MAX (round->topRight + MAX (thickness.right, thickness.top) * .5, 0) : 0; outer_adjusted.bottomRight = outer_adjusted.bottomRight ? MAX (round->bottomRight + MAX (thickness.right, thickness.bottom) * .5, 0) : 0; outer_adjusted.bottomLeft = outer_adjusted.bottomLeft ? MAX (round->bottomLeft + MAX (thickness.left, thickness.bottom) * .5, 0) : 0; /* * NOTE filling this way can leave alpha artifacts between the border fill and bg fill * but some simple inspection of the ms results make me think that is what happens there * too. */ cairo_new_path (cr); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); if (border_brush && !paint_border.IsEmpty ()) { border_brush->SetupBrush (cr, paint_border); paint_border.Draw (cr, &outer_adjusted); paint_background.Draw (cr, &inner_adjusted); if (!path_only) border_brush->Fill (cr); } if (background && !paint_background.IsEmpty ()) { background->SetupBrush (cr, paint_background); paint_background.Draw (cr, &inner_adjusted); if (!path_only) background->Fill (cr); } cairo_restore (cr); }
// virtual void Polyline::OnRender(Graphics* pGraphics) { PointCollection* points = get_Points(); if (points) { unsigned int count = points->GetCount(); if (count > 0) { __release<LDraw::GraphicsPathF> path = new LDraw::GraphicsPathF; Point point = points->get_Item(0); path->AddMove(point.X, point.Y); for (unsigned int i = 1; i < count; i++) { point = points->get_Item(i); path->AddLine(point.X, point.Y); } Brush* Fill = get_Fill(); if (Fill) { __release<LDraw::Brush> brush = Fill->CreateBrush(this, 1, 1); if (brush != NULL) { pGraphics->FillPath(brush, path); } } #if 0 double StrokeThickness; if (m_StrokeThickness) m_StrokeThickness->get_Value(&StrokeThickness); else StrokeThickness = 1; if (StrokeThickness > 0) { CComQIPtr<CLXUIElementImplImpl> Stroke(m_Stroke); if (Stroke) { Gdiplus::Brush* pBrush = Stroke->CreateBrush(this, 1, 1); if (pBrush) { Gdiplus::Pen pen(pBrush, StrokeThickness); pGraphics->DrawPath(pen, &path); delete pBrush; } } } #endif } } }
Rect Canvas::GetCoverageBounds () { Brush *background = GetBackground (); if (background && background->IsOpaque ()) return coverage_bounds; return Rect (); }
bool Brush_hasShader(const Brush& brush, const char* name) { for(Brush::const_iterator i = brush.begin(); i != brush.end(); ++i) { if(shader_equal((*i)->GetShader(), name)) { return true; } } return false; }
void Cone::generate (Brush& brush, const AABB& bounds, std::size_t sides, const TextureProjection& projection, const std::string& shader) { if (sides < _minSides) { gtkutil::errorDialog(_("Too few sides for constructing the prism, minimum is 3")); return; } if (sides > _maxSides) { gtkutil::errorDialog(_("Too many sides for constructing the prism, maximum is 32")); return; } brush.clear(); brush.reserve(sides + 1); Vector3 mins(bounds.origin - bounds.extents); Vector3 maxs(bounds.origin + bounds.extents); float radius = maxExtent(bounds.extents); const Vector3& mid = bounds.origin; Vector3 planepts[3]; planepts[0][0] = mins[0]; planepts[0][1] = mins[1]; planepts[0][2] = mins[2]; planepts[1][0] = maxs[0]; planepts[1][1] = mins[1]; planepts[1][2] = mins[2]; planepts[2][0] = maxs[0]; planepts[2][1] = maxs[1]; planepts[2][2] = mins[2]; brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); for (std::size_t i = 0; i < sides; ++i) { double sv = sin(i * 3.14159265 * 2 / sides); double cv = cos(i * 3.14159265 * 2 / sides); planepts[0][0] = static_cast<float> (floor(mid[0] + radius * cv + 0.5)); planepts[0][1] = static_cast<float> (floor(mid[1] + radius * sv + 0.5)); planepts[0][2] = mins[2]; planepts[1][0] = mid[0]; planepts[1][1] = mid[1]; planepts[1][2] = maxs[2]; planepts[2][0] = static_cast<float> (floor(planepts[0][0] - radius * sv + 0.5)); planepts[2][1] = static_cast<float> (floor(planepts[0][1] + radius * cv + 0.5)); planepts[2][2] = maxs[2]; brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); } }
bool Brush::intersectsBrush(const Brush& brush) const { if (!bounds().intersects(brush.bounds())) return false; // separating axis theorem // http://www.geometrictools.com/Documentation/MethodOfSeparatingAxes.pdf FaceList::const_iterator faceIt, faceEnd; const VertexList& myVertices = vertices(); const FaceList& theirFaces = brush.faces(); for (faceIt = theirFaces.begin(), faceEnd = theirFaces.end(); faceIt != faceEnd; ++faceIt) { const Face& theirFace = **faceIt; const Vec3f& origin = theirFace.vertices().front()->position; const Vec3f& direction = theirFace.boundary().normal; if (vertexStatusFromRay(origin, direction, myVertices) == PointStatus::PSAbove) return false; } const VertexList& theirVertices = brush.vertices(); for (faceIt = m_faces.begin(), faceEnd = m_faces.end(); faceIt != faceEnd; ++faceIt) { const Face& myFace = **faceIt; const Vec3f& origin = myFace.vertices().front()->position; const Vec3f& direction = myFace.boundary().normal; if (vertexStatusFromRay(origin, direction, theirVertices) == PointStatus::PSAbove) return false; } const EdgeList& myEdges = edges(); const EdgeList& theirEdges = brush.edges(); EdgeList::const_iterator myEdgeIt, myEdgeEnd, theirEdgeIt, theirEdgeEnd; for (myEdgeIt = myEdges.begin(), myEdgeEnd = myEdges.end(); myEdgeIt != myEdgeEnd; ++myEdgeIt) { const Edge& myEdge = **myEdgeIt; for (theirEdgeIt = theirEdges.begin(), theirEdgeEnd = theirEdges.end(); theirEdgeIt != theirEdgeEnd; ++theirEdgeIt) { const Edge& theirEdge = **theirEdgeIt; const Vec3f myEdgeVec = myEdge.vector(); const Vec3f theirEdgeVec = theirEdge.vector(); const Vec3f& origin = myEdge.start->position; const Vec3f direction = crossed(myEdgeVec, theirEdgeVec); PointStatus::Type myStatus = vertexStatusFromRay(origin, direction, myVertices); if (myStatus != PointStatus::PSInside) { PointStatus::Type theirStatus = vertexStatusFromRay(origin, direction, theirVertices); if (theirStatus != PointStatus::PSInside) { if (myStatus != theirStatus) return false; } } } } return true; }
BrushSplitType Brush_classifyPlane(const Brush& brush, const Plane3& plane) { brush.evaluateBRep(); BrushSplitType split; for (Brush::const_iterator i(brush.begin()); i != brush.end(); ++i) { if ((*i)->contributes()) { split += (*i)->getWinding().classifyPlane(plane); } } return split; }
void Brush_ConstructSphere(Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection) { if(sides < c_brushSphere_minSides) { globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned(sides) << ": too few sides, minimum is " << Unsigned(c_brushSphere_minSides) << "\n"; return; } if(sides > c_brushSphere_maxSides) { globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned(sides) << ": too many sides, maximum is " << Unsigned(c_brushSphere_maxSides) << "\n"; return; } brush.undoSave(); brush.clear(); brush.reserve(sides*sides); float radius = max_extent(bounds.extents); const Vector3& mid = bounds.origin; Vector3 planepts[3]; double dt = 2 * c_pi / sides; double dp = c_pi / sides; for(std::size_t i=0; i < sides; i++) { for(std::size_t j=0;j < sides-1; j++) { double t = i * dt; double p = float(j * dp - c_pi / 2); planepts[0] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t, p), radius)); planepts[1] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t, p + dp), radius)); planepts[2] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t + dt, p + dp), radius)); brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); } } { double p = (sides - 1) * dp - c_pi / 2; for(std::size_t i = 0; i < sides; i++) { double t = i * dt; planepts[0] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t, p), radius)); planepts[1] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t + dt, p + dp), radius)); planepts[2] = vector3_added(mid, vector3_scaled(vector3_for_spherical(t + dt, p), radius)); brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); } } }
/** void Brush::setStyle(int style) * include/mimas/Brush.h:56 */ static int Brush_setStyle(lua_State *L) { try { Brush *self = *((Brush **)dub_checksdata(L, 1, "mimas.Brush")); int style = dub_checkint(L, 2); self->setStyle(style); return 0; } catch (std::exception &e) { lua_pushfstring(L, "setStyle: %s", e.what()); } catch (...) { lua_pushfstring(L, "setStyle: Unknown exception"); } return dub_error(L); }
/** void Brush::setColor(const Color &color) * include/mimas/Brush.h:60 */ static int Brush_setColor(lua_State *L) { try { Brush *self = *((Brush **)dub_checksdata(L, 1, "mimas.Brush")); Color *color = *((Color **)dub_checksdata(L, 2, "mimas.Color")); self->setColor(*color); return 0; } catch (std::exception &e) { lua_pushfstring(L, "setColor: %s", e.what()); } catch (...) { lua_pushfstring(L, "setColor: Unknown exception"); } return dub_error(L); }
void Brush_ConstructCone(Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection) { if(sides < c_brushCone_minSides) { globalErrorStream() << c_brushCone_name << ": sides " << Unsigned(sides) << ": too few sides, minimum is " << Unsigned(c_brushCone_minSides) << "\n"; return; } if(sides > c_brushCone_maxSides) { globalErrorStream() << c_brushCone_name << ": sides " << Unsigned(sides) << ": too many sides, maximum is " << Unsigned(c_brushCone_maxSides) << "\n"; return; } brush.undoSave(); brush.clear(); brush.reserve(sides+1); Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents)); Vector3 maxs(vector3_added(bounds.origin, bounds.extents)); float radius = max_extent(bounds.extents); const Vector3& mid = bounds.origin; Vector3 planepts[3]; planepts[0][0] = mins[0];planepts[0][1] = mins[1];planepts[0][2] = mins[2]; planepts[1][0] = maxs[0];planepts[1][1] = mins[1];planepts[1][2] = mins[2]; planepts[2][0] = maxs[0];planepts[2][1] = maxs[1];planepts[2][2] = mins[2]; brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); for (std::size_t i=0 ; i<sides ; ++i) { double sv = sin (i*3.14159265*2/sides); double cv = cos (i*3.14159265*2/sides); planepts[0][0] = static_cast<float>(floor(mid[0]+radius*cv+0.5)); planepts[0][1] = static_cast<float>(floor(mid[1]+radius*sv+0.5)); planepts[0][2] = mins[2]; planepts[1][0] = mid[0]; planepts[1][1] = mid[1]; planepts[1][2] = maxs[2]; planepts[2][0] = static_cast<float>(floor(planepts[0][0] - radius * sv + 0.5)); planepts[2][1] = static_cast<float>(floor(planepts[0][1] + radius * cv + 0.5)); planepts[2][2] = maxs[2]; brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); } }
void ListTextItem::onDraw() { Brush* brush = Brush::getSingletonPtr(); brush->setFilterMode(mDesc->widget_brushFilterMode); brush->drawSkinElement(Rect(mTexturePosition,mWidgetDesc->widget_dimensions.size),mSkinElement); ColourValue prevColor = brush->getColour(); Rect prevClipRegion = brush->getClipRegion(); // Clip to client dimensions Rect clipRegion(mClientDimensions); clipRegion.translate(mTexturePosition); brush->setClipRegion(prevClipRegion.getIntersection(clipRegion)); // Adjust Rect to Text drawing region clipRegion = mClientDimensions; clipRegion.translate(mTexturePosition); mText->draw(clipRegion.position); brush->setClipRegion(prevClipRegion); brush->setColor(prevColor); }
void MapExporter::recalculateBrushWindings() { _root->foreachNode([] (const scene::INodePtr& child)->bool { Brush* brush = Node_getBrush(child); if (brush != NULL) { brush->evaluateBRep(); } return true; }); }
bool Brush::containsBrush(const Brush& brush) const { if (bounds().contains(brush.bounds())) return false; const VertexList& theirVertices = brush.vertices(); VertexList::const_iterator vertexIt, vertexEnd; for (vertexIt = theirVertices.begin(), vertexEnd = theirVertices.end(); vertexIt != vertexEnd; ++vertexIt) { const Vertex& vertex = **vertexIt; if (!containsPoint(vertex.position)) return false; } return true; }
void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::size_t sides, const std::string& shader) { if(GlobalSelectionSystem().countSelected() != 0) { const scene::INodePtr& node = GlobalSelectionSystem().ultimateSelected(); Brush* brush = Node_getBrush(node); if(brush != 0) { AABB bounds = brush->localAABB(); // copy bounds because the brush will be modified Brush_ConstructPrefab(*brush, type, bounds, sides, shader, TextureTransform_getDefault()); SceneChangeNotify(); } } }
void saveBrushToImage(const Brush& brush, Image& image) { // save brush as a 16bit grayscale image #if OGRE_VERSION_MINOR > 4 ushort* data = (ushort*)OGRE_ALLOC_T(uchar, brush.getWidth()*brush.getHeight()*sizeof(ushort), MEMCATEGORY_GENERAL); #else ushort* data = (ushort*)new uchar[brush.getWidth()*brush.getHeight()*sizeof(ushort)]; #endif for (size_t x = 0; x < brush.getWidth(); ++x) for (size_t y = 0; y < brush.getHeight(); ++y) data[y*brush.getWidth() + x] = ushort(brush.at(x, y) * 0xffff); // pass the data to the image, image takes over ownership image.loadDynamicImage((uchar*)data, brush.getWidth(), brush.getHeight(), 1, PF_L16, true); }
void Brush::restore(const Brush& brushTemplate, bool checkId) { if (checkId) assert(uniqueId() == brushTemplate.uniqueId()); Utility::deleteAll(m_faces); const FaceList templateFaces = brushTemplate.faces(); for (size_t i = 0; i < templateFaces.size(); i++) { Face* face = new Face(m_worldBounds, m_forceIntegerFacePoints, *templateFaces[i]); face->setBrush(this); m_faces.push_back(face); } rebuildGeometry(); }
LRESULT ContainerWindow::on_message(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CTLCOLORSTATIC: case WM_CTLCOLORBTN: { Window *window = Window::get((HWND)lParam); if (window == NULL) break; Canvas canvas((HDC)wParam, 1, 1); Brush *brush = on_color(*window, canvas); if (brush == NULL) break; return (LRESULT)brush->native(); } case WM_DRAWITEM: /* forward WM_DRAWITEM to the child window who sent this message */ { const DRAWITEMSTRUCT *di = (const DRAWITEMSTRUCT *)lParam; Window *window = Window::get(di->hwndItem); if (window == NULL) break; Canvas canvas(di->hDC, di->rcItem.right - di->rcItem.left, di->rcItem.bottom - di->rcItem.top); window->on_paint(canvas); return TRUE; } case WM_COMMAND: if (wParam == MAKEWPARAM(BaseButtonWindow::COMMAND_BOUNCE_ID, BN_CLICKED)) { /* forward this message to ButtonWindow::on_clicked() */ BaseButtonWindow *window = (BaseButtonWindow *)Window::get((HWND)lParam); if (window != NULL && window->on_clicked()) return true; } break; }; return PaintWindow::on_message(hWnd, message, wParam, lParam); }