|
From: Tapio V. <aa...@us...> - 2010-08-21 18:03:52
|
Module: performous
Branch: master
Commit: 6d757abe88d70767e5149b93fed23a12caaa5a14
Author: Tapio Vierros <tap...@gm...>
Date: Mon Aug 2 20:23:26 2010 +0300
Better horizontal position & size calculation for instrument menu + comment.
---
game/instrumentgraph.cc | 11 ++++++++---
game/menu.cc | 1 +
game/menu.hh | 2 ++
game/opengl_text.hh | 2 ++
game/screen_sing.cc | 11 ++++++++---
game/theme.cc | 1 +
6 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/game/instrumentgraph.cc b/game/instrumentgraph.cc
index 76e5455..b6e1443 100644
--- a/game/instrumentgraph.cc
+++ b/game/instrumentgraph.cc
@@ -62,15 +62,18 @@ void InstrumentGraph::drawMenu() {
// Some helper vars
ThemeInstrumentMenu& th = *m_menuTheme;
MenuOptions::const_iterator cur = static_cast<MenuOptions::const_iterator>(&m_menu.current());
+ double w = m_menu.dimensions.w();
const double offsetX = 0.5f * (dimensions.x1() + dimensions.x2());
const float txth = th.option.h();
const float step = txth * 0.7f;
const float h = m_menu.getOptions().size() * step + step;
float y = -h * .5f + step;
+ float x = -w * .5f + step + offsetX;
// Background
- th.bg.dimensions.middle(.05 + offsetX).center(0).stretch(.45, h);
+ th.bg.dimensions.middle(offsetX).center(0).stretch(w, h);
th.bg.draw();
// Loop through menu items
+ w = 0;
for (MenuOptions::const_iterator it = m_menu.begin(); it != m_menu.end(); ++it) {
SvgTxtTheme* txt = &th.option;
if (cur == it) {
@@ -78,16 +81,18 @@ void InstrumentGraph::drawMenu() {
//th.back_h.draw();
txt = &th.option_selected;
}
- txt->dimensions.middle(-0.1 + offsetX).center(y);
+ txt->dimensions.middle(x).center(y);
txt->draw(it->getName());
+ w = std::max(w, txt->w() + 2 * step); // Calculate the widest entry
y += step;
}
if (cur->getComment() != "") {
//th.comment_bg.dimensions.middle().screenBottom(-0.2);
//th.comment_bg.draw();
- th.comment.dimensions.middle(-0.1 + offsetX).screenBottom(-0.12);
+ th.comment.dimensions.middle(offsetX).screenBottom(-0.12);
th.comment.draw(cur->getComment());
}
+ m_menu.dimensions.stretch(w, h);
}
diff --git a/game/menu.cc b/game/menu.cc
index 265ca3f..7d44b35 100644
--- a/game/menu.cc
+++ b/game/menu.cc
@@ -62,6 +62,7 @@ MenuOption::MenuOption(const std::string& nm, const std::string& comm, const std
Menu::Menu():
+ dimensions(),
m_open(true)
{
clear();
diff --git a/game/menu.hh b/game/menu.hh
index ab5e883..a2be1c2 100644
--- a/game/menu.hh
+++ b/game/menu.hh
@@ -77,6 +77,8 @@ struct Menu {
const MenuOptions::const_iterator end() const { return menu_stack.back()->end(); }
const MenuOptions getOptions() const { return *menu_stack.back(); }
+ Dimensions dimensions;
+
private:
MenuOptions root_options;
SubmenuStack menu_stack;
diff --git a/game/opengl_text.hh b/game/opengl_text.hh
index 0a74b05..5dc228c 100644
--- a/game/opengl_text.hh
+++ b/game/opengl_text.hh
@@ -153,6 +153,8 @@ class SvgTxtTheme {
double w() const { return m_texture_width; }
/// height
double h() const { return m_texture_height; }
+ /// set align
+ void setAlign(Align align) { m_align = align; }
private:
boost::ptr_vector<OpenGLText> m_opengl_text;
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 25a2d34..e7109e6 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -488,27 +488,32 @@ void ScreenSing::drawMenu() {
// Some helper vars
ThemeInstrumentMenu& th = *m_menuTheme;
MenuOptions::const_iterator cur = static_cast<MenuOptions::const_iterator>(&m_menu.current());
+ double w = m_menu.dimensions.w();
const float txth = th.option.h();
const float step = txth * 0.85f;
const float h = m_menu.getOptions().size() * step + step;
float y = -h * .5f + step;
+ float x = -w * .5f + step;
// Background
- th.bg.dimensions.middle(.05).center(0).stretch(.45, h);
+ th.bg.dimensions.middle(0).center(0).stretch(w, h);
th.bg.draw();
// Loop through menu items
+ w = 0;
for (MenuOptions::const_iterator it = m_menu.begin(); it != m_menu.end(); ++it) {
SvgTxtTheme* txt = &th.option;
if (cur == it) {
txt = &th.option_selected;
}
- txt->dimensions.middle(-0.1).center(y);
+ txt->dimensions.middle(x).center(y);
txt->draw(it->getName());
+ w = std::max(w, txt->w() + 2 * step); // Calculate the widest entry
y += step;
}
if (cur->getComment() != "") {
- th.comment.dimensions.middle(-0.1).screenBottom(-0.12);
+ th.comment.dimensions.middle(0).screenBottom(-0.12);
th.comment.draw(cur->getComment());
}
+ m_menu.dimensions.stretch(w, h);
}
diff --git a/game/theme.cc b/game/theme.cc
index ac90a57..73b07b1 100644
--- a/game/theme.cc
+++ b/game/theme.cc
@@ -66,4 +66,5 @@ ThemeInstrumentMenu::ThemeInstrumentMenu():
//comment_bg(getThemePath("menu_comment_bg.svg"))
{
back_h.dimensions.fixedHeight(0.08f);
+ comment.setAlign(SvgTxtTheme::CENTER);
}
|