Skip to content

Instantly share code, notes, and snippets.

@kennyrkun
Created April 14, 2017 04:38
Show Gist options
  • Save kennyrkun/dba284c89a43f12ec96d5fd736b2abc0 to your computer and use it in GitHub Desktop.
Save kennyrkun/dba284c89a43f12ec96d5fd736b2abc0 to your computer and use it in GitHub Desktop.
//- Window.hpp --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef WINDOW_HPP
#define WINDOW_HPP
#include <SFML\Graphics.hpp>
struct WindowStruct
{
sf::RectangleShape window;
sf::RectangleShape windowtop;
sf::Text windowtitle;
sf::RectangleShape closebutton;
void setPosition(sf::Vector2f &pos)
{
window.setPosition(pos);
windowtop.setPosition(window.getPosition());
windowtitle.setPosition(windowtop.getPosition());
closebutton.setPosition(wingroup.windowtop.getPosition().x / 2 - wingroup.closebutton.getLocalBounds().width, wingroup.windowtop.getPosition().y);
}
};
Struct WindowContent;
class Window
{
public:
void create(sf::Vector2f &size, const std::string title);
void create(sf::Vector2f &size, const std::string title);
void resize(sf::Vector2f &newsize);
inline void setPosition(sf::Vector2f &newpos)
{
wingroup.setPosition(newpos);
}
private:
WindowStruct wingroup;
};
#endif
//- Window.cpp --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define HEADER_HEIGHT
void Window::create(sf::Vector2f &size, const sf::String title)
{
wingroup.window.setSize(size);
wingroup.window.setOrigin(wingroup.window.getSize().x / 2, wingroup.window.getSize().y / 2);
wingroup.window.setPosition(sf::Vector2f(0, 0);
wingroup.windowtop.setSize(wingroup.window.getSize().x, HEADER_HEIGHT);
wingroup.windowtop.setOrigin(wingroup.windowtop.getLocalBounds().width / 2, wingroup.windowtop.getLocalBounds.height / 2);
wingroup.windowtop.setPosition(wingroup.window.getPosition().x, (wingroup.window.getPosition().y * 2) + (wingroup.windowtop.getLocalBounds.height / 2));
wingroup.windowtitle.setString(title);
wingroup.windowtitle.setCharacterSize(wingroup.windowtop.getLocalBounds().y - 4);
wingroup.windowtitle.setOrigin(wingroup.windowtitle.getLocalBounds().width / 2, wingroup.windowtitle.getLocalBounds().height / 2);
wingroup.windowtitle.setPosition(wingroup.windowtop.getPosition());
wingroup.closebutton.setSize(HEADER_HEIGHT, wingroup.windowtop.getLocalBounds().height);
wingroup.closebutton.setOrigin(wingroup.closebutton.getLocalBounds().width, wingroup.closebutton.getLocalBounds().height);
wingroup.closebutton.setPosition(wingroup.windowtop.getPosition().x / 2 - wingroup.closebutton.getLocalBounds().width, wingroup.windowtop.getPosition().y);
wingroup.closebutton.setFillColor(sf::Color::Red);
}
void Window::resize(sf::Vector2f &newsize)
{
wingroup.window.setSize(newsize);
wingroup.windowtop.setSize(newsize.x, HEADER_HEIGHT);
wingroup.windowtop.setOrigin(wingroup.windowtop.getLocalBounds().width / 2, wingroup.windowtop.getLocalBOunds().height / 2);
wingroup.windowtop.setPosition(wingroup.window.getPosition().x, (wingroup.window.getPosition().y * 2) + (wingroup.windowtop.getLocalBounds().getLocalBounds().height / 2);
wingroup.windowtitle.setPosition(windowtop.getPosition());
wingroup.closebutton.setPosition(wingroup.windowtop.getPosition().x * 2 - wingroup.closebutton.getLocalBounds().width / 2, wingroup.windowtop.getPosition().y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment