1) Added first version of widgets that can have their position explicitely

set, avoiding the layout engine (and making it easy to make them skinable).
2) Added track groups, all current tracks are in a group called 'standard'.
   The track select widget can now scroll and therefore display a large
   number of tracks.
   


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2150 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2008-07-09 06:44:49 +00:00
parent 6733e4e810
commit 6414bdf12a
9 changed files with 452 additions and 173 deletions

View File

@@ -101,15 +101,9 @@ CharSel::CharSel(int whichPlayer)
widget_manager->addEmptyWgt(WTOK_EMPTY_DOWN, computeIndent(m_max_entries), HEIGHT/2);
widget_manager->addTextButtonWgt(WTOK_DOWN, 20, HEIGHT/2, "v");
//widget_manager->breakLine();
switchGroup(); // select all karts from the currently selected group
//widget_manager->breakLine();
//widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 2);
//widget_manager->breakLine();
widget_manager->layout(WGT_AREA_RGT);
m_current_kart = -1;
@@ -194,7 +188,7 @@ void CharSel::updateScrollPosition()
}
else
{
const std::vector<std::string> groups=kart_properties_manager->getAllGroups();
const std::vector<std::string> &groups=kart_properties_manager->getAllGroups();
widget_manager->setWgtText(WTOK_NAME0+i, groups[-indx-1]);
widget_manager->hideWgtTexture(WTOK_RACER0 + i);
widget_manager->hideWgtRect(WTOK_RACER0 + i);
@@ -277,7 +271,7 @@ void CharSel::update(float dt)
int token = widget_manager->getSelectedWgt() - WTOK_RACER0;
if(token<0 || token>(int)m_index_avail_karts.size())
token = widget_manager->getSelectedWgt() - WTOK_NAME0;
switchCharacter((token+m_offset)%(int)m_index_avail_karts.size());
switchCharacter((token+m_offset)%m_index_avail_karts.size());
}
if (m_kart != NULL)

View File

@@ -38,69 +38,202 @@ enum WidgetTokens
WTOK_IMG0,
WTOK_IMG1,
WTOK_AUTHOR,
WTOK_TRACK0
WTOK_EMPTY_UP,
WTOK_UP,
WTOK_EMPTY_DOWN,
WTOK_DOWN,
WTOK_EMPTY0 = 1000,
WTOK_TRACK0 = 2000
};
TrackSel::TrackSel()
{
// widget_manager->addTitleWgt( WTOK_TITLE, 40, 7, _("Choose a track") );
widget_manager->addEmptyWgt(WTOK_TITLE, 40, 7);
widget_manager->breakLine();
const int HEIGHT = 10;
widget_manager->addWgt( WidgetManager::WGT_NONE, 100, 1);
widget_manager->breakLine();
for (unsigned int i = 0; i != track_manager->getNumberOfTracks(); ++i)
Widget *prev_widget=NULL, *w;
w = widget_manager->addTextButtonWgt(WTOK_UP, 20, HEIGHT/2, "^");
w->setPosition(WGT_DIR_FROM_RIGHT, 0.05f, WGT_DIR_UNDER_WIDGET, 0.08f);
prev_widget = w;
for (unsigned int i = 0; i <m_max_entries; i++)
{
// snowtuxpeak must be unlocked
const Track *track = track_manager->getTrack(i);
bool isAvailable = !unlock_manager->isLocked(track->getIdent());
widget_manager->addTextButtonWgt( WTOK_TRACK0 + i, 40, 6, track->getName());
widget_manager->setWgtTextSize( WTOK_TRACK0 + i, WGT_FNT_SML );
if(!isAvailable)
{
widget_manager->hideWgtText(WTOK_TRACK0 + i);
// widget_manager->deactivateWgt(WTOK_TRACK0 + i);
int offset = (m_max_entries-1)/2-abs((int)(i-(m_max_entries-1)/2))+1;
w = widget_manager->addTextButtonWgt(WTOK_TRACK0+i, 30, HEIGHT, "");
widget_manager->setWgtTextSize(WTOK_TRACK0+i, WGT_FNT_SML);
w->setPosition(WGT_DIR_FROM_RIGHT, 0.03f*offset, NULL,
WGT_DIR_UNDER_WIDGET, 0.15f, prev_widget);
prev_widget = w;
} // for i
widget_manager->sameWidth(WTOK_TRACK0, WTOK_TRACK0+m_max_entries-1);
widget_manager->setWgtColor( WTOK_TRACK0 + i, WGT_GRAY );
widget_manager->setWgtTexture( WTOK_TRACK0 + i, "gui_lock.rgb", false );
widget_manager->showWgtTexture( WTOK_TRACK0 + i );
widget_manager->setWgtText(WTOK_TRACK0+i, _("Fulfil challenge to unlock"));
}
if( i%2 != 0 ) widget_manager->breakLine();
else if (i + 1 == track_manager->getNumberOfTracks() )
{
widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 40, 6 );
widget_manager->breakLine();
}
w = widget_manager->addTextButtonWgt(WTOK_DOWN, 20, HEIGHT/2, "v");
w->setPosition(WGT_DIR_FROM_RIGHT, 0.05f, NULL, WGT_DIR_UNDER_WIDGET, 0, prev_widget);
w = widget_manager->addImgWgt(WTOK_IMG0, 35, 35, 0);
w->setPosition(WGT_DIR_FROM_LEFT, 0.1f, WGT_DIR_FROM_TOP, 0.2f);
prev_widget = w;
w = widget_manager->addImgWgt(WTOK_IMG1, 35, 35, 0);
w->setPosition(WGT_DIR_FROM_LEFT, 0.1f, NULL, WGT_DIR_UNDER_WIDGET,0, prev_widget);
prev_widget = w;
w = widget_manager->addTextWgt(WTOK_AUTHOR, 50, 9, "" );
widget_manager->setWgtResizeToText(WTOK_AUTHOR, true);
// Loop through all tracks to determine the longest description
for(unsigned int i=0; i<track_manager->getNumberOfTracks(); i++)
{
widget_manager->setWgtText(WTOK_AUTHOR, track_manager->getTrack(i)->getDescription());
w->resizeToText();
}
w->setPosition(WGT_DIR_FROM_LEFT, 0.1f, NULL, WGT_DIR_UNDER_WIDGET, 0.05f, prev_widget);
widget_manager->addImgWgt(WTOK_IMG0, 35, 35, 0);
m_offset = 0;
m_current_track = -1;
switchGroup();
updateScrollPosition();
widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 5, 35 );
widget_manager->addImgWgt(WTOK_IMG1, 35, 35, 0);
widget_manager->breakLine();
widget_manager->addTextWgt( WTOK_AUTHOR, 80, 9, _("No track selected") );
widget_manager->hideWgtRect(WTOK_AUTHOR);
// Make sure to select one track. The call to update() here is necessary,
// since it guarantees that selectedWgt is indeed track0 (otherwise the
// manager might select e.g. arrow up, and then no track is displayed).
widget_manager->setSelectedWgt(WTOK_TRACK0+(m_max_entries-1)/2);
update(0);
widget_manager->layout(WGT_AREA_TOP);
}
} // TrackSel
//-----------------------------------------------------------------------------
TrackSel::~TrackSel()
{
widget_manager->reset();
}
} // ~TrackSel
//-----------------------------------------------------------------------------
void TrackSel::updateScrollPosition()
{
unsigned int start = 0, end=m_max_entries;
if(m_index_avail_tracks.size()<m_max_entries)
{
start = (unsigned int)(m_max_entries-m_index_avail_tracks.size()+1)/2;
end = start+m_index_avail_tracks.size()-1;
}
for(unsigned int i=0; i<m_max_entries; i++)
{
if(i<start || i>end)
{
widget_manager->hideWgtRect(WTOK_TRACK0+i);
widget_manager->hideWgtText(WTOK_TRACK0+i);
widget_manager->deactivateWgt(WTOK_TRACK0+i);
continue;
}
// Make them visible again (e.g. after a change of groups)
widget_manager->activateWgt(WTOK_TRACK0+i);
widget_manager->showWgtRect(WTOK_TRACK0+i);
widget_manager->showWgtText(WTOK_TRACK0+i);
int indx = (i+m_offset)%m_index_avail_tracks.size();
indx = m_index_avail_tracks[indx];
if(indx>=0)
{
const Track *track = track_manager->getTrack(indx);
widget_manager->setWgtText(WTOK_TRACK0+i, track->getName());
}
else
{
const std::vector<std::string>& g=track_manager->getAllGroups();
widget_manager->setWgtText(WTOK_TRACK0+i, g[-indx-1]);
}
} // for i
} // updateScrollPosition
//-----------------------------------------------------------------------------
void TrackSel::switchGroup()
{
m_index_avail_tracks.clear();
// This loop is too long (since getNumberOfKarts returns all karts in all groups),
// but the loop is left if no more kart is found.
for(unsigned int i=0; i<track_manager->getNumberOfTracks(); i++)
{
int globalIndex = track_manager->getTrackByGroup(user_config->m_track_group, i);
if(globalIndex==-1) break;
if(!unlock_manager->isLocked(track_manager->getTrack(globalIndex)->getIdent()))
{
m_index_avail_tracks.push_back(globalIndex);
}
}
// Now add the groups, indicated by a negative number as kart index
// ----------------------------------------------------------------
const std::vector<std::string>& groups=track_manager->getAllGroups();
for(int i =0; i<(int)groups.size(); i++)
{
// Only add groups other than the current one
if(groups[i]!=user_config->m_track_group) m_index_avail_tracks.push_back(-i-1);
}
if(m_index_avail_tracks.size()>=m_max_entries)
{
m_offset = 0;
widget_manager->showWgtRect(WTOK_DOWN);
widget_manager->showWgtText(WTOK_DOWN);
widget_manager->showWgtRect(WTOK_UP);
widget_manager->showWgtText(WTOK_UP);
}
else
{
// Less entries than maximum -> set m_offset to a negative number, so
// that the actual existing entries are displayed
m_offset = - (int)(1+m_max_entries-m_index_avail_tracks.size())/2;
widget_manager->hideWgtRect(WTOK_DOWN);
widget_manager->hideWgtText(WTOK_DOWN);
widget_manager->hideWgtRect(WTOK_UP);
widget_manager->hideWgtText(WTOK_UP);
}
} // switchGroup
//-----------------------------------------------------------------------------
void TrackSel::update(float dt)
{
const int SELECTED_TRACK = widget_manager->getSelectedWgt() - WTOK_TRACK0;
if( widget_manager->selectionChanged() &&
int indx = widget_manager->getSelectedWgt() - WTOK_TRACK0;
if(indx<0 || indx >= m_max_entries)
{
widget_manager->update(dt);
return;
}
indx = m_offset + indx;
// Don't use modulo here, otherwise (one extreme short lists, e.g. 1 track,
// 1 group, the track is selected when hovering over invisible menu entries
if(indx< 0 ) indx += m_index_avail_tracks.size();
if(indx>=(int)m_index_avail_tracks.size()) indx -= m_index_avail_tracks.size();
if(indx<0 || indx >= (int)m_index_avail_tracks.size())
{
widget_manager->update(dt);
return;
}
const int SELECTED_TRACK = m_index_avail_tracks[indx];
// Group selected, disable track imagess
if( m_current_track != SELECTED_TRACK)
{
if(SELECTED_TRACK<0)
{
widget_manager->hideWgtTexture(WTOK_IMG0);
widget_manager->hideWgtTexture(WTOK_IMG1);
widget_manager->hideWgtRect(WTOK_IMG0);
widget_manager->hideWgtRect(WTOK_IMG1);
widget_manager->hideWgtBorder(WTOK_IMG0);
widget_manager->hideWgtBorder(WTOK_IMG1);
widget_manager->hideWgtRect(WTOK_AUTHOR);
widget_manager->hideWgtText(WTOK_AUTHOR);
}
else
{
widget_manager->showWgtBorder(WTOK_IMG0);
widget_manager->showWgtBorder(WTOK_IMG1);
widget_manager->showWgtRect(WTOK_AUTHOR);
widget_manager->showWgtText(WTOK_AUTHOR);
}
}
if( m_current_track != SELECTED_TRACK &&
SELECTED_TRACK >= 0 &&
SELECTED_TRACK < (int)track_manager->getNumberOfTracks() )
{
@@ -176,23 +309,50 @@ void TrackSel::update(float dt)
widget_manager->hideWgtTexture( WTOK_IMG1 );
widget_manager->hideWgtTrack( WTOK_IMG1 );
}
}
}
} // isAvailable
} // m_current_track != SELECTED_TRACK && ...
m_current_track = SELECTED_TRACK;
widget_manager->update(dt);
}
} // update
//-----------------------------------------------------------------------------
void TrackSel::select()
{
const int CLICKED_TOKEN = widget_manager->getSelectedWgt();
if(CLICKED_TOKEN==WTOK_UP)
{
m_offset--;
if(m_offset < 0) m_offset = (int)m_index_avail_tracks.size() - 1;
updateScrollPosition();
return;
}
if(CLICKED_TOKEN==WTOK_DOWN)
{
m_offset++;
if(m_offset >=(int)m_index_avail_tracks.size()) m_offset = 0;
updateScrollPosition();
return;
}
unsigned int track_number = CLICKED_TOKEN - WTOK_TRACK0;
if(track_number<0 || track_number >= track_manager->getNumberOfTracks())
if(track_number<0 || track_number >= m_max_entries)
{
return; // not clicked on a track, ignore
}
track_number = (track_number+m_offset) % (int)m_index_avail_tracks.size();
int indx = m_index_avail_tracks[track_number];
if(indx<0) // group selected
{
user_config->m_track_group = track_manager->getAllGroups()[-indx-1];
switchGroup();
// forces redraw of the model, otherwise (if m_current_kart=0) the new
// model would not be displayed.
//m_current_kart = -1;
updateScrollPosition();
return;
}
const Track* TRACK = track_manager->getTrack(CLICKED_TOKEN - WTOK_TRACK0);
const Track* TRACK = track_manager->getTrack(m_index_avail_tracks[track_number]);
bool isAvailable = !unlock_manager->isLocked(TRACK->getIdent());
if( isAvailable )

View File

@@ -20,10 +20,21 @@
#ifndef HEADER_TRACKSEL_H
#define HEADER_TRACKSEL_H
#include <vector>
#include "base_gui.hpp"
class TrackSel: public BaseGUI
{
private:
unsigned int m_num_entries; // number of entries in scrolling menu
int m_offset; // index of first track
int m_current_track; // id of current track
std::vector<int> m_index_avail_tracks;
const static int m_max_entries = 7;
int computeIndent(int n) {return 40+abs((int)(m_num_entries-1)/2 - n)*3;}
void updateScrollPosition();
void switchGroup();
public:
TrackSel();
~TrackSel();

View File

@@ -91,7 +91,7 @@ void TrackManager::updateGroups(const Track* track)
for(unsigned int i=0; i<new_groups.size(); i++)
{
if(std::find(m_all_groups.begin(), m_all_groups.end(), new_groups[i])
== m_all_groups.end()) continue;
!= m_all_groups.end()) continue;
m_all_groups.push_back(new_groups[i]);
}
} // updateGroups

View File

@@ -40,12 +40,12 @@ public:
~TrackManager();
/** get TrackData by the track ident (aka filename without .track) */
const std::vector<std::string>&
getAllGroups() const { return m_all_groups; }
size_t getNumberOfTracks() const { return m_tracks.size(); }
Track *getTrack(size_t id) const { return m_tracks[id]; }
Track *getTrack(const std::string& ident) const;
Track *getTrack(size_t id) const {return m_tracks[id]; }
int getTrackByGroup(const std::string& group, int n) const;
const std::vector<std::string>
getAllGroups();
size_t getNumberOfTracks() const {return m_tracks.size();}
/** load all .track files from all directories */
void loadTrackList ();

View File

@@ -76,6 +76,7 @@ Widget::Widget
//handles that.
m_x(X_), m_y(Y_),
m_width(WIDTH_), m_height(HEIGHT_),
m_fixed_position(false),
m_rect_list(0),
m_round_corners(WGT_AREA_ALL),
m_border_list(0),
@@ -99,6 +100,78 @@ Widget::~Widget()
}
//-----------------------------------------------------------------------------
void Widget::setPosition(WidgetDirection horizontal, float percentage_horizontal,
const Widget *w_hori,
WidgetDirection vertical, float percentage_vertical,
const Widget *w_verti)
{
m_fixed_position = true;
m_horizontal = horizontal;
m_percentage_x = percentage_horizontal;
m_widget_horizontal = w_hori;
// If the direction is left/right of a widget, but that widget is not defined
// use left/right (of screen). This simplified programming, since the e.g.
// left-most widget will be positioned relative to the side of the screen
if(!w_hori)
{
if(m_horizontal==WGT_DIR_LEFT_WIDGET ) m_horizontal = WGT_DIR_FROM_RIGHT;
if(m_horizontal==WGT_DIR_RIGHT_WIDGET) m_horizontal = WGT_DIR_FROM_LEFT;
}
m_vertical = vertical;
m_percentage_y = percentage_vertical;
m_widget_vertical = w_verti;
if(!w_verti)
{
if(m_vertical==WGT_DIR_ABOVE_WIDGET) m_vertical = WGT_DIR_FROM_BOTTOM;
if(m_vertical==WGT_DIR_UNDER_WIDGET) m_vertical = WGT_DIR_FROM_TOP;
}
} // setPosition
// ----------------------------------------------------------------------------
void Widget::layout()
{
if(!hasFixedPosition())
{
std::cerr << "Warning: layout called for widget without fixed position.\n";
return;
}
if( !createRect() ) return;
switch(m_horizontal)
{
case WGT_DIR_FROM_LEFT:
m_x = (int)(user_config->m_width*m_percentage_x); break;
case WGT_DIR_FROM_RIGHT:
m_x = (int)(user_config->m_width*(1-m_percentage_x)-m_width); break;
case WGT_DIR_CENTER:
m_x = (int)((user_config->m_width-m_width)*0.5f); break;
case WGT_DIR_LEFT_WIDGET:
m_x = m_widget_horizontal->m_x - m_width; break;
case WGT_DIR_RIGHT_WIDGET:
m_x = m_widget_horizontal->m_x+m_widget_horizontal->m_width; break;
default:
break;
} // switch
switch(m_vertical)
{
case WGT_DIR_FROM_TOP:
m_y = (int)(user_config->m_height*(1-m_percentage_y)-m_height); break;
case WGT_DIR_FROM_BOTTOM:
m_y = (int)(user_config->m_height*m_percentage_y); break;
case WGT_DIR_CENTER:
m_y = (int)((user_config->m_height-m_height)*0.5f); break;
case WGT_DIR_ABOVE_WIDGET:
m_y = m_widget_vertical->m_y + m_widget_vertical->m_height; break;
case WGT_DIR_UNDER_WIDGET:
m_y = m_widget_vertical->m_y-m_height; break;
default:
break;
} // switch
} // layout
//-----------------------------------------------------------------------------
void Widget::update( const float DELTA )
{

View File

@@ -36,8 +36,6 @@
# pragma warning(default:4312)
#endif
#include "gui/font.hpp"
#ifdef __APPLE__
# include <OpenGL/gl.h>
#else
@@ -47,7 +45,14 @@
# endif
# include <GL/gl.h>
#endif
#include "gui/font.hpp"
#include "user_config.hpp"
// For widgets with fixed position
enum WidgetDirection{ WGT_DIR_FROM_LEFT, WGT_DIR_FROM_RIGHT,
WGT_DIR_LEFT_WIDGET, WGT_DIR_RIGHT_WIDGET, WGT_DIR_CENTER,
WGT_DIR_FROM_TOP, WGT_DIR_FROM_BOTTOM,
WGT_DIR_ABOVE_WIDGET, WGT_DIR_UNDER_WIDGET};
enum WidgetFontSize { WGT_FNT_SML = 18, WGT_FNT_MED = 24, WGT_FNT_LRG = 30};
@@ -134,6 +139,13 @@ class Widget
int m_width, m_height;
int m_radius;
/* support for specifying the position of a widget */
bool m_fixed_position;
WidgetDirection m_horizontal, m_vertical;
float m_percentage_x, m_percentage_y;
const Widget *m_widget_horizontal,
*m_widget_vertical;
/* 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
@@ -198,8 +210,6 @@ class Widget
void pulse() {m_text_scale = MAX_TEXT_SCALE;}
/* Convenience functions. */
void resizeToText(); //This checks if the widget is smaller than the
//text, and if so, changes the width and height.
void lightenColor();
void darkenColor();
@@ -207,11 +217,27 @@ class Widget
void setFont( const WidgetFont FONT );
void setTexture( const std::string& FILENAME, const bool is_full_path=true );
/* position support */
bool hasFixedPosition() const {return m_fixed_position;}
void layout();
/* Functions created simply to organize the code */
bool createRect();
void updateVariables( const float DELTA );
void draw();
void applyTransformations();
public:
void setPosition(WidgetDirection horizontal, float percentage_horizontal,
WidgetDirection vertical, float percentage_vertical)
{
setPosition(horizontal, percentage_horizontal, NULL,
vertical, percentage_vertical, NULL);
}
void setPosition(WidgetDirection horizontal, float percentage_horizontal,
const Widget *w_hori,
WidgetDirection vertical, float percentage_vertical,
const Widget *w_verti);
void resizeToText(); //This checks if the widget is smaller than the
//text, and if so, changes the width and height.
};

View File

@@ -53,7 +53,7 @@ WidgetManager::~WidgetManager()
}
//-----------------------------------------------------------------------------
bool WidgetManager::addWgt
Widget *WidgetManager::addWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -64,7 +64,7 @@ bool WidgetManager::addWgt
{
std::cerr << "WARNING: tried to create widget with token " <<
TOKEN << " but it is already in use.\n";
return false;
return NULL;
}
WidgetID new_id;
@@ -115,10 +115,13 @@ bool WidgetManager::addWgt
new_id.widget->m_enable_track = m_default_show_track;
new_id.widget->m_track_num = m_default_track_num;
new_id.widget->m_width = (int)(user_config->m_width * new_id.min_width * 0.01);
new_id.widget->m_height =(int)(user_config->m_height * new_id.min_height * 0.01);
m_elems.push_back(WidgetElement(ET_WGT, (int)m_widgets.size()));
m_widgets.push_back(new_id);
return true;
return new_id.widget;
}
//-----------------------------------------------------------------------------
@@ -285,20 +288,12 @@ bool WidgetManager::layout(const WidgetArea POSITION)
const int SCREEN_HEIGHT = user_config->m_height;
{
int width, height;
//Set the widgets' rect shape properties in pixels.
for( int i = 0; i < NUM_WIDGETS; ++i )
{
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 )
Widget *w=m_widgets[i].widget;
if( m_widgets[i].resize_to_text ) w->resizeToText();
if( w->m_width < w->m_height )
{
m_widgets[i].widget->m_radius = (int)( m_widgets[i].min_radius *
m_widgets[i].widget->m_width * 0.01 );
@@ -408,7 +403,11 @@ bool WidgetManager::layout(const WidgetArea POSITION)
{
case ET_WGT:
curr_wgt = &m_widgets[ m_elems[ i ].pos ];
if(curr_wgt->widget->hasFixedPosition())
{
curr_wgt->widget->layout();
break;
}
curr_wgt->widget->m_x = cursor_x;
//We have to give createRect() the bottom left corner
@@ -465,6 +464,7 @@ bool WidgetManager::layoutLine( int& x, int& y, int& pos )
{
case ET_WGT:
curr_wgt = &m_widgets[ m_elems[ i ].pos ];
if(curr_wgt->widget->hasFixedPosition()) break;
curr_wgt->widget->m_x = cursor_x;
@@ -509,6 +509,7 @@ bool WidgetManager::layoutColumn( int& x, int& y, int& pos )
{
case ET_WGT:
curr_wgt = &m_widgets[ m_elems[ i ].pos ];
if(curr_wgt->widget->hasFixedPosition()) break;
curr_wgt->widget->m_x = cursor_x;
@@ -572,7 +573,8 @@ int WidgetManager::getLineWidth( int& pos )
switch( m_elems[ pos ].type)
{
case ET_WGT:
width += m_widgets[ m_elems[ pos ].pos ].widget->m_width;
if(!m_widgets[ m_elems[ pos ].pos ].widget->hasFixedPosition())
width += m_widgets[ m_elems[ pos ].pos ].widget->m_width;
break;
case ET_BREAK:
@@ -604,6 +606,7 @@ int WidgetManager::getLineHeight( int& pos )
switch( m_elems[ pos ].type)
{
case ET_WGT:
if( m_widgets[ m_elems[ pos ].pos ].widget->hasFixedPosition()) break;
if( m_widgets[ m_elems[ pos ].pos ].widget->m_height > height )
{
height = m_widgets[ m_elems[ pos ].pos ].widget->m_height;
@@ -640,11 +643,12 @@ int WidgetManager::getColumnWidth( int& pos )
switch( m_elems[ pos ].type )
{
case ET_WGT:
if( m_widgets[ m_elems[ pos ].pos ].widget->m_width > width )
{
width = m_widgets[ m_elems[ pos ].pos ].widget->m_width;
}
break;
if(m_widgets[ m_elems[ pos ].pos ].widget->hasFixedPosition()) break;
if( m_widgets[ m_elems[ pos ].pos ].widget->m_width > width )
{
width = m_widgets[ m_elems[ pos ].pos ].widget->m_width;
}
break;
case ET_BREAK:
return width;
@@ -676,6 +680,7 @@ int WidgetManager::getColumnHeight( int& pos )
switch( m_elems[ pos ].type)
{
case ET_WGT:
if(m_widgets[ m_elems[ pos ].pos ].widget->hasFixedPosition()) break;
height += m_widgets[ m_elems[ pos ].pos ].widget->m_height;
break;
@@ -706,6 +711,7 @@ int WidgetManager::calcLineWidth( const int POS )
switch( m_elems[i].type)
{
case ET_WGT:
if(m_widgets[ m_elems[ i ].pos ].widget->hasFixedPosition()) break;
width += m_widgets[ m_elems[ i ].pos ].widget->m_width;
break;
@@ -737,6 +743,7 @@ int WidgetManager::calcLineHeight( const int POS )
switch( m_elems[i].type)
{
case ET_WGT:
if( m_widgets[ m_elems[ i ].pos ].widget->hasFixedPosition()) break;
if( m_widgets[ m_elems[ i ].pos ].widget->m_height > height )
{
height = m_widgets[ m_elems[ i ].pos ].widget->m_height;
@@ -772,11 +779,12 @@ int WidgetManager::calcColumnWidth( const int POS )
switch( m_elems[ i ].type )
{
case ET_WGT:
if( m_widgets[ m_elems[ i ].pos ].widget->m_width > width )
{
width = m_widgets[ m_elems[ i ].pos ].widget->m_width;
}
break;
if( m_widgets[ m_elems[ i ].pos ].widget->hasFixedPosition()) break;
if( m_widgets[ m_elems[ i ].pos ].widget->m_width > width )
{
width = m_widgets[ m_elems[ i ].pos ].widget->m_width;
}
break;
case ET_BREAK:
return width;
@@ -807,6 +815,7 @@ int WidgetManager::calcColumnHeight( const int POS )
switch( m_elems[i].type)
{
case ET_WGT:
if(m_widgets[ m_elems[ i ].pos ].widget->hasFixedPosition()) break;
height += m_widgets[ m_elems[ i ].pos ].widget->m_height;
break;
@@ -837,6 +846,7 @@ int WidgetManager::calcLineX( const int POS )
{
case ET_WGT:
curr_wgt = &m_widgets[ m_elems[ i ].pos ];
if(curr_wgt->widget->hasFixedPosition()) break;
width += curr_wgt->widget->m_width;
break;
@@ -915,7 +925,7 @@ void WidgetManager::setSelectedWgt(const int TOKEN)
}
//-----------------------------------------------------------------------------
bool WidgetManager::addTitleWgt
Widget *WidgetManager::addTitleWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -923,7 +933,8 @@ bool WidgetManager::addTitleWgt
const std::string TEXT
)
{
if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false;
Widget *w=addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT );
if( !w) return false;
showWgtRect( TOKEN );
setWgtTextSize( TOKEN, WGT_FNT_LRG );
@@ -932,11 +943,11 @@ bool WidgetManager::addTitleWgt
setWgtRoundCorners( TOKEN, WGT_AREA_ALL );
setWgtCornerRadius( TOKEN, 20 );
return true;
return w;
}
//-----------------------------------------------------------------------------
bool WidgetManager::addTextWgt
Widget *WidgetManager::addTextWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -944,7 +955,8 @@ bool WidgetManager::addTextWgt
const std::string TEXT
)
{
if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false;
Widget *w=addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT );
if( !w) return false;
showWgtRect( TOKEN );
setWgtRoundCorners( TOKEN, WGT_AREA_ALL );
@@ -952,11 +964,11 @@ bool WidgetManager::addTextWgt
showWgtText( TOKEN );
setWgtText( TOKEN, TEXT );
return true;
return w;
}
//-----------------------------------------------------------------------------
bool WidgetManager::addTextButtonWgt
Widget *WidgetManager::addTextButtonWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -964,7 +976,8 @@ bool WidgetManager::addTextButtonWgt
const std::string TEXT
)
{
if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false;
Widget *w=addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT );
if( !w) return false;
showWgtRect( TOKEN );
setWgtRoundCorners( TOKEN, WGT_AREA_ALL );
@@ -973,11 +986,11 @@ bool WidgetManager::addTextButtonWgt
setWgtText( TOKEN, TEXT );
activateWgt( TOKEN );
return true;
}
return w;
} // addTextButtonWgt
//-----------------------------------------------------------------------------
bool WidgetManager::addImgWgt
Widget *WidgetManager::addImgWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -985,7 +998,8 @@ bool WidgetManager::addImgWgt
const int IMG
)
{
if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false;
Widget *w=addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT );
if( !w) return false;
setWgtColor( TOKEN, WGT_WHITE );
showWgtRect( TOKEN );
@@ -995,11 +1009,11 @@ bool WidgetManager::addImgWgt
setWgtTexture( TOKEN, IMG );
showWgtTexture( TOKEN );
return true;
return w;
}
//-----------------------------------------------------------------------------
bool WidgetManager::addImgWgt
Widget *WidgetManager::addImgWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -1007,7 +1021,8 @@ bool WidgetManager::addImgWgt
const char* FILENAME
)
{
if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false;
Widget *w=addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT );
if( !w) return false;
setWgtColor( TOKEN, WGT_WHITE );
showWgtRect( TOKEN );
@@ -1017,11 +1032,11 @@ bool WidgetManager::addImgWgt
setWgtTexture( TOKEN, FILENAME );
showWgtTexture( TOKEN );
return true;
return w;
}
//-----------------------------------------------------------------------------
bool WidgetManager::addImgButtonWgt
Widget *WidgetManager::addImgButtonWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -1029,7 +1044,8 @@ bool WidgetManager::addImgButtonWgt
const int IMG
)
{
if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false;
Widget *w=addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT );
if( !w) return false;
setWgtColor( TOKEN, WGT_GRAY );
showWgtRect( TOKEN );
@@ -1039,11 +1055,11 @@ bool WidgetManager::addImgButtonWgt
showWgtTexture( TOKEN );
activateWgt( TOKEN );
return true;
return w;
}
//-----------------------------------------------------------------------------
bool WidgetManager::addImgButtonWgt
Widget *WidgetManager::addImgButtonWgt
(
const int TOKEN,
const int MIN_WIDTH,
@@ -1051,7 +1067,8 @@ bool WidgetManager::addImgButtonWgt
const std::string& FILENAME
)
{
if( !( addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT ))) return false;
Widget *w=addWgt( TOKEN, MIN_WIDTH, MIN_HEIGHT );
if( !w) return false;
setWgtColor( TOKEN, WGT_GRAY );
showWgtRect( TOKEN );
@@ -1061,7 +1078,7 @@ bool WidgetManager::addImgButtonWgt
showWgtTexture( TOKEN );
activateWgt( TOKEN );
return true;
return w;
}
//-----------------------------------------------------------------------------
@@ -2207,3 +2224,39 @@ void WidgetManager::reloadFonts()
}
}
// ----------------------------------------------------------------------------
void WidgetManager::setPosition(const int token,
WidgetDirection hori, float percentage_x,
WidgetDirection verti, float percentage_y)
{
const int id = findId(token);
if( id != WGT_NONE )
m_widgets[id].widget->setPosition(hori, percentage_x,
verti, percentage_y);
} // setPosition
// ----------------------------------------------------------------------------
/** Sets the width of all widgets between widget_min and widget_max to
be the same */
void WidgetManager::sameWidth(int widget_min, int widget_max)
{
int width = -1;
for(int i=widget_min; i<=widget_max; i++)
{
const int id = findId(i);
Widget *w = m_widgets[id].widget;
w->m_width = (int)(user_config->m_width * m_widgets[id].min_width * 0.01);
if( m_widgets[id].resize_to_text ) w->resizeToText();
if(width < w->m_width)
width = w->m_width;
}
for(int i=widget_min; i<=widget_max; i++)
{
const int id = findId(i);
m_widgets[id].widget->m_width = width;
}
} // sameWidth

View File

@@ -170,7 +170,7 @@ public:
bool isEmpty() { return m_widgets.empty(); }
bool addWgt
Widget *addWgt
(
const int TOKEN, //A number that names the widget.
const int MIN_WIDTH, //These values are percentages not pixels. 100%
@@ -205,85 +205,43 @@ public:
/* Macro functions. They are widgets with special predefined values. */
//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 *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, rounded corners with 20% radius,
//sets the text, and large font
bool addTitleWgt
(
const int TOKEN,
const int MIN_WIDTH,
const int MIN_HEIGHT,
const std::string TEXT
);
Widget *addTitleWgt (const int TOKEN, const int MIN_WIDTH,
const int MIN_HEIGHT, const std::string TEXT);
//Widget that adds visible rect & text, rounded corners with 20% radius,
//and sets the text
bool addTextWgt
(
const int TOKEN,
const int MIN_WIDTH,
const int MIN_HEIGHT,
const std::string TEXT
);
Widget *addTextWgt (const int TOKEN, const int MIN_WIDTH,
const int MIN_HEIGHT, const std::string TEXT);
//Widget that adds visible rect & text, rounded corners with 20% radius,
//sets the text and is selectable
bool addTextButtonWgt
(
const int TOKEN,
const int MIN_WIDTH,
const int MIN_HEIGHT,
const std::string TEXT
);
Widget *addTextButtonWgt(const int TOKEN, const int MIN_WIDTH,
const int MIN_HEIGHT, const std::string TEXT);
//Widget that adds visible rect & image, white rect, 5% black
//border, and sets the texture
bool addImgWgt
(
const int TOKEN,
const int MIN_WIDTH,
const int MIN_HEIGHT,
const int IMG
);
bool addImgWgt
(
const int TOKEN,
const int MIN_WIDTH,
const int MIN_HEIGHT,
const char* FILENAME
);
Widget *addImgWgt (const int TOKEN, const int MIN_WIDTH,
const int MIN_HEIGHT, const int IMG);
Widget *addImgWgt (const int TOKEN, const int MIN_WIDTH,
const int MIN_HEIGHT, const char* FILENAME);
//Selectable widget with visible rect & image, rounded corners with 20% radius,
//gray rect and texture
bool addImgButtonWgt
(
const int TOKEN,
const int MIN_WIDTH,
const int MIN_HEIGHT,
const int IMG
);
bool addImgButtonWgt
(
const int TOKEN,
const int MIN_WIDTH,
const int MIN_HEIGHT,
const std::string& FILENAME
);
Widget *addImgButtonWgt (const int TOKEN, const int MIN_WIDTH,
const int MIN_HEIGHT, const int IMG);
Widget *addImgButtonWgt (const int TOKEN, const int MIN_WIDTH,
const int MIN_HEIGHT,const std::string& FILENAME);
/* On/off widget switch features. They are all disabled/hidden initially. */
void setInitialActivationState( const bool ACTIVE);
void setInitialRectState
(
const bool SHOW,
const WidgetArea ROUND_CORNERS,
const int RADIUS,
const GLfloat* const COLOR
);
void setInitialRectState(const bool SHOW,const WidgetArea ROUND_CORNERS,
const int RADIUS,const GLfloat* const COLOR);
void setInitialTextureState(const bool SHOW, const int TEXTURE );
@@ -401,6 +359,10 @@ public:
/* Scrolling modification. */
void increaseScrollSpeed(bool = false);
void decreaseScrollSpeed(bool = false);
void setPosition(const int token,
WidgetDirection hori, float percentage_x,
WidgetDirection verti, float percentage_y);
void sameWidth(int widget_min, int widget_max);
};
extern WidgetManager *widget_manager;