More binding work scripting
authorHarley Laue <losinggeneration@gmail.com>
Tue, 23 Aug 2011 09:41:31 -0500
branchscripting
changeset 166 7efd37600fb8
parent 165 da3db4db3f2b
child 167 4ed45048e2f3
More binding work
src/core/scripting/lua/CMakeLists.txt
src/core/scripting/lua/binding/hgeBinding.lua
src/core/scripting/lua/binding/hgegui.lua
src/core/scripting/lua/binding/hgeguictrls.lua
src/core/scripting/lua/binding/hgesprite.lua
--- a/src/core/scripting/lua/CMakeLists.txt	Tue Aug 23 09:41:16 2011 -0500
+++ b/src/core/scripting/lua/CMakeLists.txt	Tue Aug 23 09:41:31 2011 -0500
@@ -30,8 +30,8 @@
 	cpp/lua_hgecolor.h
 	cpp/lua_hgedistort.h
 	cpp/lua_hgefont.h
-# 	cpp/lua_hgegui.h
-# 	cpp/lua_hgeguictrls.h
+	cpp/lua_hgegui.h
+	cpp/lua_hgeguictrls.h
 # 	cpp/lua_hgeparticle.h
 	cpp/lua_hgerect.h
 	cpp/lua_hgeresource.h
@@ -46,7 +46,7 @@
 	cpp/lua_hgedistort.cpp
 	cpp/lua_hgefont.cpp
 # 	cpp/lua_hgegui.cpp
-# 	cpp/lua_hgeguictrls.cpp
+	cpp/lua_hgeguictrls.cpp
 # 	cpp/lua_hgeparticle.cpp
 	cpp/lua_hgerect.cpp
 # 	cpp/lua_hgeresource.cpp
--- a/src/core/scripting/lua/binding/hgeBinding.lua	Tue Aug 23 09:41:16 2011 -0500
+++ b/src/core/scripting/lua/binding/hgeBinding.lua	Tue Aug 23 09:41:31 2011 -0500
@@ -27,6 +27,7 @@
 	write([[
 		#include "]]..lower_class..[[.h"
 	]])
+
 	writeDefinitions(bind_tbl, 'bind_lua_'..class_name)
 	flushWritten('cpp/lua_'..lower_class..'.cpp')
 end
@@ -41,8 +42,9 @@
 		'hgeRect',
 		'hgeStrings',
 		'hgeVector',
--- 		'hgeGui',
--- 		'hgeResource', -- has members for sprite, animation, font, and others
+		'hgeGui',
+		'hgeGuiCtrls',
+		'hgeResource', -- has members for sprite, animation, font, and others
 -- 		'hge',
 	}
 
--- a/src/core/scripting/lua/binding/hgegui.lua	Tue Aug 23 09:41:16 2011 -0500
+++ b/src/core/scripting/lua/binding/hgegui.lua	Tue Aug 23 09:41:31 2011 -0500
@@ -29,20 +29,20 @@
 			memberFunctions = {
 				{ 'void Update(float dt);' },
 
-				{ 'virtual void Enter();' },
-				{ 'virtual void Leave();' },
-				{ 'virtual void Reset();' },
-				{ 'virtual bool IsDone();' },
-				{ 'virtual void Focus(bool bFocused);' },
-				{ 'virtual void MouseOver(bool bOver);' },
+				{ 'void Enter();' },
+				{ 'void Leave();' },
+				{ 'void Reset();' },
+				{ 'bool IsDone();' },
+				{ 'void Focus(bool bFocused);' },
+				{ 'void MouseOver(bool bOver);' },
 
-				{ 'virtual bool MouseMove(float x, float y);' },
-				{ 'virtual bool MouseLButton(bool bDown);' },
-				{ 'virtual bool MouseRButton(bool bDown);' },
-				{ 'virtual bool MouseWheel(int nNotches);' },
-				{ 'virtual bool KeyClick(int key, int chr);' },
+				{ 'bool MouseMove(float x, float y);' },
+				{ 'bool MouseLButton(bool bDown);' },
+				{ 'bool MouseRButton(bool bDown);' },
+				{ 'bool MouseWheel(int nNotches);' },
+				{ 'bool KeyClick(int key, int chr);' },
 
-				{ 'virtual void SetColor(DWORD _color);' },
+				{ 'void SetColor(DWORD _color);' },
 			},
 		},
 		{
@@ -87,71 +87,4 @@
 #define HGEGUI_UPDOWN			2
 #define HGEGUI_CYCLED			4
 
-class hgeGUI;
-
-class hgeGUIObject
-{
-public:
-	hgeGUIObject();
-	virtual ~hgeGUIObject();
-
-	virtual void Render() = 0;
-	virtual void Update(float dt);
-
-	virtual void Enter();
-	virtual void Leave();
-	virtual void Reset();
-	virtual bool IsDone();
-	virtual void Focus(bool bFocused);
-	virtual void MouseOver(bool bOver);
-
-	virtual bool MouseMove(float x, float y);
-	virtual bool MouseLButton(bool bDown);
-	virtual bool MouseRButton(bool bDown);
-	virtual bool MouseWheel(int nNotches);
-	virtual bool KeyClick(int key, int chr);
-
-	virtual void SetColor(DWORD _color);
-
-	int id;
-	bool bStatic;
-	bool bVisible;
-	bool bEnabled;
-	hgeRect rect;
-	DWORD color;
-
-	hgeGUI *gui;
-	hgeGUIObject *next;
-	hgeGUIObject *prev;
-};
-
-class hgeGUI
-{
-public:
-	hgeGUI();
-	~hgeGUI();
-
-	void			AddCtrl(hgeGUIObject *ctrl);
-	void			DelCtrl(int id);
-	hgeGUIObject*	GetCtrl(int id) const;
-
-	void			MoveCtrl(int id, float x, float y);
-	void			ShowCtrl(int id, bool bVisible);
-	void			EnableCtrl(int id, bool bEnabled);
-
-	void			SetNavMode(int mode);
-	void			SetCursor(hgeSprite *spr);
-	void			SetColor(DWORD color);
-	void			SetFocus(int id);
-	int				GetFocus() const;
-
-	void			Enter();
-	void			Leave();
-	void			Reset();
-	void			Move(float dx, float dy);
-
-	int				Update(float dt);
-	void			Render();
-};
-
 --]]
--- a/src/core/scripting/lua/binding/hgeguictrls.lua	Tue Aug 23 09:41:16 2011 -0500
+++ b/src/core/scripting/lua/binding/hgeguictrls.lua	Tue Aug 23 09:41:31 2011 -0500
@@ -6,6 +6,93 @@
 -- hgeGUI default controls header
 --
 
+bindhgeGuiCtrls = {
+	classes = {
+		{
+			name = 'hge.GUI.Button',
+			className = 'hgeGUIButton',
+			ctors = {
+				'(int id, float x, float y, float w, float h, HTEXTURE tex, float tx, float ty)',
+			},
+			memberFunctions = {
+				{ 'void SetMode(bool _bTrigger);' },
+				{ 'void SetState(bool _bPressed);' },
+				{ 'bool GetState() const;' },
+
+				{ 'void Render();' },
+				{ 'bool MouseLButton(bool bDown);' },
+			},
+		},
+		{
+			name = 'hge.GUI.Listbox',
+			className = 'hgeGUIListbox',
+			ctors = {
+				'(int id, float x, float y, float w, float h, hgeFont *fnt, DWORD tColor, DWORD thColor, DWORD hColor)',
+			},
+			memberFunctions = {
+				{ 'int AddItem(const char * item);' },
+				{ 'void DeleteItem(int n);' },
+				{ 'int GetSelectedItem();' },
+				{ 'void SetSelectedItem(int n);' },
+				{ 'int GetTopItem();' },
+				{ 'void SetTopItem(int n);' },
+
+				{ 'const char * GetItemText(int n);' },
+				{ 'int GetNumItems();' },
+				{ 'int GetNumRows();' },
+				{ 'void Clear();' },
+
+				{ 'void Render();' },
+				{ 'bool MouseMove(float x, float y);' },
+				{ 'bool MouseLButton(bool bDown);' },
+				{ 'bool MouseWheel(int nNotches);' },
+				{ 'bool KeyClick(int key, int chr);' },
+			},
+		},
+		{
+			name = 'hge.GUI.Listbox.Item',
+			className = 'hgeGUIListboxItem',
+			--  really text[64]
+			properties = {
+-- 				'std::string text;',
+				'hgeGUIListboxItem *next;',
+			},
+		},
+		{
+			name = 'hge.GUI.Slider',
+			className = 'hgeGUISlider',
+			ctors = {
+				'(int id, float x, float y, float w, float h, HTEXTURE tex, float tx, float ty, float sw, float sh, bool vertical)',
+			},
+			memberFunctions = {
+				{ 'void SetMode(float _fMin, float _fMax, int _mode);' },
+				{ 'void SetValue(float _fVal);' },
+				{ 'float GetValue() const;' },
+
+				{ 'void Render();' },
+				{ 'bool MouseMove(float x, float y);' },
+				{ 'bool MouseLButton(bool bDown);' },
+			},
+		},
+		{
+			name = 'hge.GUI.Text',
+			className = 'hgeGUIText',
+			ctors = {
+				'(int id, float x, float y, float w, float h, hgeFont *fnt)',
+			},
+			memberFunctions = {
+				{ 'void SetMode(int _align);' },
+				{ 'void SetText(const char * _text);' },
+-- 				{ 'void printf(const char *format, ...);' },
+
+				{ 'void Render();' },
+			},
+		},
+	},
+	modules = {
+	},
+}
+
 --[[
 
 #define hgeButtonGetState(gui,id) ((hgeGUIButton*)gui->GetCtrl(id))->GetState()
@@ -15,80 +102,8 @@
 #define hgeGetTextCtrl(gui,id) ((hgeGUIText*)gui->GetCtrl(id))
 #define hgeGetListboxCtrl(gui,id) ((hgeGUIListbox*)gui->GetCtrl(id))
 
-class hgeGUIText : public hgeGUIObject
-{
-public:
-	hgeGUIText(int id, float x, float y, float w, float h, hgeFont *fnt);
-
-	void SetMode(int _align);
-	void SetText(const char *_text);
-	void printf(const char *format, ...);
-
-	virtual void Render();
-};
-
-class hgeGUIButton : public hgeGUIObject
-{
-public:
-	hgeGUIButton(int id, float x, float y, float w, float h, HTEXTURE tex, float tx, float ty);
-	virtual ~hgeGUIButton();
-
-	void SetMode(bool _bTrigger) { bTrigger=_bTrigger; }
-	void SetState(bool _bPressed) { bPressed=_bPressed; }
-	bool GetState() const { return bPressed; }
-
-	virtual void Render();
-	virtual bool MouseLButton(bool bDown);
-};
-
 #define HGESLIDER_BAR 0
 #define HGESLIDER_BARRELATIVE 1
 #define HGESLIDER_SLIDER 2
 
-class hgeGUISlider : public hgeGUIObject
-{
-public:
-	hgeGUISlider(int id, float x, float y, float w, float h, HTEXTURE tex, float tx, float ty, float sw, float sh, bool vertical=false);
-	virtual ~hgeGUISlider();
-
-	void SetMode(float _fMin, float _fMax, int _mode) { fMin=_fMin; fMax=_fMax; mode=_mode; }
-	void SetValue(float _fVal);
-	float GetValue() const { return fVal; }
-
-	virtual void Render();
-	virtual bool MouseMove(float x, float y);
-	virtual bool MouseLButton(bool bDown);
-};
-
-struct hgeGUIListboxItem
-{
-	char text[64];
-	hgeGUIListboxItem *next;
-};
-
-class hgeGUIListbox : public hgeGUIObject
-{
-public:
-	hgeGUIListbox(int id, float x, float y, float w, float h, hgeFont *fnt, DWORD tColor, DWORD thColor, DWORD hColor);
-	virtual ~hgeGUIListbox();
-
-	int AddItem(char *item);
-	void DeleteItem(int n);
-	int GetSelectedItem() { return nSelectedItem; }
-	void SetSelectedItem(int n) { if(n>=0 && n<GetNumItems()) nSelectedItem=n; }
-	int GetTopItem() { return nTopItem; }
-	void SetTopItem(int n) { if(n>=0 && n<=GetNumItems()-GetNumRows()) nTopItem=n; }
-
-	char *GetItemText(int n);
-	int GetNumItems() { return nItems; }
-	int GetNumRows() { return int((rect.y2-rect.y1)/font->GetHeight()); }
-	void Clear();
-
-	virtual void Render();
-	virtual bool MouseMove(float x, float y) { mx=x; my=y; return false; }
-	virtual bool MouseLButton(bool bDown);
-	virtual bool MouseWheel(int nNotches);
-	virtual bool KeyClick(int key, int chr);
-};
-
 --]]
--- a/src/core/scripting/lua/binding/hgesprite.lua	Tue Aug 23 09:41:16 2011 -0500
+++ b/src/core/scripting/lua/binding/hgesprite.lua	Tue Aug 23 09:41:31 2011 -0500
@@ -8,6 +8,7 @@
 
 bindhgeSprite = {
 	classes = {
+		{
 		name = 'hge.Sprite',
 		className = 'hgeSprite',
 		ctors = {
@@ -16,7 +17,7 @@
 		},
 		memberFunctions = {
 			{ 'void Render(float x, float y);' },
-			{ 'void RenderEx(float x, float y, float rot, float hscale=1.0f, float vscale);' },
+			{ 'void RenderEx(float x, float y, float rot, float hscale, float vscale);' },
 			{ 'void RenderStretch(float x1, float y1, float x2, float y2);' },
 			{ 'void Render4V(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3);' },
 
@@ -26,21 +27,22 @@
 			{ 'void SetZ(float z, int i);' },
 			{ 'void SetBlendMode(int blend);' },
 			{ 'void SetHotSpot(float x, float y);' },
-			{ 'void SetFlip(bool bX, bool bY, bool bHotSpot = false);' },
+			{ 'void SetFlip(bool bX, bool bY, bool bHotSpot);' },
 
 			{ 'HTEXTURE GetTexture() const;' },
-			{ 'void GetTextureRect(float *x, float *y, float *w, float *h) const;' },
 			{ 'DWORD GetColor(int i) const;' },
 			{ 'float GetZ(int i) const;' },
 			{ 'int GetBlendMode() const;' },
-			{ 'void GetHotSpot(float *x, float *y) const;' },
-			{ 'void GetFlip(bool *bX, bool *bY) const;' },
+-- 			{ 'void GetTextureRect(float *x, float *y, float *w, float *h) const;' },
+-- 			{ 'void GetHotSpot(float *x, float *y) const;' },
+-- 			{ 'void GetFlip(bool *bX, bool *bY) const;' },
 
 			{ 'float GetWidth() const;' },
 			{ 'float GetHeight() const;' },
 			{ 'hgeRect* GetBoundingBox(float x, float y, hgeRect *rect) const;' },
 			{ 'hgeRect* GetBoundingBoxEx(float x, float y, float rot, float hscale, float vscale, hgeRect *rect) const;' },
-		}
+		},
+		},
 	},
 	modules = {
 	},