For writing own DisplayObjects the DisplayObject and DisplayObjectContainer are the base class for all objects that are able to be added to the screen.

The DisplayObject represents a leaf. A DisplayObjectContainer are used for storing other leafs. A DisplayObjectContainer can hold other DisplayObjectContainer, so that hierarchies can be built easily.

ConcretDisplayObject.h

#include "Objects\display\DisplayObject.h"

using namespace D2;

class CheckBox : public DisplayObject {
public:
    ConcretDisplayObject(int x, int y, int width, int height);
    virtual ~ConcretDisplayObject(void);

    virtual bool Draw(Direct2DContext* ctx, D2D1::Matrix3x2F* mtx = 0);
    
   //virtual void OnMouseOver(const MouseEvent &e);
   //virtual void OnMouseOut(const MouseEvent &e); 
   //virtual void OnMouseDown0(const MouseEvent &e); 
//virtual void OnMouseUp0(const MouseEvent &e);

//...
};

ConcretDisplayObject.cpp

ConcretDisplayObject::ConcretDisplayObject(int x, int y, int width, int height) : DisplayObject(x, y, width, height) {

}

ConcretDisplayObject::~ConcretDisplayObject(void) {
}

bool ConcretDisplayObject::Draw(Direct2DContext* ctx, D2D1::Matrix3x2F* mtx) {
   //draw code

   return true;
}
/* 
void ConcretDisplayObject::OnMouseOver(const MouseEvent &e) { }
void ConcretDisplayObject::OnMouseOut(const MouseEvent &e) { }
void ConcretDisplayObject::OnMouseDown0(const MouseEvent &e) { }
void ConcretDisplayObject::OnMouseUp0(const MouseEvent &e) { }
...
*/

For notify events there a several build-in methods that can be integrated.

    virtual void OnAdded(const Event &e);
    virtual void OnRemoved(const Event &e);
    virtual void OnAddedToStage(const Event &e);
    virtual void OnRemovedFromStage(const Event &e);

    virtual void OnKeyUp(const KeyboardEvent &e);
    virtual void OnKeyDown(const KeyboardEvent &e);

    virtual void OnMouseMove(const MouseEvent &e);
    virtual void OnMouseWheel(const MouseEvent &e);

    virtual void OnMouseOver(const MouseEvent &e);
    virtual void OnMouseOut(const MouseEvent &e);

    virtual void OnFocusLost(const MouseEvent &e);

    virtual void OnMouseDown0(const MouseEvent &e);
    virtual void OnMouseUp0(const MouseEvent &e);
    virtual void OnMouseLeave0(const MouseEvent &e);
    virtual void OnMouseRaise0(const MouseEvent &e);
    virtual void OnMouseDrag0(const MouseEvent &e);
    virtual void OnMouseDoubleClick0(const MouseEvent &e);

    virtual void OnMouseDown1(const MouseEvent &e);
    virtual void OnMouseUp1(const MouseEvent &e);
    virtual void OnMouseLeave1(const MouseEvent &e);
    virtual void OnMouseRaise1(const MouseEvent &e);
    virtual void OnMouseDrag1(const MouseEvent &e);
    virtual void OnMouseDoubleClick1(const MouseEvent &e);

    virtual void OnMouseDown2(const MouseEvent &e);
    virtual void OnMouseUp2(const MouseEvent &e);
    virtual void OnMouseLeave2(const MouseEvent &e);
    virtual void OnMouseRaise2(const MouseEvent &e);
    virtual void OnMouseDrag2(const MouseEvent &e);
    virtual void OnMouseDoubleClick2(const MouseEvent &e);

    virtual void OnMouseDown3(const MouseEvent &e);
    virtual void OnMouseUp3(const MouseEvent &e);
    virtual void OnMouseLeave3(const MouseEvent &e);
    virtual void OnMouseRaise3(const MouseEvent &e);
    virtual void OnMouseDrag3(const MouseEvent &e);
    virtual void OnMouseDoubleClick3(const MouseEvent &e);

    virtual void OnMouseDown4(const MouseEvent &e);
    virtual void OnMouseUp4(const MouseEvent &e);
    virtual void OnMouseLeave4(const MouseEvent &e);
    virtual void OnMouseRaise4(const MouseEvent &e);
    virtual void OnMouseDrag4(const MouseEvent &e);
    virtual void OnMouseDoubleClick4(const MouseEvent &e);

As we can derive from a DisplayObject we can derive from DisplayObjectContainer, because a DisplayObjectContainer is a DisplayObject. We can use a container instead of building a leaf object.

Last edited Mar 28, 2013 at 11:54 AM by TypeOverride, version 25

Comments

No comments yet.