• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
    14
  • comments
    9
  • views
    12620

GUIObject: Button

Sign in to follow this  
Followers 0
JD_Rushing

621 views

Now please correct me if I say something wrong. I am not trying to create a tutorial, but rather explain my process.

Now all my GUI (Graphical User Interface) objects inherit from GUIObject.hpp

#include #include "OpenGLContext.hpp"#include "Command.hpp"#include "AValue.hpp"#include "Vector2i.hpp"#include "Texture.hpp"#include "FontBMP.hpp"#include #include #include #include "Buffer.hpp"#include "Mouse.hpp"#ifndef GUIOBJECT_H#define GUIOBJECT_Hclass GUIObject{public: GUIObject() { }; std::vector command; //outgoing command std::vector commands; //command to copy to outgoing std::string name; std::string type; int width; int height; Vector2i position; Vector2i prevPos; bool enabled; //Is this button clickable; bool visible; Vector2i mousePosition; int debug; std::string debugS; bool created; bool grabbed; virtual void Standard() { return; }; virtual void CreateVAO() { return; } virtual void Destroy() { return; } virtual void Draw(std::vector &textures, FontBMP &aFont, bool textured, OpenGLContext *openglContext) { Draw(0, 0, textures, aFont, textured, openglContext); return; }; virtual void Draw(int sx, int sy, std::vector &textures, FontBMP &aFont, bool textured, OpenGLContext *openglContext) { return; }; virtual void DrawPick(int sx, int sy, Color4f thePick, OpenGLContext *openglContext) { return; } virtual void SetPosition(int x, int y, int Awidth, int Aheight) { position.x = x; position.y = y; width = Awidth; height = Aheight; } virtual void SetPosition(int x, int y) { SetPosition(x, y, width, height); return; } virtual bool InBounds(Vector2i pos) { return InBounds(pos.x, pos.y); } virtual bool InBounds(int x, int y) { if (x > position.x && x < position.x + width) { if (y > position.y && y < position.y + height) { return true; } } return false; } virtual bool InBounds(Vector2i pos, Vector2i upperLeft, Vector2i size) { if (pos.x > upperLeft.x && pos.x < upperLeft.x + size.x) { if (pos.y > upperLeft.y && pos.y < upperLeft.y + size.y) { return true; } } return false; } virtual bool ClickUp(Mouse& mouse) { return true; }; virtual bool ClickHeld(Mouse& mouse) { return true; }; virtual bool ClickDown(Mouse& mouse) { return true; }; virtual int KeyboardInput(std::vectorkeys, std::vector buffer) { return -2; }; virtual AValue PropertyGet(std::string theProp) { AValue newValue; newValue.theString = (char*)"none"; return newValue; }; virtual std::vector PropertyGetVector(std::string theProp) { std::vector newValue; newValue.clear(); return newValue; }; virtual void PropertySet(std::string theProp, std::string theFormat, ...) { return; }; virtual void PropertySet(std::string theProp, AValue &theValue) { return; } virtual void Commands(Command &aCommand) { return; } virtual AValue CommandR(Command &aCommand) { return AValue(); } virtual void LoseFocus() { return; }};#endifNow my Button class will Inherit the GUIObject class. This allows Button to immediately have all the variables and functions that the GUIObject has. Plus, it can override any virtual class to make one with the same name and parameters, but different code inside it.
Now if I wanted to, I could make a function abstract versus virtual. This would make any class that inherits this class forced to override the function and make its own.

#ifndef Button_h#define Button_h#include "GUIObject.hpp"#include "Quad.hpp"#include class Button: public GUIObject{ public: Quad back; std::string text; Button() { } Button(const Button& other) { if (this != &other) { Destroy(); back = other.back; } } void Standard(); void CreateVAO(); void Destroy(); void Draw(std::vector &textures, FontBMP &aFont, bool textured, OpenGLContext *openglContext); void Draw(int sx, int sy, std::vector &textures, FontBMP &aFont, bool textured, OpenGLContext *openglContext); void DrawPick(int sx, int sy, Color4f thePick, OpenGLContext *openglContext); void SetPosition(int x, int y, int Awidth, int Aheight); void SetPosition(int x, int y); bool InBounds(int x, int y); bool ClickUp(Mouse& mouse); bool ClickHeld(Mouse& mouse); bool ClickDown(Mouse& mouse); int KeyboardInput(std::vectorkeys, std::vector buffer); AValue PropertyGet(std::string theProp); std::vector PropertyGetVector(std::string theProp); void PropertySet(std::string theProp, std::string theFormat, ...); void PropertySet(std::string theProp, AValue &theValue); void Commands(Command &aCommand); AValue CommandR(Command &aCommand); void LoseFocus();};#endifNotice some of the functions are the same as GUIObject, just without the virtual part. These functions can be called even when stored in a GUIObject pointer, and will call the overridden function versus the GUIObject original function.

ComponentGUI has a vector 'std::vector guiObject' that stores a pointer to all the GUIObject created.
It has a function to Add a GUIObject:

int ComponentGui::AddControl(char *theName, char *theType, GUIObject *theObject){ int count = AddControlVar(); guiObject[count] = theObject; guiObject[count]->type = theType; guiObject[count]->name = theName; controlOrder.push_back(ControlOrder(count, theName)); theObject = NULL; return count;}Now I want to add a button so I could call this function like this:
componentGui.AddControl("Button1", "Button", new Button());Even though the parameter asked for two char* and a GUIObject pointer, I gave it two char* and a pointer to a Button. Since Button inherited GUIObject, the Button pointer can be used in place of a GUIObject pointer. This can work vice versa, but you have the type cast the GUIObject back to Button.
Button* button = (Button*)guiObject[0];Now since guiObject[0] now contains a GUIObject, I can call one of its functions.
componentGui.guiObject[0]->Standard();componentGui.guiObject[0]->Draw(0, 0, textures, aFont, textured, &openglContext);This code calls Standard(), basically sets all the parameters of the object to starting/standard.
Then the next code draws it.
Now since button has overridden Standard and Draw, the buttons version of the functions will be called.

I do want to point out, you cannot call any function or use any parameter from Button that is not contained in GUIObject while it is thought of as a GUIobject.
'Button *button = new Button()' could call any of the functions from GUIObject or Button.
'GUIObject *guiObject = new Button()' could only call the functions from GUIObject. Now any overridden functions would be called instead, but they must have same name and parameters.

1
Sign in to follow this  
Followers 0


0 Comments


There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now