Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BuildMenuButton Struct Reference

#include <BuildMenu.hxx>

+ Collaboration diagram for BuildMenuButton:

Public Types

using Ptr = std::shared_ptr< BuildMenuButton >
 
using Items = std::vector< Ptr >
 

Public Member Functions

 BuildMenuButton (const std::string &tx, const std::string &category)
 
 BuildMenuButton (const std::string &tx, const std::string &category, const TileData &tile)
 
Ptr addCategoryButton (const std::string &tx, const std::string &id, const TileData &tile)
 
Ptr addTileButton (const std::string &tx, const std::string &id, const TileData &tile)
 
Ptr addActionButton (const std::string &tx, const std::string &action, const std::string &tooltip)
 
Ptr addButtonImpl (const std::string &tx, const std::string &id, const TileData &tile)
 
void scaleCenterImage (SDL_Rect &ret, int btnW, int btnH, int imgW, int imgH) const
 takes an SDL_Rect, default button width and height, and image width and height and scales the image to fit on a button of the default button size (maintaining the aspect ration of the original image). More...
 
const ImVec2 & getBtnSize () const
 
const std::stringgetId () const
 
const ItemsgetButtons () const
 
void hideItems ()
 

Public Attributes

bool m_open = false
 
bool m_background = false
 
std::string m_texstr
 
std::string m_id
 
std::string m_action
 
std::string m_tiletype
 
SDL_Texture * m_tex
 
ImVec2 m_uv0 = ImVec2{0, 0}
 
ImVec2 m_uv1 = ImVec2{1, 1}
 
ImSpan2i m_texSize
 
BuildMenuButtonm_parent = nullptr
 
ImVec4 m_destRect
 
ImVec2 m_btnSize
 
Items m_buttons
 

Detailed Description

Definition at line 9 of file BuildMenu.hxx.

Member Typedef Documentation

◆ Items

using BuildMenuButton::Items = std::vector<Ptr>

Definition at line 12 of file BuildMenu.hxx.

◆ Ptr

using BuildMenuButton::Ptr = std::shared_ptr<BuildMenuButton>

Definition at line 11 of file BuildMenu.hxx.

Constructor & Destructor Documentation

◆ BuildMenuButton() [1/2]

BuildMenuButton::BuildMenuButton ( const std::string tx,
const std::string category 
)

Definition at line 457 of file BuildMenu.cxx.

457  : m_texstr(tx), m_id(id)
458 {
460  SDL_QueryTexture(m_tex, nullptr, nullptr, &m_texSize.w, &m_texSize.h);
461  m_btnSize = ImVec2(m_texSize.w, m_texSize.h);
462  m_destRect = ImVec4(0, 0, (float)m_texSize.w, (float)m_texSize.h);
463 }
+ Here is the call graph for this function:

◆ BuildMenuButton() [2/2]

BuildMenuButton::BuildMenuButton ( const std::string tx,
const std::string category,
const TileData tile 
)

Definition at line 465 of file BuildMenu.cxx.

466  : m_background(true), m_texstr(tx), m_id(id), m_tiletype(tx)
467 {
468  int bWid = Settings::instance().subMenuButtonWidth; //UI button width for sub menues
469  int bHei = Settings::instance().subMenuButtonHeight; //UI button height for sub menues
470 
471  SDL_Rect destRect;
472  scaleCenterImage(destRect, bWid, bHei, tile.tiles.clippingWidth, tile.tiles.clippingHeight);
473 
475  SDL_QueryTexture(m_tex, nullptr, nullptr, &m_texSize.w, &m_texSize.h);
476  m_uv0 = ImVec2((float)(tile.tiles.clippingWidth * tile.tiles.offset) / (float)m_texSize.w, 0.f);
477  m_uv1 = ImVec2(m_uv0.x + (float)(tile.tiles.clippingWidth) / (float)m_texSize.w,
478  m_uv0.y + ((float)tile.tiles.clippingHeight) / (float)m_texSize.h);
479  m_btnSize = ImVec2(bWid, bHei);
480  m_destRect = ImVec4((float)destRect.x, (float)destRect.y, (float)destRect.w, (float)destRect.h);
481 }
+ Here is the call graph for this function:

Member Function Documentation

◆ addActionButton()

BuildMenuButton::Ptr BuildMenuButton::addActionButton ( const std::string tx,
const std::string action,
const std::string tooltip 
)

Definition at line 483 of file BuildMenu.cxx.

485 {
486  auto btn = std::make_shared<BuildMenuButton>(tx, action);
487  btn->m_id = tooltip;
488  btn->m_background = true;
489  btn->m_parent = this;
490  btn->m_action = action;
491  m_buttons.push_back(btn);
492  return btn;
493 }

◆ addButtonImpl()

BuildMenuButton::Ptr BuildMenuButton::addButtonImpl ( const std::string tx,
const std::string id,
const TileData tile 
)

Definition at line 495 of file BuildMenu.cxx.

496 {
497  auto btn = std::make_shared<BuildMenuButton>(tx, id, tile);
498  btn->m_parent = this;
499  m_buttons.push_back(btn);
500  return btn;
501 }
+ Here is the caller graph for this function:

◆ addCategoryButton()

Ptr BuildMenuButton::addCategoryButton ( const std::string tx,
const std::string id,
const TileData tile 
)
inline

Definition at line 40 of file BuildMenu.hxx.

41  {
42  return addButtonImpl(tx, id, tile);
43  }
+ Here is the call graph for this function:

◆ addTileButton()

Ptr BuildMenuButton::addTileButton ( const std::string tx,
const std::string id,
const TileData tile 
)
inline

Definition at line 46 of file BuildMenu.hxx.

46 { return addButtonImpl(tx, id, tile); }
+ Here is the call graph for this function:

◆ getBtnSize()

const ImVec2& BuildMenuButton::getBtnSize ( ) const
inline

Definition at line 66 of file BuildMenu.hxx.

66 { return m_btnSize; }

◆ getButtons()

const Items& BuildMenuButton::getButtons ( ) const
inline

Definition at line 68 of file BuildMenu.hxx.

68 { return m_buttons; }

◆ getId()

const std::string& BuildMenuButton::getId ( ) const
inline

Definition at line 67 of file BuildMenu.hxx.

67 { return m_id; }

◆ hideItems()

void BuildMenuButton::hideItems ( )

Definition at line 523 of file BuildMenu.cxx.

524 {
525  m_open = false;
526  for (auto btn : m_buttons)
527  {
528  btn->hideItems();
529  }
530 }

◆ scaleCenterImage()

void BuildMenuButton::scaleCenterImage ( SDL_Rect &  ret,
int  btnW,
int  btnH,
int  imgW,
int  imgH 
) const

takes an SDL_Rect, default button width and height, and image width and height and scales the image to fit on a button of the default button size (maintaining the aspect ration of the original image).

Parameters
retthe address of a rect that will contain the size of the scaled image
btnWthe default button width
btnHthe default button height
imgWthe width of the image to scale
imgHthe height of the image to scale

Definition at line 503 of file BuildMenu.cxx.

504 {
505  if (imgW > imgH)
506  {
507  float ratio = (float)imgH / (float)imgW;
508  ret.w = btnW;
509  ret.h = static_cast<int>(ceil((float)btnH * ratio));
510  ret.x = 0;
511  ret.y = btnH - ret.h;
512  }
513  else
514  {
515  float ratio = (float)imgW / (float)imgH;
516  ret.w = static_cast<int>(ceil((float)btnW * ratio));
517  ret.h = btnH;
518  ret.x = static_cast<int>(ceil(((float)(btnW - ret.w)) / 2));
519  ret.y = 0;
520  }
521 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_action

std::string BuildMenuButton::m_action

Definition at line 19 of file BuildMenu.hxx.

◆ m_background

bool BuildMenuButton::m_background = false

Definition at line 15 of file BuildMenu.hxx.

◆ m_btnSize

ImVec2 BuildMenuButton::m_btnSize

Definition at line 29 of file BuildMenu.hxx.

◆ m_buttons

Items BuildMenuButton::m_buttons

Definition at line 31 of file BuildMenu.hxx.

◆ m_destRect

ImVec4 BuildMenuButton::m_destRect

Definition at line 28 of file BuildMenu.hxx.

◆ m_id

std::string BuildMenuButton::m_id

Definition at line 18 of file BuildMenu.hxx.

◆ m_open

bool BuildMenuButton::m_open = false

Definition at line 14 of file BuildMenu.hxx.

◆ m_parent

BuildMenuButton* BuildMenuButton::m_parent = nullptr

Definition at line 26 of file BuildMenu.hxx.

◆ m_tex

SDL_Texture* BuildMenuButton::m_tex

Definition at line 22 of file BuildMenu.hxx.

◆ m_texSize

ImSpan2i BuildMenuButton::m_texSize

Definition at line 25 of file BuildMenu.hxx.

◆ m_texstr

std::string BuildMenuButton::m_texstr

Definition at line 17 of file BuildMenu.hxx.

◆ m_tiletype

std::string BuildMenuButton::m_tiletype

Definition at line 20 of file BuildMenu.hxx.

◆ m_uv0

ImVec2 BuildMenuButton::m_uv0 = ImVec2{0, 0}

Definition at line 23 of file BuildMenu.hxx.

◆ m_uv1

ImVec2 BuildMenuButton::m_uv1 = ImVec2{1, 1}

Definition at line 24 of file BuildMenu.hxx.


The documentation for this struct was generated from the following files:
BuildMenuButton::m_tex
SDL_Texture * m_tex
Definition: BuildMenu.hxx:22
BuildMenuButton::m_id
std::string m_id
Definition: BuildMenu.hxx:18
BuildMenuButton::m_texstr
std::string m_texstr
Definition: BuildMenu.hxx:17
BuildMenuButton::m_background
bool m_background
Definition: BuildMenu.hxx:15
SettingsData::subMenuButtonWidth
int subMenuButtonWidth
The width in pixels of the buttons used in the build sub menues on the UI.
Definition: Settings.hxx:154
ResourcesManager::getUITexture
SDL_Texture * getUITexture(const std::string &uiElement)
retrieves texture for a tileID
Definition: ResourcesManager.cxx:44
TileData::tiles
TileSetData tiles
Tile Spritesheet information.
Definition: tileData.hxx:148
BuildMenuButton::m_uv0
ImVec2 m_uv0
Definition: BuildMenu.hxx:23
TileManager::getTexture
SDL_Texture * getTexture(const std::string &tileID) const
Get the Texture for the tileID.
Definition: TileManager.cxx:17
BuildMenuButton::m_uv1
ImVec2 m_uv1
Definition: BuildMenu.hxx:24
SettingsData::subMenuButtonHeight
int subMenuButtonHeight
The height in pixels of the buttons used in the build sub menues on the UI.
Definition: Settings.hxx:160
BuildMenuButton::scaleCenterImage
void scaleCenterImage(SDL_Rect &ret, int btnW, int btnH, int imgW, int imgH) const
takes an SDL_Rect, default button width and height, and image width and height and scales the image t...
Definition: BuildMenu.cxx:503
BuildMenuButton::m_texSize
ImSpan2i m_texSize
Definition: BuildMenu.hxx:25
BuildMenuButton::m_open
bool m_open
Definition: BuildMenu.hxx:14
BuildMenuButton::m_destRect
ImVec4 m_destRect
Definition: BuildMenu.hxx:28
BuildMenuButton::m_btnSize
ImVec2 m_btnSize
Definition: BuildMenu.hxx:29
BuildMenuButton::m_tiletype
std::string m_tiletype
Definition: BuildMenu.hxx:20
Singleton< ResourcesManager >::instance
static ResourcesManager & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
BuildMenuButton::addButtonImpl
Ptr addButtonImpl(const std::string &tx, const std::string &id, const TileData &tile)
Definition: BuildMenu.cxx:495
BuildMenuButton::m_buttons
Items m_buttons
Definition: BuildMenu.hxx:31