From 73817a99d5e92deec732dbebb6acb2eaeff5fa82 Mon Sep 17 00:00:00 2001 From: cosmosninja Date: Fri, 2 May 2008 20:58:26 +0000 Subject: [PATCH] GUI improvements: removes warnings, fixes bugs, adds some capabilities. Sorry for the late commit, I thought I had done it last night. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1806 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/gui/challenges_menu.cpp | 35 +++-------- src/gui/credits_menu.cpp | 18 ++---- src/gui/feature_unlocked.cpp | 29 +++------ src/gui/grand_prix_select.cpp | 3 +- src/gui/help_page_one.cpp | 68 +++++++++----------- src/gui/help_page_two.cpp | 114 ++++++++++++---------------------- src/gui/track_sel.cpp | 4 +- src/widget.cpp | 36 ++++++----- src/widget.hpp | 9 +-- src/widget_manager.cpp | 88 ++++++++++++++++++++------ src/widget_manager.hpp | 27 +++++--- 11 files changed, 206 insertions(+), 225 deletions(-) diff --git a/src/gui/challenges_menu.cpp b/src/gui/challenges_menu.cpp index 7eb10c884..dc8d43c7f 100755 --- a/src/gui/challenges_menu.cpp +++ b/src/gui/challenges_menu.cpp @@ -33,39 +33,22 @@ enum WidgetTokens ChallengesMenu::ChallengesMenu() { - const bool SHOW_RECT = true; - const bool SHOW_TEXT = true; - widget_manager->setInitialActivationState(false); - widget_manager->setInitialRectState(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK); - widget_manager->setInitialTextState(SHOW_TEXT, "", WGT_FNT_MED, WGT_FONT_GUI, WGT_WHITE, false ); - - widget_manager->addWgt( WTOK_TITLE, 60, 10); - widget_manager->showWgtRect( WTOK_TITLE ); - widget_manager->setWgtText( WTOK_TITLE, _("Active Challenges")); - widget_manager->setWgtTextSize( WTOK_TITLE, WGT_FNT_LRG); - widget_manager->showWgtText( WTOK_TITLE ); + widget_manager->addTitleWgt( WTOK_TITLE, 60, 10, _("Active Challenges")); widget_manager->breakLine(); m_all_challenges=unlock_manager->getActiveChallenges(); for(int i=0; i<(int)m_all_challenges.size(); i++) { - widget_manager->addWgt(WTOK_CHALLENGES+i, 60, 10); - widget_manager->setWgtText( WTOK_CHALLENGES+i, _(m_all_challenges[i]->getName().c_str()) ); - widget_manager->activateWgt(WTOK_CHALLENGES+i); - widget_manager->breakLine(); + widget_manager->addTextButtonWgt(WTOK_CHALLENGES+i, 60, 10, + _(m_all_challenges[i]->getName().c_str()) ); + widget_manager->breakLine(); } - widget_manager->addWgt( WTOK_DESCRIPTION, 60, 30); - widget_manager->showWgtRect( WTOK_DESCRIPTION ); - widget_manager->setWgtText( WTOK_DESCRIPTION, ""); - widget_manager->showWgtText( WTOK_DESCRIPTION ); + widget_manager->addTextButtonWgt( WTOK_DESCRIPTION, 60, 30, ""); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_BACK, 50, 7); - widget_manager->showWgtRect(WTOK_BACK); - widget_manager->showWgtText(WTOK_BACK); - widget_manager->setWgtText(WTOK_BACK, _("Go back to the main menu")); - widget_manager->activateWgt(WTOK_BACK); + widget_manager->addTextButtonWgt(WTOK_BACK, 50, 7, + _("Go back to the main menu")); widget_manager->layout(WGT_AREA_ALL); } // ChallengesMenu @@ -83,9 +66,9 @@ void ChallengesMenu::update(float dt) if(challenge>=0 && challenge<(int)m_all_challenges.size()) { widget_manager->setWgtText(WTOK_DESCRIPTION, - m_all_challenges[challenge]->getChallengeDescription()); + m_all_challenges[challenge]->getChallengeDescription()); } - BaseGUI::update(dt); + widget_manager->update(dt); } // update //----------------------------------------------------------------------------- diff --git a/src/gui/credits_menu.cpp b/src/gui/credits_menu.cpp index 6b305ef3f..d3426c006 100644 --- a/src/gui/credits_menu.cpp +++ b/src/gui/credits_menu.cpp @@ -63,25 +63,17 @@ CreditsMenu::CreditsMenu() } - const bool SHOW_RECT = true; - const bool SHOW_TEXT = true; - const WidgetFontSize TEXT_SIZE = WGT_FNT_SML; - - widget_manager->setInitialActivationState( true ); - widget_manager->setInitialRectState(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK); - widget_manager->setInitialTextState(SHOW_TEXT, "", TEXT_SIZE, - WGT_FONT_GUI, WGT_WHITE, false ); - - widget_manager->addWgt( WTOK_CREDITS, 100, 93); - widget_manager->setWgtText( WTOK_CREDITS, credits_text ); + widget_manager->addTextWgt( WTOK_CREDITS, 100, 93, credits_text ); + widget_manager->setWgtTextSize( WTOK_CREDITS, WGT_FNT_SML ); //FIXME: maybe I should make scroll names more consistent + widget_manager->activateWgt( WTOK_CREDITS ); widget_manager->enableWgtScroll( WTOK_CREDITS ); widget_manager->setWgtYScrollPos( WTOK_CREDITS, WGT_SCROLL_START_BOTTOM ); widget_manager->setWgtYScrollSpeed( WTOK_CREDITS, -80 ); widget_manager->breakLine(); - widget_manager->addWgt( WTOK_QUIT, 40, 7); - widget_manager->setWgtText( WTOK_QUIT, _("Go back to the main menu")); + widget_manager->addTextButtonWgt( WTOK_QUIT, 40, 7, + _("Go back to the main menu")); widget_manager->layout( WGT_AREA_TOP ); } // CreditsMenu diff --git a/src/gui/feature_unlocked.cpp b/src/gui/feature_unlocked.cpp index aec888667..968c20a58 100755 --- a/src/gui/feature_unlocked.cpp +++ b/src/gui/feature_unlocked.cpp @@ -32,34 +32,19 @@ enum WidgetTokens FeatureUnlocked::FeatureUnlocked() { - const bool SHOW_RECT = true; - const bool SHOW_TEXT = true; - widget_manager->setInitialActivationState(false); - widget_manager->setInitialRectState(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK); - widget_manager->setInitialTextState(SHOW_TEXT, "", WGT_FNT_MED, WGT_FONT_GUI, WGT_WHITE, false ); - - widget_manager->addWgt( WTOK_TITLE, 60, 10); - widget_manager->showWgtRect( WTOK_TITLE ); - widget_manager->setWgtText( WTOK_TITLE, _("New Feature Unlocked")); - widget_manager->setWgtTextSize( WTOK_TITLE, WGT_FNT_LRG); - widget_manager->showWgtText( WTOK_TITLE ); - widget_manager->breakLine(); + widget_manager->insertColumn(); + widget_manager->addTitleWgt( WTOK_TITLE, 60, 10, + _("New Feature Unlocked")); m_new_features=unlock_manager->getUnlockedFeatures(); assert(m_new_features.size()>0); unlock_manager->clearUnlocked(); - widget_manager->addWgt( WTOK_DESCRIPTION, 60, 30); - widget_manager->showWgtRect( WTOK_DESCRIPTION ); - widget_manager->setWgtText( WTOK_DESCRIPTION, m_new_features[0]->getFeatureDescription()); - widget_manager->showWgtText( WTOK_DESCRIPTION ); - widget_manager->breakLine(); + widget_manager->addTextWgt( WTOK_DESCRIPTION, 60, 30, + m_new_features[0]->getFeatureDescription()); - widget_manager->addWgt(WTOK_CONTINUE, 50, 7); - widget_manager->showWgtRect(WTOK_CONTINUE); - widget_manager->showWgtText(WTOK_CONTINUE); - widget_manager->setWgtText(WTOK_CONTINUE, _("Continue")); - widget_manager->activateWgt(WTOK_CONTINUE); + widget_manager->addTextButtonWgt(WTOK_CONTINUE, 50, 7, + _("Continue")); widget_manager->layout(WGT_AREA_ALL); } // FeatureUnlocked diff --git a/src/gui/grand_prix_select.cpp b/src/gui/grand_prix_select.cpp index d4ed024ac..db3fa50d2 100644 --- a/src/gui/grand_prix_select.cpp +++ b/src/gui/grand_prix_select.cpp @@ -77,8 +77,7 @@ GrandPrixSelect::GrandPrixSelect() : m_curr_track_img(0), m_clock(0.0f) widget_manager->enableWgtScroll( WTOK_TRACKS ); widget_manager->setWgtYScrollSpeed( WTOK_TRACKS, -60 ); - widget_manager->addEmptyWgt( WTOK_IMG, 40, 40 ); - widget_manager->showWgtRect( WTOK_IMG ); + widget_manager->addImgWgt( WTOK_IMG, 40, 40, 0 ); widget_manager->setWgtColor( WTOK_IMG, WGT_BLACK ); widget_manager->breakLine(); diff --git a/src/gui/help_page_one.cpp b/src/gui/help_page_one.cpp index 2c03e3365..5af095a9e 100644 --- a/src/gui/help_page_one.cpp +++ b/src/gui/help_page_one.cpp @@ -35,8 +35,6 @@ enum WidgetTokens WTOK_MSG4, WTOK_MSG5, - WTOK_EMPTY, - WTOK_FIRST_KEYNAME, WTOK_LAST_KEYNAME = WTOK_FIRST_KEYNAME + KA_LAST, @@ -61,24 +59,23 @@ HelpPageOne::HelpPageOne() m_clock = 0; - const bool SHOW_RECT = true; - const bool SHOW_TEXT = true; - const WidgetFontSize TEXT_SIZE = WGT_FNT_SML; - - widget_manager->setInitialRectState( SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK ); - widget_manager->setInitialTextState( SHOW_TEXT, "", TEXT_SIZE, - WGT_FONT_GUI, WGT_WHITE, false ); - - /*Help header*/ - widget_manager->addWgt(WTOK_MSG1, 50, 7); - widget_manager->setWgtText( WTOK_MSG1, _("Force your rivals bite *your* dust!") ); + //FIXME: instead of using setInitialTextState, the gui & widget manager macros should improve it's design + widget_manager->setInitialTextState + ( + false, + "", + WGT_FNT_SML, + WGT_FONT_GUI, + WGT_WHITE, + false + ); + widget_manager->addTextWgt( WTOK_MSG1, 50, 7, + _("Force your rivals bite *your* dust!") ); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_MSG2, 60, 7); - widget_manager->setWgtText( WTOK_MSG2, _("Grab blue boxes and coins") ); - - widget_manager->addWgt(WTOK_MSG3, 30, 7); - widget_manager->setWgtText( WTOK_MSG3, _("Avoid bananas") ); + widget_manager->addTextWgt( WTOK_MSG2, 60, 7, + _("Grab blue boxes and coins") ); + widget_manager->addTextWgt( WTOK_MSG3, 30, 7, _("Avoid bananas") ); widget_manager->breakLine(); /*Rotating 3D models*/ @@ -107,20 +104,16 @@ HelpPageOne::HelpPageOne() m_banana->addKid(hm); /*Empty widget to cover the space for the 3D models*/ - widget_manager->addWgt(WTOK_EMPTY, 100, 15); - widget_manager->hideWgtRect(WTOK_EMPTY); - widget_manager->hideWgtText(WTOK_EMPTY); + widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 100, 15); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_MSG4, 100, 10); - widget_manager->setWgtText( WTOK_MSG4, + widget_manager->addTextWgt(WTOK_MSG4, 100, 10, //Next line starts at column 0 to avoid spaces in the GUI _("At high speeds wheelies drive you faster, but you can't steer. If you\n\ get stuck or fall too far, use the rescue button to get back on track.")); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_MSG5, 70, 7); - widget_manager->setWgtText( WTOK_MSG5, + widget_manager->addTextWgt(WTOK_MSG5, 70, 7, _("Check the current key bindings for the first player")); widget_manager->breakLine(); @@ -129,34 +122,30 @@ get stuck or fall too far, use the rescue button to get back on track.")); * number of kart actions without changing this screen. */ for(int i = WTOK_FIRST_KEYNAME; i <= WTOK_LAST_KEYNAME; ++i) { - widget_manager->addWgt( i, 20, 4 ); - widget_manager->setWgtRoundCorners( i, WGT_AREA_LFT ); - widget_manager->setWgtText( i, + widget_manager->addTextWgt( i, 20, 4, sKartAction2String[i - WTOK_FIRST_KEYNAME] ); + widget_manager->setWgtRoundCorners( i, WGT_AREA_LFT ); } widget_manager->breakLine(); widget_manager->insertColumn(); for(int i = WTOK_FIRST_KEYBINDING; i <= WTOK_LAST_KEYBINDING; ++i) { - widget_manager->addWgt( i, 20, 4 ); - widget_manager->setWgtRoundCorners( i, WGT_AREA_RGT ); - widget_manager->setWgtText( i, + widget_manager->addTextWgt( i, 20, 4, user_config->getMappingAsString( 0, (KartAction)(i - WTOK_FIRST_KEYBINDING)).c_str()); + widget_manager->setWgtRoundCorners( i, WGT_AREA_RGT ); } widget_manager->breakLine(); widget_manager->breakLine(); /*Buttons at the bottom*/ - widget_manager->addWgt(WTOK_SECOND_PAGE, 20, 7); - widget_manager->setWgtText(WTOK_SECOND_PAGE, _("Next screen")); - widget_manager->activateWgt(WTOK_SECOND_PAGE); + widget_manager->addTextButtonWgt(WTOK_SECOND_PAGE, 20, 7, + _("Next screen")); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_QUIT, 40, 7); - widget_manager->setWgtText(WTOK_QUIT, _("Go back to the main menu")); - widget_manager->activateWgt(WTOK_QUIT); + widget_manager->addTextButtonWgt(WTOK_QUIT, 40, 7, + _("Go back to the main menu")); widget_manager->layout( WGT_AREA_TOP ); } // HelpPageOne @@ -183,7 +172,6 @@ HelpPageOne::~HelpPageOne() void HelpPageOne::update(float dt) { m_clock += dt * 40.0f; - BaseGUI::update(dt); if (m_box != NULL && m_silver_coin != NULL && m_gold_coin != NULL && m_banana != NULL ) @@ -221,6 +209,8 @@ void HelpPageOne::update(float dt) glDisable (GL_DEPTH_TEST); oldContext->makeCurrent(); } + + widget_manager->update(dt); } //----------------------------------------------------------------------------- @@ -229,7 +219,7 @@ void HelpPageOne::select() switch ( widget_manager->getSelectedWgt() ) { case WTOK_SECOND_PAGE: - //This switches thee first page with the second page, so they + //This switches the first page with the second page, so they //are not stacked by the menu manager, and the menu that called //this help is the one that gets called back when the next page //is popped. diff --git a/src/gui/help_page_two.cpp b/src/gui/help_page_two.cpp index 7215f937c..fdc19cbad 100644 --- a/src/gui/help_page_two.cpp +++ b/src/gui/help_page_two.cpp @@ -29,14 +29,14 @@ enum WidgetTokens { - WTOK_MSG6, + WTOK_MSG, - WTOK_ITEMIMG1, WTOK_ITEMTXT1, - WTOK_ITEMIMG2, WTOK_ITEMTXT2, - WTOK_ITEMIMG3, WTOK_ITEMTXT3, - WTOK_ITEMIMG4, WTOK_ITEMTXT4, - WTOK_ITEMIMG5, WTOK_ITEMTXT5, - WTOK_ITEMIMG6, WTOK_ITEMTXT6, + WTOK_IMG1, WTOK_TXT1, + WTOK_IMG2, WTOK_TXT2, + WTOK_IMG3, WTOK_TXT3, + WTOK_IMG4, WTOK_TXT4, + WTOK_IMG5, WTOK_TXT5, + WTOK_IMG6, WTOK_TXT6, WTOK_FIRST_PAGE, WTOK_QUIT @@ -44,110 +44,76 @@ enum WidgetTokens HelpPageTwo::HelpPageTwo() { + //FIXME: instead of using setInitialTextState, the gui & widget manager macros should improve it's design + widget_manager->setInitialTextState + ( + false, + "", + WGT_FNT_SML, + WGT_FONT_GUI, + WGT_WHITE, + false + ); - /* Add the widgets */ - const bool SHOW_RECT = true; - const WidgetFontSize TEXT_SIZE = WGT_FNT_SML; - widget_manager->setInitialRectState( SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK ); - widget_manager->setInitialTextState( false, "", TEXT_SIZE, - WGT_FONT_GUI, WGT_WHITE, false ); - - widget_manager->addWgt(WTOK_MSG6, 100, 8); - widget_manager->setWgtText(WTOK_MSG6, + widget_manager->addTextWgt( WTOK_MSG, 100, 8, _("To help you win, there are certain collectables you can grab:")); - widget_manager->showWgtText( WTOK_MSG6 ); widget_manager->breakLine(); - /* Collectable images and descriptions */ - widget_manager->addWgt(WTOK_ITEMIMG1, 10, 13); - widget_manager->setWgtTexture(WTOK_ITEMIMG1, + widget_manager->addImgWgt( WTOK_IMG1, 10, 13, collectable_manager->getIcon(COLLECT_MISSILE)->getState()->getTextureHandle()); - widget_manager->setWgtColor(WTOK_ITEMIMG1, WGT_WHITE); - widget_manager->showWgtTexture(WTOK_ITEMIMG1); - widget_manager->setWgtRoundCorners(WTOK_ITEMIMG1, WGT_AREA_NONE); - widget_manager->addWgt(WTOK_ITEMTXT1, 90, 13); - widget_manager->setWgtText( WTOK_ITEMTXT1, + widget_manager->addTextWgt( WTOK_TXT1, 90, 13, _("Missile - fast stopper in a straight line")); - widget_manager->showWgtText( WTOK_ITEMTXT1 ); + widget_manager->setWgtRoundCorners( WTOK_TXT1, WGT_AREA_RGT ); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_ITEMIMG2, 10, 13); - widget_manager->setWgtTexture(WTOK_ITEMIMG2, + widget_manager->addImgWgt(WTOK_IMG2, 10, 13, collectable_manager->getIcon(COLLECT_HOMING)->getState()->getTextureHandle()); - widget_manager->setWgtColor(WTOK_ITEMIMG2, WGT_WHITE); - widget_manager->showWgtTexture( WTOK_ITEMIMG2 ); - widget_manager->setWgtRoundCorners(WTOK_ITEMIMG2, WGT_AREA_NONE); - widget_manager->addWgt(WTOK_ITEMTXT2, 90, 13); - widget_manager->setWgtText( WTOK_ITEMTXT2, + widget_manager->addTextWgt(WTOK_TXT2, 90, 13, _("Homing missile - follows rivals, but is slower than the missile")); - widget_manager->showWgtText( WTOK_ITEMTXT2 ); + widget_manager->setWgtRoundCorners( WTOK_TXT2, WGT_AREA_RGT ); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_ITEMIMG3, 10, 13); - widget_manager->setWgtTexture(WTOK_ITEMIMG3, + widget_manager->addImgWgt(WTOK_IMG3, 10, 13, collectable_manager->getIcon(COLLECT_SPARK)->getState()->getTextureHandle()); - widget_manager->setWgtColor(WTOK_ITEMIMG3, WGT_WHITE); - widget_manager->showWgtTexture( WTOK_ITEMIMG3 ); - widget_manager->setWgtRoundCorners(WTOK_ITEMIMG3, WGT_AREA_NONE); - widget_manager->addWgt(WTOK_ITEMTXT3, 90, 13); - widget_manager->setWgtText( WTOK_ITEMTXT3, + widget_manager->addTextWgt(WTOK_TXT3, 90, 13, _("Fuzzy blob/Spark - very slow, but bounces from walls")); - widget_manager->showWgtText( WTOK_ITEMTXT3 ); + widget_manager->setWgtRoundCorners( WTOK_TXT3, WGT_AREA_RGT ); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_ITEMIMG4, 10, 13); - widget_manager->setWgtTexture(WTOK_ITEMIMG4, + widget_manager->addImgWgt(WTOK_IMG4, 10, 13, collectable_manager->getIcon(COLLECT_ZIPPER)->getState()->getTextureHandle()); - widget_manager->setWgtColor(WTOK_ITEMIMG4, WGT_WHITE); - widget_manager->showWgtTexture( WTOK_ITEMIMG4 ); - widget_manager->setWgtRoundCorners(WTOK_ITEMIMG4, WGT_AREA_NONE); - widget_manager->addWgt(WTOK_ITEMTXT4, 90, 13); - widget_manager->setWgtText( WTOK_ITEMTXT4, + widget_manager->addTextWgt(WTOK_TXT4, 90, 13, _("Zipper - speed boost")); - widget_manager->showWgtText( WTOK_ITEMTXT4 ); + widget_manager->setWgtRoundCorners(WTOK_TXT4, WGT_AREA_RGT); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_ITEMIMG5, 10, 13); - widget_manager->setWgtTexture(WTOK_ITEMIMG5, + widget_manager->addImgWgt(WTOK_IMG5, 10, 13, collectable_manager->getIcon(COLLECT_PARACHUTE)->getState()->getTextureHandle()); - widget_manager->setWgtColor(WTOK_ITEMIMG5, WGT_WHITE); - widget_manager->showWgtTexture( WTOK_ITEMIMG5 ); - widget_manager->setWgtRoundCorners(WTOK_ITEMIMG5, WGT_AREA_NONE); - widget_manager->addWgt(WTOK_ITEMTXT5, 90, 13); - widget_manager->setWgtText( WTOK_ITEMTXT5, + widget_manager->addTextWgt(WTOK_TXT5, 90, 13, _("Parachute - slows down all karts in a better position!")); - widget_manager->showWgtText( WTOK_ITEMTXT5 ); + widget_manager->setWgtRoundCorners(WTOK_TXT5, WGT_AREA_RGT); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_ITEMIMG6, 10, 13); - widget_manager->setWgtTexture(WTOK_ITEMIMG6, + widget_manager->addImgWgt(WTOK_IMG6, 10, 13, collectable_manager->getIcon(COLLECT_ANVIL)->getState()->getTextureHandle()); - widget_manager->setWgtColor(WTOK_ITEMIMG6, WGT_WHITE); - widget_manager->showWgtTexture( WTOK_ITEMIMG6 ); - widget_manager->setWgtRoundCorners(WTOK_ITEMIMG6, WGT_AREA_NONE); - widget_manager->addWgt(WTOK_ITEMTXT6, 90, 13); - widget_manager->setWgtText( WTOK_ITEMTXT6, + widget_manager->addTextWgt(WTOK_TXT6, 90, 13, _("Anvil - slows down greatly the kart in the first position")); - widget_manager->showWgtText( WTOK_ITEMTXT6 ); + widget_manager->setWgtRoundCorners(WTOK_TXT6, WGT_AREA_RGT); widget_manager->breakLine(); /*Buttons at the bottom*/ - widget_manager->addWgt(WTOK_FIRST_PAGE, 25, 7); - widget_manager->setWgtText(WTOK_FIRST_PAGE, _("Previous screen")); - widget_manager->showWgtText( WTOK_FIRST_PAGE ); - widget_manager->activateWgt(WTOK_FIRST_PAGE); + widget_manager->addTextButtonWgt(WTOK_FIRST_PAGE, 25, 7, + _("Previous screen")); widget_manager->breakLine(); - widget_manager->addWgt(WTOK_QUIT, 40, 7); - widget_manager->setWgtText(WTOK_QUIT, _("Go back to the main menu")); - widget_manager->showWgtText( WTOK_QUIT ); - widget_manager->activateWgt(WTOK_QUIT); + widget_manager->addTextButtonWgt(WTOK_QUIT, 40, 7, + _("Go back to the main menu")); widget_manager->layout( WGT_AREA_TOP ); } // HelpMenu diff --git a/src/gui/track_sel.cpp b/src/gui/track_sel.cpp index d87f51c7e..2e9ad8db7 100644 --- a/src/gui/track_sel.cpp +++ b/src/gui/track_sel.cpp @@ -73,11 +73,11 @@ TrackSel::TrackSel() } } - widget_manager->addEmptyWgt(WTOK_IMG0, 35, 35); + widget_manager->addImgWgt(WTOK_IMG0, 35, 35, 0); widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 5, 35 ); - widget_manager->addEmptyWgt(WTOK_IMG1, 35, 35); + widget_manager->addImgWgt(WTOK_IMG1, 35, 35, 0); widget_manager->breakLine(); widget_manager->addTextWgt( WTOK_AUTHOR, 80, 9, _("No track selected") ); diff --git a/src/widget.cpp b/src/widget.cpp index 72d5abd0b..7b5aeae6c 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -252,7 +252,7 @@ void Widget::setFont( const WidgetFont FONT ) //----------------------------------------------------------------------------- void Widget::setTexture( const char* FILENAME ) { - Material *m = material_manager->getMaterial( FILENAME ); + Material *m = material_manager->getMaterial( FILENAME, true ); m_texture = m->getState()->getTextureHandle(); } @@ -261,21 +261,22 @@ void Widget::setTexture( const char* FILENAME ) * map to the rectangle as though the corners were not rounded . Returns * false if the call to glGenLists failed, otherwise it returns true. */ -bool Widget::createRect(int radius) +bool Widget::createRect() { + //TODO: show warning if text > rect - if(radius > m_width * 0.5) + if(m_radius > m_width * 0.5) { std::cerr << "Warning: widget's radius > half width.\n"; } - if(radius > m_height * 0.5) + if(m_radius > m_height * 0.5) { std::cerr << "Warning: widget's radius > half height.\n"; } - if(radius < 1) + if(m_radius < 1) { std::cerr << "Warning: widget's radius < 1, setting to 1.\n"; - radius = 1; + m_radius = 1; } if(m_width == 0) @@ -305,7 +306,7 @@ bool Widget::createRect(int radius) //isn't based just on logic, since it went through visual testing to give //the perception of roundness. const int MIN_QUADS = 2; - const int NUM_QUADS = MIN_QUADS + radius; + const int NUM_QUADS = MIN_QUADS + m_radius; int i; @@ -348,8 +349,8 @@ bool Widget::createRect(int radius) //+ 1 parts, and use the angles at those parts to find the //X and Y position of the points. angle = 0.5f * M_PI * (float)i / (float)NUM_QUADS; - circle_x = radius * cos(angle); - circle_y = radius * sin(angle); + circle_x = m_radius * cos(angle); + circle_y = m_radius * sin(angle); //After we generate the positions in circle for the angles, //we have to position each rounded corner properly depending @@ -359,12 +360,12 @@ bool Widget::createRect(int radius) //for a rectangle without rounder corners. inner_vertex[i].resize(3); outer_vertex[i].resize(3); - outer_vertex[i][0] = radius - circle_x; + outer_vertex[i][0] = m_radius - circle_x; inner_vertex[i][0] = outer_vertex[i][0] + BORDER_LENGTH; if( m_round_corners & WGT_AREA_NW ) { - outer_vertex[i][1] = m_height + circle_y - radius; + outer_vertex[i][1] = m_height + circle_y - m_radius; inner_vertex[i][1] = outer_vertex[i][1] - BORDER_LENGTH; } else @@ -375,7 +376,7 @@ bool Widget::createRect(int radius) if( m_round_corners & WGT_AREA_SW ) { - outer_vertex[i][2] = radius - circle_y; + outer_vertex[i][2] = m_radius - circle_y; inner_vertex[i][2] = outer_vertex[i][2] + BORDER_LENGTH; } else @@ -398,17 +399,17 @@ bool Widget::createRect(int radius) //By inverting the use of sin and cos we get corners that are //drawn from left to right instead of right to left - circle_x = radius * sin(angle); - circle_y = radius * cos(angle); + circle_x = m_radius * sin(angle); + circle_y = m_radius * cos(angle); inner_vertex[i+1].resize(3); outer_vertex[i+1].resize(3); - outer_vertex[i+1][0] = m_width - radius + circle_x; + outer_vertex[i+1][0] = m_width - m_radius + circle_x; inner_vertex[i+1][0] = outer_vertex[i+1][0] - BORDER_LENGTH; if( m_round_corners & WGT_AREA_NE ) { - outer_vertex[i+1][1] = m_height - radius + circle_y; + outer_vertex[i+1][1] = m_height - m_radius + circle_y; inner_vertex[i+1][1] = outer_vertex[i+1][1] - BORDER_LENGTH; } else @@ -419,7 +420,7 @@ bool Widget::createRect(int radius) if( m_round_corners & WGT_AREA_SE ) { - outer_vertex[i+1][2] = radius - circle_y; + outer_vertex[i+1][2] = m_radius - circle_y; inner_vertex[i+1][2] = outer_vertex[i+1][2] + BORDER_LENGTH; } else @@ -693,6 +694,7 @@ void Widget::draw() { if( m_enable_border ) { + glDisable ( GL_TEXTURE_2D ); glColor4fv(m_border_color); //FIXME: I should probably revert the values to the defaults within the widget manager diff --git a/src/widget.hpp b/src/widget.hpp index 7c4285646..81686bdd2 100644 --- a/src/widget.hpp +++ b/src/widget.hpp @@ -130,12 +130,13 @@ class Widget friend class WidgetManager; /* Basic widget properties that will always be used. */ - int m_x, m_y; - int m_width, m_height; + int m_x, m_y; + int m_width, m_height; + int m_radius; /* Low level features. They are off by default. */ bool m_enable_rect; - GLuint m_rect_list; //A display list number that draws the rectangle with + GLuint m_rect_list; //A display list number that draws the rectangle with //possibly rounded corners. const GLfloat *m_rect_color; //This const cannot change the value it points to, but it //can change where it points to. @@ -207,7 +208,7 @@ class Widget void setTexture( const char* FILENAME ); /* Functions created simply to organize the code */ - bool createRect(int radius); + bool createRect(); void updateVariables( const float DELTA ); void draw(); void applyTransformations(); diff --git a/src/widget_manager.cpp b/src/widget_manager.cpp index 123aee164..89dba723b 100644 --- a/src/widget_manager.cpp +++ b/src/widget_manager.cpp @@ -74,6 +74,7 @@ bool WidgetManager::addWgt new_id.min_width = MIN_WIDTH; new_id.min_height = MIN_HEIGHT; + new_id.min_radius = m_default_rect_radius; new_id.last_preset_scroll_x = m_default_scroll_preset_x; new_id.last_preset_scroll_y = m_default_scroll_preset_y; @@ -83,9 +84,9 @@ bool WidgetManager::addWgt new_id.widget = new Widget(0, 0, 0, 0); new_id.widget->m_enable_rect = m_default_show_rect; + new_id.widget->m_round_corners = m_default_rect_round_corners; new_id.widget->m_rect_color = m_default_rect_color; - new_id.widget->m_enable_border = m_default_show_border; new_id.widget->m_border_percentage = m_default_border_percentage; new_id.widget->m_border_color = m_default_border_color; @@ -388,22 +389,37 @@ bool WidgetManager::layout(const WidgetArea POSITION) const int NUM_WIDGETS = (int)m_widgets.size(); if( NUM_WIDGETS < 1 ) return true; - int SCREEN_WIDTH = user_config->m_width; - int SCREEN_HEIGHT = user_config->m_height; + const int SCREEN_WIDTH = user_config->m_width; + const int SCREEN_HEIGHT = user_config->m_height; - int width; - int height; - //Resize the widgets. + int width, height; + //Set the widgets' rect shape properties in pixels. for( int i = 0; i < NUM_WIDGETS; ++i ) { - width = (SCREEN_WIDTH * m_widgets[i].min_width) / 100; - height = (SCREEN_HEIGHT * m_widgets[i].min_height) / 100; + width = (int)(SCREEN_WIDTH * m_widgets[i].min_width * 0.01); + height = (int)(SCREEN_HEIGHT * m_widgets[i].min_height * 0.01); m_widgets[i].widget->m_width = width; m_widgets[i].widget->m_height = height; if( m_widgets[i].resize_to_text ) m_widgets[i].widget-> resizeToText(); + + if( width < height ) + { + m_widgets[i].widget->m_radius = (int)( m_widgets[i].min_radius * + m_widgets[i].widget->m_width * 0.01 ); + } + else + { + m_widgets[i].widget->m_radius = (int)( m_widgets[i].min_radius * + m_widgets[i].widget->m_height * 0.01 ); + } + + if( m_widgets[i].widget->m_radius < 1 ) + { + m_widgets[i].widget->m_radius = 1; + } } const int WGTS_WIDTH = calcWidth(); @@ -477,14 +493,6 @@ bool WidgetManager::layout(const WidgetArea POSITION) break; } - //This formula seems not to have much theory behind it, we pick the - //smallest from the screen height and width because if we pick the - //biggest one, it might look bad for the smaller one, but it doesn't - //happens the other way around, and it's divided by 60, maybe because - //it results in small enough values to be of use, or maybe because it's - //divided by 60 minutes? The formula was taken from the old Widget Set. - const int RADIUS = ( SCREEN_HEIGHT < SCREEN_WIDTH ? SCREEN_HEIGHT : SCREEN_WIDTH ) / 60; - /* In this loop we give each widget it's true position on the screen and * create their rect; we start at the position where the first widget * will be, and move right first and down on breaks if the widget is @@ -532,7 +540,7 @@ bool WidgetManager::layout(const WidgetArea POSITION) m_widgets[curr_wgt].widget->m_y = widget_y; //Create widget's rect - if( !(m_widgets[curr_wgt].widget->createRect(RADIUS)) ) + if( !(m_widgets[curr_wgt].widget->createRect()) ) { return false; } @@ -745,6 +753,8 @@ bool WidgetManager::addTitleWgt setWgtTextSize( TOKEN, WGT_FNT_LRG ); showWgtText( TOKEN ); setWgtText( TOKEN, TEXT ); + setWgtRoundCorners( TOKEN, WGT_AREA_ALL ); + setWgtCornerRadius( TOKEN, 20 ); return true; } @@ -761,6 +771,8 @@ bool WidgetManager::addTextWgt if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false; showWgtRect( TOKEN ); + setWgtRoundCorners( TOKEN, WGT_AREA_ALL ); + setWgtCornerRadius( TOKEN, 20 ); showWgtText( TOKEN ); setWgtText( TOKEN, TEXT ); @@ -779,6 +791,8 @@ bool WidgetManager::addTextButtonWgt if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false; showWgtRect( TOKEN ); + setWgtRoundCorners( TOKEN, WGT_AREA_ALL ); + setWgtCornerRadius( TOKEN, 20 ); showWgtText( TOKEN ); setWgtText( TOKEN, TEXT ); activateWgt( TOKEN ); @@ -799,6 +813,9 @@ bool WidgetManager::addImgWgt setWgtColor( TOKEN, WGT_WHITE ); showWgtRect( TOKEN ); + setWgtBorderPercentage( TOKEN, 5 ); + setWgtBorderColor( TOKEN, WGT_BLACK ); + showWgtBorder( TOKEN ); setWgtTexture( TOKEN, IMG ); showWgtTexture( TOKEN ); @@ -818,6 +835,8 @@ bool WidgetManager::addImgButtonWgt setWgtColor( TOKEN, WGT_GRAY ); showWgtRect( TOKEN ); + setWgtRoundCorners( TOKEN, WGT_AREA_ALL ); + setWgtCornerRadius( TOKEN, 20 ); setWgtTexture( TOKEN, IMG ); showWgtTexture( TOKEN ); activateWgt( TOKEN ); @@ -836,11 +855,13 @@ void WidgetManager::setInitialRectState ( const bool SHOW, const WidgetArea ROUND_CORNERS, + const int RADIUS, const GLfloat* const COLOR ) { m_default_show_rect = SHOW; - m_default_rect_round_corners = (ROUND_CORNERS!= WGT_AREA_NONE); + m_default_rect_round_corners = ROUND_CORNERS; + m_default_rect_radius = RADIUS; m_default_rect_color = COLOR; } @@ -934,8 +955,9 @@ void WidgetManager::restoreDefaultStates() //FIXME: maybe instead of 'default' these variables should be 'initial' m_default_active = false; m_default_show_rect = false; - m_default_rect_round_corners = WGT_AREA_NONE; m_default_rect_color = WGT_TRANS_BLACK; + m_default_rect_round_corners = WGT_AREA_NONE; + m_default_rect_radius = 1; m_default_show_border = false; m_default_border_percentage = 0.0; m_default_border_color = WGT_TRANS_WHITE; @@ -1006,6 +1028,34 @@ void WidgetManager::setWgtRoundCorners(const int TOKEN, const WidgetArea CORNERS "unnamed widget with token " << TOKEN << '\n'; } } + +//----------------------------------------------------------------------------- +void WidgetManager::setWgtCornerRadius(const int TOKEN, const int RADIUS) +{ + if( RADIUS > 50 ) + { + std::cerr << "WARNING: tried to set the corner's radius " << + "percentage of a widget with token " << TOKEN << " to " << + "something bigger than 50% \n"; + return; + } + else if( RADIUS < 1 ) + { + std::cerr << "WARNING: tried to set the corner's radius " << + "percentage of a widget with token " << TOKEN << " to " << + "something smaller than 1% \n"; + return; + } + + const int ID = findId(TOKEN); + if( ID != WGT_NONE ) m_widgets[ID].min_radius = RADIUS; + else + { + std::cerr << "WARNING: tried to change the corner radius of an " << + "unnamed widget with token " << TOKEN << '\n'; + } +} + //----------------------------------------------------------------------------- void WidgetManager::showWgtRect(const int TOKEN) { diff --git a/src/widget_manager.hpp b/src/widget_manager.hpp index f3b7caaf5..bcc28903b 100644 --- a/src/widget_manager.hpp +++ b/src/widget_manager.hpp @@ -47,9 +47,10 @@ class WidgetManager bool active; //If true, then this widget is interactive(though by //definition, widgets are supposed to be interactive). - //The percentages of the container this widget takes + //The percentages for the widget's rect int min_width; int min_height; + int min_radius; //The last given preset scroll position is stored, to restore it in //case that the text is changed it needs to be restored. @@ -100,7 +101,8 @@ class WidgetManager bool m_default_resize_to_text; bool m_default_show_rect; - bool m_default_rect_round_corners; + WidgetArea m_default_rect_round_corners; + int m_default_rect_radius; const GLfloat *m_default_rect_color; bool m_default_show_border; @@ -150,6 +152,7 @@ class WidgetManager void setSelectedWgtToken(const int TOKEN); public: + //TODO: remove return values that we don't check static const int WGT_NONE; WidgetManager(); @@ -197,7 +200,8 @@ public: //FIXME: Temporal, till I rename addWgt() to addEmptyWgt() bool addEmptyWgt(const int TOKEN, const int MIN_WIDTH, const int MIN_HEIGHT) {return addWgt(TOKEN,MIN_WIDTH,MIN_HEIGHT);} - //Widget that adds visible rect & text, sets the text and large font + //Widget that adds visible rect & text, rounded corners with 20% radius, + //sets the text, and large font bool addTitleWgt ( const int TOKEN, @@ -206,7 +210,8 @@ public: const std::string TEXT ); - //Widget that adds visible rect & text, and sets the text + //Widget that adds visible rect & text, rounded corners with 20% radius, + //and sets the text bool addTextWgt ( const int TOKEN, @@ -215,7 +220,8 @@ public: const std::string TEXT ); - //Widget that adds visible rect & text, sets the text and is selectable + //Widget that adds visible rect & text, rounded corners with 20% radius, + //sets the text and is selectable bool addTextButtonWgt ( const int TOKEN, @@ -224,7 +230,8 @@ public: const std::string TEXT ); - //Widget that adds visible rect & image, white rect, and sets the texture + //Widget that adds visible rect & image, white rect, 5% black + //border, and sets the texture bool addImgWgt ( const int TOKEN, @@ -233,7 +240,8 @@ public: const int IMG ); - //Selectable widget with visible rect & image, gray rect and texture + //Selectable widget with visible rect & image, rounded corners with 20% radius, + //gray rect and texture bool addImgButtonWgt ( const int TOKEN, @@ -249,6 +257,7 @@ public: ( const bool SHOW, const WidgetArea ROUND_CORNERS, + const int RADIUS, const GLfloat* const COLOR ); @@ -302,6 +311,10 @@ public: //FIXME: maybe this should be setWgtRectColor ? and put after the other rect funcs? void setWgtColor(const int TOKEN, const GLfloat* const COLOR); void setWgtRoundCorners(const int TOKEN, const WidgetArea CORNERS); + //The radius given is the percentage of the height or the width of the + //widget, whatever is smaller; however, the maximum is 50% (the corner's + //size). + void setWgtCornerRadius(const int TOKEN, const int RADIUS); void showWgtRect(const int TOKEN); void hideWgtRect(const int TOKEN);