Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SFML Game Development By Example

You're reading from   SFML Game Development By Example Create and develop exciting games from start to finish using SFML

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785287343
Length 522 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Raimondas Pupius Raimondas Pupius
Author Profile Icon Raimondas Pupius
Raimondas Pupius
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. It's Alive! It's Alive! – Setup and First Program 2. Give It Some Structure – Building the Game Framework FREE CHAPTER 3. Get Your Hands Dirty – What You Need to Know 4. Grab That Joystick – Input and Event Management 5. Can I Pause This? – Application States 6. Set It in Motion! – Animating and Moving around Your World 7. Rediscovering Fire – Common Game Design Elements 8. The More You Know – Common Game Programming Patterns 9. A Breath of Fresh Air – Entity Component System Continued 10. Can I Click This? – GUI Fundamentals 11. Don't Touch the Red Button! – Implementing the GUI 12. Can You Hear Me Now? – Sound and Music 13. We Have Contact! – Networking Basics 14. Come Play with Us! – Multiplayer Subtleties Index

The core of all elements


The GUI_Element class is the core of every single element and interface. It provides key functionality that higher level objects rely on, as well as enforcing the implementation of necessary methods, which leads to several distinctive element types.

A definition of the different element types is a good place to start:

enum class GUI_ElementType{ Window, Label, Button, Scrollbar,
  Textfield };

Each element has to hold different styles it can switch to, based on its state. The unordered_map data structure suits our purposes pretty well:

using ElementStyles = std::unordered_map<
  GUI_ElementState, GUI_Style>;

A forward declaration of the owner class is also necessary to prevent cross-inclusion:

class GUI_Interface;

Next, we can begin shaping the GUI_Element class:

class GUI_Element{
  friend class GUI_Interface;
public:
  GUI_Element(const std::string& l_name, 
    const GUI_ElementType& l_type, GUI_Interface* l_owner);
  virtual ~GUI_Element();

  // Event...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $24.99/month. Cancel anytime