GUI Manager

A forum to store posts deemed exceptionally wise and useful
Post Reply
aktlakfh1777
Posts: 17
Joined: Sun Dec 21, 2008 1:40 am

GUI Manager

Post by aktlakfh1777 »

I was felt tired to write GUI codes. so, I was made it.
but It's very simple and easy.

sample :

MyGUIManager * MGM=new MyGUIManager;

void main()
{

MGM->Create(guienv->addStaticText(L"Debug Mode",rect<s32>(10,10,2600,200),false));
MGM->Create(guienv->addStaticText(L"Debug Mode",rect<s32>(30,10,2600,200),false));

}

Codes if you don't use it :

void main()
{

IGUIStaticText *lgst;
lgst=new IGUIStaticText;
lgst=guienv->addStaticText(L"Debug Mode",rect<s32>(10,10,2600,200),false);

IGUIStaticText *lgst2;
lgst2=new IGUIStaticText;
lgst2=guienv->addStaticText(L"Debug Mode",rect<s32>(30,10,2600,200),false);

}

difference is very big that don't use it and use it.
code using MyGUIManager is very simple but Codes you don't use it is isn't.

MGM->Create();

this is return control key.
control key is what?
control key can control Objects.

int ck;
ck=MGM->Create(guienv->addStaticText(L"Debug Mode",rect<s32>(30,10,2600,200),false));

// I was used 'StaticText'.

MGM->STB[ck]->setText("WWWHWHWHWH hahahaha...");

Code: Select all

#define MAX_OBJ_NUM 10000

class MyGUIManager
{
public:
	MyGUIManager()
	{
		uEB=0;
		uLB=0;
		uBTN=0;
		uCB=0;
		uCOB=0;
		uCTM=0;
		uST=0;
		uWS=0;
		uIB=0;
	}
	~MyGUIManager()
	{
//this will use to erase GUI Buffers
	IGUIStaticText * O1;
	IGUIEditBox * O2;
	IGUIListBox * O3;
	IGUIButton * O4;
	IGUICheckBox * O5;
	IGUIComboBox * O6;
	IGUIContextMenu * O7;
	IGUIWindow * O8;
	IGUIImage * O9;
/*
	IGUIStaticText * STB[MAX_OBJ_NUM];
	IGUIEditBox * EB[MAX_OBJ_NUM];
	IGUIListBox * LB[MAX_OBJ_NUM];
	IGUIButton * BTN[MAX_OBJ_NUM];
	IGUICheckBox * CB[MAX_OBJ_NUM];
	IGUIComboBox * COB[MAX_OBJ_NUM];
	IGUIContextMenu * CTM[MAX_OBJ_NUM];
	IGUIWindow * WinS[MAX_OBJ_NUM];
	IGUIImage *ImgB[MAX_OBJ_NUM];
*/
		for(int i=0;i > MAX_OBJ_NUM ; i++)
		{
			STB[i]=O1;
			EB[i]=O2;
			LB[i]=O3;
			BTN[i]=O4;
			CB[i]=O5;
			COB[i]=O6;
			CTM[i]=O7;
			WinS[i]=O8;
			ImgB[i]=O9;
		} // MAX_OBJ_NUM
	}

	IGUIStaticText * STB[MAX_OBJ_NUM]; // 1
	IGUIEditBox * EB[MAX_OBJ_NUM]; // 2
	IGUIListBox * LB[MAX_OBJ_NUM];//3
	IGUIButton * BTN[MAX_OBJ_NUM];//4
	IGUICheckBox * CB[MAX_OBJ_NUM];//5
	IGUIComboBox * COB[MAX_OBJ_NUM];//6
	IGUIContextMenu * CTM[MAX_OBJ_NUM];//7
	IGUIWindow * WinS[MAX_OBJ_NUM];//8
	IGUIImage *ImgB[MAX_OBJ_NUM];//9
	// 간접 생성
	int Create(IGUIImage * ImageControl)
	{
		if(uIB==MAX_OBJ_NUM)
			return -1;
		uIB++;
		ImgB[uIB]=ImageControl;
		return uLB;
	}
	int Create(IGUIWindow * WindowControl)
	{
		if(uWS==MAX_OBJ_NUM)
			return -1;
		uWS++;
		WinS[uWS]=WindowControl;
		return uLB;
	}
	int Create(IGUIContextMenu * ContextMenuControl)
	{
		if(uCTM==MAX_OBJ_NUM)
			return -1;
		uCTM++;
		CTM[uCTM]=ContextMenuControl;
		return uLB;
	}
	int Create(IGUIComboBox * ComboboxControl)
	{
		if(uCOB==MAX_OBJ_NUM)
			return -1;
		uCOB++;
		COB[uCOB]=ComboboxControl;
		return uLB;
	}
	int Create(IGUICheckBox * CheckboxControl)
	{
		if(uCB==MAX_OBJ_NUM)
			return -1;
		uCB++;
		CB[uCB]=CheckboxControl;
		return uLB;
	}
	int Create(IGUIButton * BtnControl)
	{
		if(uBTN==MAX_OBJ_NUM)
			return -1;
		uBTN++;
		BTN[uBTN]=BtnControl;
		return uLB;
	}
	int Create(IGUIListBox * ListBoxControl)
	{
		if(uLB==MAX_OBJ_NUM)
			return -1;
		uLB++;
		LB[uLB]=ListBoxControl;
		return uLB;
	}
	int Create(IGUIStaticText * StaticTextControl)
	{
		if(uST==MAX_OBJ_NUM)
			return -1;
		uST++;
		STB[uST]=StaticTextControl;
		return uST;
	}
	int Create(IGUIEditBox * EditBoxControl)
	{
		if(uEB==MAX_OBJ_NUM)
			return -1;
		uEB++;
		EB[uEB]=EditBoxControl;
		return uEB;
	}

	int Create(IGUIImage * ImageControl,int contkey)
	{
		ImgB[contkey]=ImageControl;
		return contkey;
	}
	int Create(IGUIWindow * WindowControl,int contkey)
	{
		WinS[contkey]=WindowControl;
		return contkey;
	}
	int Create(IGUIContextMenu * ContextMenuControl,int contkey)
	{
		CTM[contkey]=ContextMenuControl;
		return contkey;
	}
	int Create(IGUIComboBox * ComboboxControl,int contkey)
	{
		COB[contkey]=ComboboxControl;
		return contkey;
	}
	int Create(IGUICheckBox * CheckboxControl,int contkey)
	{
		CB[contkey]=CheckboxControl;
		return contkey;
	}
	int Create(IGUIButton * BtnControl,int contkey)
	{
		BTN[contkey]=BtnControl;
		return contkey;
	}
	int Create(IGUIListBox * ListBoxControl,int contkey)
	{
		LB[contkey]=ListBoxControl;
		return contkey;
	}
	int Create(IGUIStaticText * StaticTextControl,int contkey)
	{
		STB[contkey]=StaticTextControl;
		return contkey;
	}
	int Create(IGUIEditBox * EditBoxControl,int contkey)
	{
		EB[contkey]=EditBoxControl;
		return contkey;
	}

	void AllErase()
	{
	//this will use to erase GUI Buffers
	IGUIStaticText * O1;
	IGUIEditBox * O2;
	IGUIListBox * O3;
	IGUIButton * O4;
	IGUICheckBox * O5;
	IGUIComboBox * O6;
	IGUIContextMenu * O7;
	IGUIWindow * O8;
	IGUIImage * O9;
/*
	IGUIStaticText * STB[MAX_OBJ_NUM];
	IGUIEditBox * EB[MAX_OBJ_NUM];
	IGUIListBox * LB[MAX_OBJ_NUM];
	IGUIButton * BTN[MAX_OBJ_NUM];
	IGUICheckBox * CB[MAX_OBJ_NUM];
	IGUIComboBox * COB[MAX_OBJ_NUM];
	IGUIContextMenu * CTM[MAX_OBJ_NUM];
	IGUIWindow * WinS[MAX_OBJ_NUM];
	IGUIImage *ImgB[MAX_OBJ_NUM];
*/
		for(int i=0;i > MAX_OBJ_NUM ; i++)
		{
			STB[i]=O1;
			EB[i]=O2;
			LB[i]=O3;
			BTN[i]=O4;
			CB[i]=O5;
			COB[i]=O6;
			CTM[i]=O7;
			WinS[i]=O8;
			ImgB[i]=O9;
		} // MAX_OBJ_NUM

	}

private:
		int uEB,uLB,uBTN,uCB,uCOB,uCTM,uST,uWS,uIB;
};

Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

There is no need to define the statictext, then 'new' it, then assign it. you can do all of that in one statement. (actually, you are creating 2 statictexts, only one of which is being added to the gui in your first code)

Code: Select all

// declare a variable (no memory used yet)
IGUIStaticText *lgst; 

// create a new variable (memory used) and assign it to lgst
lgst=new IGUIStaticText; 

// create a new variable (memory used) and assign it to lgst (also gets added to gui environment)
lgst=guienv->addStaticText(L"Debug Mode",rect<s32>(10,10,2600,200),false); 

Code: Select all

IGUIStaticText *lgst = guienv->addStaticText(L"Debug Mode",rect<s32>(10,10,2600,200),false); 

IGUIStaticText *lgst2 = guienv->addStaticText(L"Debug Mode",rect<s32>(30,10,2600,200),false); 

keeping the pointers to all of the gui elements is not needed howoever, because you can easily use the GUI to get the gui element by it's id when desired.

Code: Select all

	//! Finds the first element with the given id.
	/** \param id: Id to search for.
	\param searchchildren: Set this to true, if also children of this
	element may contain the element with the searched id and they
	should be searched too.
	\return Returns the first element with the given id. If no element
	with this id was found, 0 is returned. */
	virtual IGUIElement* getElementFromId(s32 id, bool searchchildren=false) const
Last edited by Seven on Sun Jan 04, 2009 1:28 am, edited 2 times in total.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

Code: Select all

#define ID_MYBUTTON 100

IGUIButton* b = gui->addButton(core::rect<s32>(10,10,100,30),0,ID_MYBUTTON,"OldText");

Code: Select all

IGUIElement* FindElement(int id)
{
  IGUIElement* root = gui->getRootGUIElement();
  if (root) return root->getElementFromId(id,true);
  else return NULL;
}

Code: Select all

IGUIButton* button = (IGUIButton*)FindElement(ID_MYBUTTON);
if (button) button->setText(L"new text");
the benefit to using this method, is that you will run across newer, cooler gui elements that people have created and you will have to update your manager each time. This method allows you to recall any gui element without ever changing your code.

I do however like the way you link keyboard to gui elements :)
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post by Halan »

It is even wrong to new the interface and creates a memory leak.
Post Reply