Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualekimr

Posted 21 March 2012 - 06:47 AM

Sorry it took me so long. Work. Here is what I have.

The class type is END_MenuItem, and the function name is the same, so I am assuming it is the constructor. I don't know if script functions are being called at this point or not, but if that is the case then they shouldn't be because I took out all instances of the class to debug this problem.

The class is a hierarchy involving a subclass and an interface. See their code below.

funcdef void END_MENUITEM_FUNC(END_MenuItem@ item);

class END_MenuItem : Widget
{
	private Vector3 m_DrawColor;
	private END_MENUITEM_FUNC@ m_Func;

	 private string@ m_Font;
	private string@ m_Text;
	private int mSize;
	private bool bStringMeasured;

	END_MenuItem(string@ font,int size,string@ txt,END_MENUITEM_FUNC@ f)
	{
		END_MenuMode mode = END_MenuMode::MAIN;

		@m_Func = @f;

		@m_Font = @font;
		@m_Text = @txt;
		mSize = size;
		m_DrawColor = RGBA( 255,255,255,255 );

		bStringMeasured = false;
	}

	void OnMousePressed(Mouse mouse)
	{
		// Left Mouse Button
		if(mouse == Mouse::ONE) {
		}
	}

	void OnMouseReleased(Mouse mouse)
	{
	}

	void OnRender()
	{
		Canvas@ c = Canvas();
		c.DrawString( m_Font,Position,m_DrawColor,mSize,m_Text );
	}

	void SetText( string@ txt ) { m_Text = txt; }
};


	class Widget : IWidget
	{
		private IWidget@		mParent;
		private Rect			mGeometry;
		private Vector2		 mPosition;
		private bool			bIsVisible;
		private uint			uiZOrder;
		private array<IWidget@> arrChildren;

		Widget( IWidget@ parent = null )
	 {
@mParent = @parent;

if(mParent is null) {
@mParent = Ir_GUIRoot.Root;
}
bIsVisible = true;
}

bool OnUpdate(float delta_t)			{ return false; }
bool OnRender()						 { return false; }
bool OnDestroyed()					  { return false; }
bool OnCharInsert(uint8 ch)			 { return false; }
bool OnKeyPressed(Keys key)			  { return false; }
bool OnKeyReleased(Keys key)			 { return false; }
bool OnMouseMoved(const Vector2&in delta) { return false; }
bool OnMousePressed(Mouse mouse)		{ return false; }
bool OnMouseReleased(Mouse mouse)	   { return false; }

bool Update(float delta_t) final
{
for(uint i=0;i<arrChildren.length;i++)
{
arrChildren[i].OnUpdate(delta_t);
}
return false;
}

bool Render() final
{
for(uint i=0;i<arrChildren.length;i++)
{
if(arrChildren[i].IsVisible)
arrChildren[i].OnRender();
}
return false;
}

bool Destroyed() final
{
for(uint i=0;i<arrChildren.length;i++)
{
arrChildren[i].OnDestroyed();
}
return true;
}

bool CharInsert(uint8 ch) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
if(arrChildren[i].CharInsert(ch)) {
return true;
}
}
return OnCharInsert(ch);
}

bool KeyPressed(Keys key) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
if(arrChildren[i].KeyPressed(key)) {
return true;
}
}
return OnKeyPressed(key);
}

bool KeyReleased(Keys key) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
if(arrChildren[i].KeyReleased(key)) {
return true;
}
}
return OnKeyReleased(key);
}

bool MouseMoved(const Vector2&in delta) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
arrChildren[i].MouseMoved(delta);
}
OnMouseMoved(delta);
return false;
}

bool MousePressed(Mouse mouse) final
{
for(uint i=0;i<arrChildren.length;i++)
{
// Short Circuit
if(arrChildren[i].MousePressed(mouse)) {
return true;
}
}
return OnMousePressed(mouse);
}

	bool MouseReleased(Mouse mouse) final
	{
		for(uint i=0;i<arrChildren.length;i++)
		{
			// Short Circuit
			if(arrChildren[i].MousePressed(mouse)) {
				return true;
			}
		}
		return false;
	}

	// Methods
	void AddChild( IWidget@ widget )
	{
		for(uint i=0;i<arrChildren.length;i++)
		{
IWidget@ child = arrChildren[i];

if(widget.ZOrder < child.ZOrder) {
arrChildren.insertAt(i,widget);
break;
}
}
}


// Properties.
IWidget@ Parent {
get const { return mParent; }
}
Vector2 Position {
get const { return mPosition; }
set	   { mPosition = value; }
}
Rect Geometry {
get const { return mGeometry; }
		set	   { mGeometry = value; }
	}
	bool IsVisible {
		get const { return bIsVisible; }
		set	   { bIsVisible = value; }
	}
	uint ZOrder {
		get const { return uiZOrder; }
		set	   { uiZOrder = value; }
	}
};

interface IWidget
{
	bool Update(float delta_t);
	bool Render();
	bool Destroyed();
	bool CharInsert(uint8 ch);
	bool KeyPressed(Keys key);
	bool KeyReleased(Keys key);
	bool MouseMoved(const Vector2&in delta);
	bool MousePressed(Mouse mouse);
	bool MouseReleased(Mouse mouse);

	// Event callbacks.
	bool OnUpdate(float delta_t);
	bool OnRender();
	bool OnDestroyed();
	bool OnCharInsert(uint8 ch);
	bool OnKeyPressed(Keys key);
	bool OnKeyReleased(Keys key);
	bool OnMouseMoved(const Vector2&in delta);
	bool OnMousePressed(Mouse mouse);
	bool OnMouseReleased(Mouse mouse);

	// Methods
	void AddChild( IWidget@ widget );

	// Properties.
	IWidget@ Parent	{ get const;	  }
	Vector2  Position  { get const; set; }
	Rect	 Geometry  { get const; set; }
	bool	 IsVisible { get const; set; }
	uint	 ZOrder	{ get const; set; }
};

EDIT: Just as I thought, excluding the file that defined END_MenuItem allows the program to run.

#2ekimr

Posted 21 March 2012 - 06:42 AM

Sorry it took me so long. Work. Here is what I have.

The class type is END_MenuItem, and the function name is the same, so I am assuming it is the constructor. I don't know if script functions are being called at this point or not, but if that is the case then they shouldn't be because I took out all instances of the class to debug this problem.

The class is a hierarchy involving a subclass and an interface. See their code below.

funcdef void END_MENUITEM_FUNC(END_MenuItem@ item);

class END_MenuItem : Widget
{
    private Vector3 m_DrawColor;
    private END_MENUITEM_FUNC@ m_Func;

     private string@ m_Font;
    private string@ m_Text;
    private int mSize;
    private bool bStringMeasured;

    END_MenuItem(string@ font,int size,string@ txt,END_MENUITEM_FUNC@ f)
    {
        END_MenuMode mode = END_MenuMode::MAIN;

        @m_Func = @f;

        @m_Font = @font;
        @m_Text = @txt;
        mSize = size;
        m_DrawColor = RGBA( 255,255,255,255 );

        bStringMeasured = false;
    }
 
    void OnMousePressed(Mouse mouse)
    {
        // Left Mouse Button
        if(mouse == Mouse::ONE) {
        }
    }

    void OnMouseReleased(Mouse mouse)
    {
    }

    void OnRender()
    {
        Canvas@ c = Canvas();
        c.DrawString( m_Font,Position,m_DrawColor,mSize,m_Text );
    }

    void SetText( string@ txt ) { m_Text = txt; }
};


    class Widget : IWidget
    {
        private IWidget@		mParent;
        private Rect			mGeometry;
        private Vector2		 mPosition;
        private bool			bIsVisible;
        private uint			uiZOrder;
        private array<IWidget@> arrChildren;

        Widget( IWidget@ parent = null )
	 {
@mParent = @parent;

if(mParent is null) {
@mParent = Ir_GUIRoot.Root;
}
bIsVisible = true;
}

bool OnUpdate(float delta_t)			{ return false; }
bool OnRender()						 { return false; }
bool OnDestroyed()					  { return false; }
bool OnCharInsert(uint8 ch)			 { return false; }
bool OnKeyPressed(Keys key)			  { return false; }
bool OnKeyReleased(Keys key)			 { return false; }
bool OnMouseMoved(const Vector2&in delta) { return false; }
bool OnMousePressed(Mouse mouse)		{ return false; }
bool OnMouseReleased(Mouse mouse)	   { return false; }

bool Update(float delta_t) final
{
for(uint i=0;i<arrChildren.length;i++)
{
arrChildren[i].OnUpdate(delta_t);
}
return false;
}

bool Render() final
{
for(uint i=0;i<arrChildren.length;i++)
{
if(arrChildren[i].IsVisible)
arrChildren[i].OnRender();
}
return false;
}

bool Destroyed() final
{
for(uint i=0;i<arrChildren.length;i++)
{
arrChildren[i].OnDestroyed();
}
return true;
}

bool CharInsert(uint8 ch) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
if(arrChildren[i].CharInsert(ch)) {
return true;
}
}
return OnCharInsert(ch);
}

bool KeyPressed(Keys key) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
if(arrChildren[i].KeyPressed(key)) {
return true;
}
}
return OnKeyPressed(key);
}

bool KeyReleased(Keys key) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
if(arrChildren[i].KeyReleased(key)) {
return true;
}
}
return OnKeyReleased(key);
}

bool MouseMoved(const Vector2&in delta) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
arrChildren[i].MouseMoved(delta);
}
OnMouseMoved(delta);
return false;
}

bool MousePressed(Mouse mouse) final
{
for(uint i=0;i<arrChildren.length;i++)
{
// Short Circuit
if(arrChildren[i].MousePressed(mouse)) {
return true;
}
}
return OnMousePressed(mouse);
}

    bool MouseReleased(Mouse mouse) final
    {
        for(uint i=0;i<arrChildren.length;i++)
        {
            // Short Circuit
            if(arrChildren[i].MousePressed(mouse)) {
                return true;
            }
        }
        return false;
    }

    // Methods
    void AddChild( IWidget@ widget )
    {
        for(uint i=0;i<arrChildren.length;i++)
        {
IWidget@ child = arrChildren[i];

if(widget.ZOrder < child.ZOrder) {
arrChildren.insertAt(i,widget);
break;
}
}
}


// Properties.
IWidget@ Parent {
get const { return mParent; }
}
Vector2 Position {
get const { return mPosition; }
set	   { mPosition = value; }
}
Rect Geometry {
get const { return mGeometry; }
        set	   { mGeometry = value; }
    }
    bool IsVisible {
        get const { return bIsVisible; }
        set	   { bIsVisible = value; }
    }
    uint ZOrder {
        get const { return uiZOrder; }
        set	   { uiZOrder = value; }
    }
};

interface IWidget
{
    bool Update(float delta_t);
    bool Render();
    bool Destroyed();
    bool CharInsert(uint8 ch);
    bool KeyPressed(Keys key);
    bool KeyReleased(Keys key);
    bool MouseMoved(const Vector2&in delta);
    bool MousePressed(Mouse mouse);
    bool MouseReleased(Mouse mouse);

    // Event callbacks.
    bool OnUpdate(float delta_t);
    bool OnRender();
    bool OnDestroyed();
    bool OnCharInsert(uint8 ch);
    bool OnKeyPressed(Keys key);
    bool OnKeyReleased(Keys key);
    bool OnMouseMoved(const Vector2&in delta);
    bool OnMousePressed(Mouse mouse);
    bool OnMouseReleased(Mouse mouse);

    // Methods
    void AddChild( IWidget@ widget );

    // Properties.
    IWidget@ Parent	{ get const;	  }
    Vector2  Position  { get const; set; }
    Rect	 Geometry  { get const; set; }
    bool	 IsVisible { get const; set; }
    uint	 ZOrder	{ get const; set; }
};

#1ekimr

Posted 21 March 2012 - 06:36 AM

Sorry it took me so long. Work. Here is what I have.

The class type is END_MenuItem, and the function name is the same, so I am assuming it is the constructor. I don't know if script functions are being called at this point or not, but if that is the case then they shouldn't be because I took out all instances of the class to debug this problem.

The class is a hierarchy involving a subclass and an interface. See their code below.


class END_MenuItem : Widget
{
private Vector3 m_DrawColor;
private END_MENUITEM_FUNC@ m_Func;

private string@ m_Font;
private string@ m_Text; 
private int mSize;
private bool bStringMeasured;

END_MenuItem(string@ font,int size,string@ txt,END_MENUITEM_FUNC@ f)
{
END_MenuMode mode = END_MenuMode::MAIN;

@m_Func = @f;

@m_Font = @font;
@m_Text = @txt;
mSize = size;
m_DrawColor = RGBA( 255,255,255,255 );

bStringMeasured = false;
}

void OnMousePressed(Mouse mouse)
{
// Left Mouse Button
if(mouse == Mouse::ONE) {
}
}

void OnMouseReleased(Mouse mouse)
{
}

void OnRender()
{
Canvas@ c = Canvas();
c.DrawString( m_Font,Position,m_DrawColor,mSize,m_Text );
}

void SetText( string@ txt ) { m_Text = txt; }
};


class Widget : IWidget
{
private IWidget@        mParent;
private Rect            mGeometry;
private Vector2         mPosition;
private bool            bIsVisible;
private uint            uiZOrder;
private array<IWidget@> arrChildren;

Widget( IWidget@ parent = null )
{
@mParent = @parent;

if(mParent is null) {
@mParent = Ir_GUIRoot.Root;
}
bIsVisible = true;
}

bool OnUpdate(float delta_t)            { return false; }
bool OnRender()                         { return false; }
bool OnDestroyed()                      { return false; }
bool OnCharInsert(uint8 ch)             { return false; }
bool OnKeyPressed(Keys key)              { return false; }
bool OnKeyReleased(Keys key)             { return false; }
bool OnMouseMoved(const Vector2&in delta) { return false; }
bool OnMousePressed(Mouse mouse)        { return false; }
bool OnMouseReleased(Mouse mouse)       { return false; }

bool Update(float delta_t) final
{ 
for(uint i=0;i<arrChildren.length;i++) 
{ 
arrChildren[i].OnUpdate(delta_t); 
} 
return false;
}

bool Render() final
{ 
for(uint i=0;i<arrChildren.length;i++) 
{ 
if(arrChildren[i].IsVisible) 
arrChildren[i].OnRender(); 
} 
return false;
}

bool Destroyed() final
{
for(uint i=0;i<arrChildren.length;i++) 
{ 
arrChildren[i].OnDestroyed();
} 
return true;
}

bool CharInsert(uint8 ch) final
{ 
for(uint i=arrChildren.length-1;i>=0;i--) 
{ 
if(arrChildren[i].CharInsert(ch)) {
return true;
}
} 
return OnCharInsert(ch);
}

bool KeyPressed(Keys key) final
{ 
for(uint i=arrChildren.length-1;i>=0;i--) 
{ 
if(arrChildren[i].KeyPressed(key)) {
return true;
}
} 
return OnKeyPressed(key);
}

bool KeyReleased(Keys key) final
{ 
for(uint i=arrChildren.length-1;i>=0;i--) 
{ 
if(arrChildren[i].KeyReleased(key)) {
return true;
}
} 
return OnKeyReleased(key);
}

bool MouseMoved(const Vector2&in delta) final
{
for(uint i=arrChildren.length-1;i>=0;i--)
{
arrChildren[i].MouseMoved(delta);
}
OnMouseMoved(delta);
return false;
}

bool MousePressed(Mouse mouse) final
{ 
for(uint i=0;i<arrChildren.length;i++)
{
// Short Circuit
if(arrChildren[i].MousePressed(mouse)) {
return true;
}
}
return OnMousePressed(mouse);
}

bool MouseReleased(Mouse mouse) final
{
for(uint i=0;i<arrChildren.length;i++)
{
// Short Circuit
if(arrChildren[i].MousePressed(mouse)) {
return true;
}
}
return false;
}

// Methods
void AddChild( IWidget@ widget )
{
for(uint i=0;i<arrChildren.length;i++)
{
IWidget@ child = arrChildren[i];

if(widget.ZOrder < child.ZOrder) {
arrChildren.insertAt(i,widget);
break;
}
}
}


// Properties.
IWidget@ Parent { 
get const { return mParent; } 
}
Vector2 Position {
get const { return mPosition; }
set       { mPosition = value; }
}
Rect Geometry {
get const { return mGeometry; }
set       { mGeometry = value; }
}
bool IsVisible { 
get const { return bIsVisible; }
set       { bIsVisible = value; }
}
uint ZOrder {
get const { return uiZOrder; }
set       { uiZOrder = value; }
}
};


interface IWidget
{
bool Update(float delta_t);
bool Render();
bool Destroyed();
bool CharInsert(uint8 ch);
bool KeyPressed(Keys key);
bool KeyReleased(Keys key);
bool MouseMoved(const Vector2&in delta);
bool MousePressed(Mouse mouse);
bool MouseReleased(Mouse mouse);



// Event callbacks.
bool OnUpdate(float delta_t);
bool OnRender();
bool OnDestroyed();
bool OnCharInsert(uint8 ch);
bool OnKeyPressed(Keys key);
bool OnKeyReleased(Keys key);
bool OnMouseMoved(const Vector2&in delta);
bool OnMousePressed(Mouse mouse);
bool OnMouseReleased(Mouse mouse);

// Methods
void AddChild( IWidget@ widget );

// Properties.
IWidget@ Parent    { get const;      }
Vector2  Position  { get const; set; }
Rect     Geometry  { get const; set; }
bool     IsVisible { get const; set; }
uint     ZOrder    { get const; set; }
};

PARTNERS