选择和修改早期在DC中绘制的特定形状 [英] Selecting and modifying particular shapes drawn earlier in DC

查看:124
本文介绍了选择和修改早期在DC中绘制的特定形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在开发一个应用程序,一个绘图工具,我已经打了一半。

这个工具基本上是一个绘图工具。我使用GDI绘制到Device上下文。

我有各种形状的绘图要求,如直线,圆形,多边形等。



我在onDraw()事件上完成的绘图部分和工作。



绘制形状后,我想修改同一个对象。



关于如何用鼠标选择以前的形状,然后拖动,移动,调整大小等。



请帮帮我。



谢谢

Hi
I am developing an application, a drawing tool, in which I have struck half the way.
This tool is one drawing tool basically. I have used GDI for drawing to Device context.
I have various shapes drawing requirements like lines, circles, polygons etc.

The drawing part I have done on the onDraw() event and working.

Once the shapes are drawn, later I wants to modify the same object.

For that how to select the previous shapes with mouse and then drag, move, resize etc.

Please help me in this.

Thanks

推荐答案

我可以建议一种从DC识别绘制对象并修改它的方法。



但您可以通过以下设计实现上述要求(更改绘制对象的形状)。

为每个图形项目准备单独的类,像Rectangle,Line,Triangle等。这些类应该从一个公共基类派生,比如 GraphicBase

I can’t suggest a method to identify the drawn object from DC and modify the same.

But you can implement the above requirements (change shape of drawn objects) by following design.
Prepare separate classes for each graphic item, like Rectangle, Line, Triangle etc. These classes should be derived from a common base class, say it GraphicBase.
class GraphicBase
{
public:
    GraphicBase(void);
    ~GraphicBase(void);

    virtual void Draw();
    virtual bool IsInside( POINT ptMousePos);
    virtual void MouseMove( POINT ptMousePos);
};







// Derived from GraphicBase to draw a Rectangle
class GraphicRectangle: public GraphicBase
{
public:
    GraphicRectangle(void);
    ~GraphicRectangle(void);

    void Draw();
    bool IsInside(POINT ptMousePos);
    void MouseMove( POINT ptMousePos);

private:
    RECT m_Position; // Position of graphic item. This wil be used to draw Rectangle.
    
};

这里Draw()用于绘制图形对象。 IsInside()用于标识对象是否在图形对象内。 MouseMove()LButtonDown()和LButtonUp用于调整图形项的大小。

主类(Dlg类)将所有图形项保存在列表中,每当鼠标在Dlg类中重现时,它将调用所有图形项的IsInside()来识别需要调整大小的图形项。把它称为m_pActiveGraphicItem。之后,鼠标移动消息将发送到活动图形项m_pActiveGraphicItem。识别鼠标移动的变化以应用图形项的调整大小动作。每当在Dlg类中收到鼠标时,它将停止调整大小动作[通过将 m_pActiveGraphicItem 指定为NULL]。

每次鼠标移动后,使整个客户区无效以重绘所有图形项。

Dlg类的OnPaint()将是这样的

Here Draw() is used to draw a graphic object. IsInside() is used to identify whether an object is inside the graphic object. MouseMove() LButtonDown() and LButtonUp is used to resize the graphic item.
Main class( Dlg class) will hold all graphic items in a list, and whenever a mouse down recives in Dlg class, it will call IsInside() of all graphic items to idntify the graphic item need to be resized. Say it as m_pActiveGraphicItem. After that mouse move messages will send to the active graphic item, m_pActiveGraphicItem. The change in mouse movement is identified to apply resize action of the graphic item. Whenever mouse up received in Dlg class, it will stop resize action[By assigning m_pActiveGraphicItem as NULL].
After each mouse movement, invalidating the entire client area to redraw all graphic items.
OnPaint() of Dlg class will be like this

Dlg::OnPaint()
{
for( i=0;m_GraphicItems.size(); i++)
{
M_pGraphicItems[i]->Draw(); // To draw graphic item
}
}



GraphicRectangle :: MouseMove()应该重新计算 m_Position 以重新绘制新的矩形尺寸。预期的DC应该以任何方法共享给所有Graphic项目,作为静态成员函数,或者将其保存为 GraphicBase 中的受保护成员。



每个图形项的IsInside()应该返回传入点是否在图形项内。请使用HRGN或其他方法识别鼠标位置在图形项目区域内。


GraphicRectangle::MouseMove() should recalculate m_Position to redraw the rectangle in new size. The intended DC should be shared to all Graphic items in any method, as static member function, or keep it as a protected member in GraphicBase.

IsInside() of each graphic item should return whether incoming point is inside the graphic item or not. Please use HRGN or other method to identify the mouse position is inside the region of graphic item.


这篇关于选择和修改早期在DC中绘制的特定形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆