Window centering and positioning added.

pull/28/head
sigonasr2 1 year ago
parent ce1a2adf81
commit c1d64e7bd1
  1. 20
      Crawler/Menu.cpp
  2. 4
      Crawler/Menu.h
  3. 1
      Crawler/MenuComponent.h
  4. 1
      Crawler/State_GameRun.cpp
  5. 2
      Crawler/TestMenu.cpp
  6. 2
      Crawler/TestSubMenu.cpp
  7. 2
      Crawler/Version.h

@ -8,13 +8,15 @@ std::vector<Menu*>Menu::stack;
std::map<MenuType,Menu>Menu::menus;
std::string Menu::themeSelection="BlueDefault";
safeunorderedmap<std::string,Theme>Menu::themes;
const vf2d Menu::CENTERED = {-456,-456};
INCLUDE_GFX
extern vi2d WINDOW_SIZE;
Menu::Menu(){}
Menu::Menu(vf2d size)
:size(size){}
Menu::Menu(vf2d pos,vf2d size)
:pos(pos==CENTERED?WINDOW_SIZE/2-size/2:vi2d{pos}),size(size){}
void Menu::InitializeMenus(){
stack.reserve(32);
@ -57,7 +59,6 @@ void Menu::MenuSelect(Crawler*game){
}
void Menu::Update(Crawler*game){
vf2d upperLeftPos=game->GetScreenSize()/2-size/2;
for(auto&key:buttons){
for(auto&button:key.second){
@ -69,14 +70,14 @@ void Menu::Update(Crawler*game){
}else{
for(auto&key:buttons){
for(auto&button:key.second){
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+upperLeftPos,button->rect.size},game->GetMousePos())){
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+pos,button->rect.size},game->GetMousePos())){
button->hovered=true;
}
}
}
}
KeyboardButtonNavigation(game,upperLeftPos);
KeyboardButtonNavigation(game,pos);
for(auto&key:buttons){
for(auto&button:key.second){
button->Update(game);
@ -88,21 +89,20 @@ void Menu::Update(Crawler*game){
};
void Menu::Draw(Crawler*game){
vf2d upperLeftPos=game->GetScreenSize()/2-size/2;
if(GetCurrentTheme().IsScaled()){
DrawScaledWindow(game,upperLeftPos);
DrawScaledWindow(game,pos);
}else{
DrawTiledWindow(game,upperLeftPos);
DrawTiledWindow(game,pos);
}
for(auto&key:buttons){
for(auto&button:key.second){
button->Draw(game,upperLeftPos,this==Menu::stack.back());
button->Draw(game,pos,this==Menu::stack.back());
}
}
for(auto&component:displayComponents){
component->Draw(game,upperLeftPos,this==Menu::stack.back());
component->Draw(game,pos,this==Menu::stack.back());
}
};

@ -18,10 +18,11 @@ class Menu:IAttributable{
std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes.
safemap<std::string,MenuComponent*>components; //A friendly way to interrogate any component we are interested in.
vi2d selection={-1,-1};
vf2d pos; //Specify the upper-left corner of the window. Using CENTERED will always put this where the upper-left corner would center the window.
vf2d size; //Size in tiles (24x24), every menu will be tile-based
public:
Menu();
Menu(vf2d size);
Menu(vf2d pos,vf2d size);
void AddComponent(std::string key,MenuComponent*button);
void Update(Crawler*game);
void Draw(Crawler*game);
@ -30,6 +31,7 @@ public:
static std::vector<Menu*>stack;
static std::string themeSelection;
static safeunorderedmap<std::string,Theme>themes;
static const vf2d CENTERED;
private:
void MenuSelect(Crawler*game);
static const Menu InitializeTestMenu();

@ -12,6 +12,7 @@ class MenuComponent{
MenuFunc onClick;
bool hovered=false;
bool selectable=true;
bool draggable=false;
private:
float hoverEffect=0;
protected:

@ -33,4 +33,5 @@ void State_GameRun::OnUserUpdate(Crawler*game){
game->UpdateCamera(game->GetElapsedTime());
};
void State_GameRun::Draw(Crawler*game){
};

@ -2,7 +2,7 @@
#include "Menu.h"
const Menu Menu::InitializeTestMenu(){
Menu testMenu({24*8,24*6});
Menu testMenu(CENTERED,{24*8,24*6});
MenuFunc quitWindow=[](Menu&menu,Crawler*game){
menu.stack.clear();

@ -10,7 +10,7 @@ INCLUDE_GFX
typedef Attribute A;
const Menu Menu::InitializeTestSubMenu(){
Menu testSubMenu({24*4,24*5});
Menu testSubMenu({30,30},{24*4,24*5});
MenuFunc goBack=[](Menu&menu,Crawler*game){
menu.stack.pop_back();

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 1777
#define VERSION_BUILD 1782
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save