Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
class CGui { private: struct SButton { friend CGui; SButton() : bActivate(false), sName(""), fPosition(0.0f, 0.0f) {} //Konstruktor SButton(const string &s_Name, void (*p_ActionListener) ()) : bActivate(false) //Konstruktor zum Anlegen eines neuen Buttons { sName.SetText(s_Name); sName.SetSize(20.0f); sName.SetColor(Color(14,14,14)); pActionListener = *p_ActionListener; //cout << pActionListener << " " << p_ActionListener << endl; } void (*pActionListener) (); bool bActivate; //Ob der Button aktiviert wurde String sName; //Name des Buttons Vector2f fPosition; //Position relativ zum Interface }; } class CMap { public: CMap() { //GUI Init m_GUI.Init(); m_GUI.AddButton("Button1", &CMap::GUI_ActionListener); m_GUI.AddButton("Button2", &CMap::GUI_ActionListener); m_GUI.AddButton("Button3", &CMap::GUI_ActionListener); m_GUI.AddButton("Button4", &CMap::GUI_ActionListener); m_GUI.AddButton("Button5", &CMap::GUI_ActionListener); } private: CGui m_GUI; //GUI für die Elementsetzung void GUI_ActionListener() {} } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
class CGui { struct SButton; class SomeClass; //Die Klasse, von der der ActionListener aufgerufen wird typedef void (SomeClass::* ActionListener)(); //Typedef für Memberfunktionspointer public: void AddButton(const string &sName, SomeClass *p_Class, ActionListener _listener) { SButton* tempButton = new SButton(sName, p_Class, _listener); //Button laden m_vButtons.push_back(*tempButton); } private: vector<SButton> m_vButtons; //Vector, der die Buttons beinhaltet struct SButton { friend CGui; SButton() : bActivate(false), sName(""), fPosition(0.0f, 0.0f) {} //Konstruktor SButton(const string &s_Name, SomeClass *p_Class, ActionListener _listener) : bActivate(false) //Konstruktor zum Anlegen eines neuen Buttons { sName.SetText(s_Name); sName.SetSize(20.0f); sName.SetColor(Color(14,14,14)); pClass = p_Class; //Die Klasse definieren listener = _listener; //Den Funktionspointer der Klasse definieren //cout << pActionListener << " " << p_ActionListener << endl; } void RunActionListener() { (pClass->*listener)(); } SomeClass *pClass; ActionListener listener; bool bActivate; //Ob der Button aktiviert wurde String sName; //Name des Buttons Vector2f fPosition; //Position relativ zum Interface }; } class CMap { public: CMap() { //GUI Init m_GUI.Init(); m_GUI.AddButton("Button1", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button2", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button3", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button4", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button5", this, &CMap::GUI_ActionListener); } private: CGui m_GUI; //GUI für die Elementsetzung void GUI_ActionListener() {} } |
C-/C++-Quelltext |
|
1 |
Class::Mebmberfunc() |
Zitat
Nur weil ich mich an der seite orientiert habe heißt das noch lange nicht, dass ich mich damit nicht auseinandergesetzt habe
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
class CGui { struct SButton; class CMap;//### typedef void (CMap::* ActionListener)();//### public: void AddButton(const string &sName, CMap *p_Class, ActionListener _listener)//### { SButton* tempButton = new SButton(sName, p_Class, _listener); m_vButtons.push_back(*tempButton); delete tempButton; // push_back macht eine Kopie } private: vector<SButton> m_vButtons; struct SButton { friend CGui; SButton() : bActivate(false), sName(""), fPosition(0.0f, 0.0f) {} SButton(const string &s_Name, CMap *p_Class, ActionListener _listener) : bActivate(false) //### { sName.SetText(s_Name); sName.SetSize(20.0f); sName.SetColor(Color(14,14,14)); pClass = p_Class; listener = _listener; } void RunActionListener() { (pClass->*listener)(); } CMap *pClass;//### ActionListener listener; bool bActivate; String sName; Vector2f fPosition; }; }; // Strichpunkt class CMap { public: CMap() { m_GUI.Init(); m_GUI.AddButton("Button1", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button2", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button3", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button4", this, &CMap::GUI_ActionListener); m_GUI.AddButton("Button5", this, &CMap::GUI_ActionListener); } private: CGui m_GUI; void GUI_ActionListener() {} }; // Strichpunkt |
Administrator
Werbeanzeige