Added rotation to widgets, but it's incomplete; text doesn't shows outside of the 'normal' box, and selection does the same.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1436 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
2d849d0efb
commit
d20a7a229b
110
src/widget.cpp
110
src/widget.cpp
@ -96,7 +96,21 @@ void Widget::update(const float DELTA)
|
|||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glTranslatef ( (GLfloat)m_x , (GLfloat)m_y , 0);
|
/* OpenGL transformations are affected by the order of the calls; but the
|
||||||
|
* operations must be called in the inverse order that you want them to
|
||||||
|
* be applied, since the calls are stacked, and the one at the top is
|
||||||
|
* done first, till the one at the bottom.
|
||||||
|
*/
|
||||||
|
|
||||||
|
glTranslatef ( (GLfloat)(m_x + m_width * 0.5f), (GLfloat)(m_y + m_height * 0.5f), 0);
|
||||||
|
|
||||||
|
m_rotation_angle += m_rotation_speed * DELTA;
|
||||||
|
if( m_enable_rotation )
|
||||||
|
{
|
||||||
|
glRotatef( (GLfloat)m_rotation_angle, 0.0f, 0.0f, (GLfloat)1.0f );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*Handle delta time dependant features*/
|
/*Handle delta time dependant features*/
|
||||||
if(m_text_scale > MIN_TEXT_SCALE)
|
if(m_text_scale > MIN_TEXT_SCALE)
|
||||||
@ -299,8 +313,8 @@ void Widget::update(const float DELTA)
|
|||||||
std::cerr << "(Did you set the text?)\n";
|
std::cerr << "(Did you set the text?)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int x_pos = (int)m_scroll_pos_x;
|
int x_pos = (int)m_scroll_pos_x - m_width * 0.5f;
|
||||||
int y_pos = - (int)m_scroll_pos_y + m_height / 2 + (lines - 1 )* m_text_size / 2;
|
int y_pos = - (int)m_scroll_pos_y + (lines - 1 )* m_text_size / 2;
|
||||||
|
|
||||||
size_t line_start = 0;
|
size_t line_start = 0;
|
||||||
bool draw;
|
bool draw;
|
||||||
@ -413,6 +427,15 @@ bool Widget::createRect(int radius)
|
|||||||
//quad.
|
//quad.
|
||||||
glBegin(GL_QUAD_STRIP);
|
glBegin(GL_QUAD_STRIP);
|
||||||
{
|
{
|
||||||
|
//These are used to center the widget; without centering, the
|
||||||
|
//widget's 0,0 coordinates are at the lower left corner.
|
||||||
|
float half_width = m_width * 0.5f;
|
||||||
|
float half_height = m_height * 0.5f;
|
||||||
|
|
||||||
|
float angle;
|
||||||
|
float circle_x, circle_y;
|
||||||
|
float vertex_x, vertex_ya, vertex_yb;
|
||||||
|
|
||||||
//Draw the left side of a rectangle.
|
//Draw the left side of a rectangle.
|
||||||
for (i = 0; i <= NUM_QUADS; ++i)
|
for (i = 0; i <= NUM_QUADS; ++i)
|
||||||
{
|
{
|
||||||
@ -430,9 +453,9 @@ bool Widget::createRect(int radius)
|
|||||||
//on that, we just split the radians in a corner in NUM_QUADS
|
//on that, we just split the radians in a corner in NUM_QUADS
|
||||||
//+ 1 parts, and use the angles at those parts to find the
|
//+ 1 parts, and use the angles at those parts to find the
|
||||||
//X and Y position of the points.
|
//X and Y position of the points.
|
||||||
const float ANGLE = 0.5f * M_PI * (float)i / (float)NUM_QUADS;
|
angle = 0.5f * M_PI * (float)i / (float)NUM_QUADS;
|
||||||
const float CIRCLE_X = radius * cos(ANGLE);
|
circle_x = radius * cos(angle);
|
||||||
const float CIRCLE_Y = radius * sin(ANGLE);
|
circle_y = radius * sin(angle);
|
||||||
|
|
||||||
//After we generate the positions in circle for the angles,
|
//After we generate the positions in circle for the angles,
|
||||||
//we have to position each rounded corner properly depending
|
//we have to position each rounded corner properly depending
|
||||||
@ -440,44 +463,69 @@ bool Widget::createRect(int radius)
|
|||||||
//position for the circle is dependant on rect; if a corner
|
//position for the circle is dependant on rect; if a corner
|
||||||
//wasn't given, then the y position is computed as if it was
|
//wasn't given, then the y position is computed as if it was
|
||||||
//for a rectangle without rounder corners.
|
//for a rectangle without rounder corners.
|
||||||
const float VERTEX_X = radius - CIRCLE_X;
|
vertex_x = radius - circle_x;
|
||||||
const float VERTEX_YA = m_height +
|
|
||||||
((m_round_corners & WGT_AREA_NW) ? (CIRCLE_Y - radius) : 0);
|
|
||||||
const float VERTEX_YB = m_round_corners & WGT_AREA_SW ?
|
|
||||||
radius - CIRCLE_Y : 0;
|
|
||||||
|
|
||||||
glTexCoord2f(VERTEX_X / m_width,
|
if( m_round_corners & WGT_AREA_NW )
|
||||||
VERTEX_YA / m_height);
|
{
|
||||||
glVertex2f(VERTEX_X, VERTEX_YA);
|
vertex_ya = m_height + circle_y - radius;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertex_ya = m_height;
|
||||||
|
}
|
||||||
|
|
||||||
glTexCoord2f(VERTEX_X / m_width,
|
if( m_round_corners & WGT_AREA_SW )
|
||||||
VERTEX_YB / m_height);
|
{
|
||||||
glVertex2f(VERTEX_X, VERTEX_YB);
|
vertex_yb = radius - circle_y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertex_yb = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
glTexCoord2f(vertex_x / m_width, vertex_ya / m_height);
|
||||||
|
glVertex2f(vertex_x - half_width, vertex_ya - half_height);
|
||||||
|
|
||||||
|
glTexCoord2f(vertex_x / m_width, vertex_yb / m_height);
|
||||||
|
glVertex2f(vertex_x - half_width, vertex_yb - half_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draw the right side of a rectangle
|
//Draw the right side of a rectangle
|
||||||
for (i = 0; i <= NUM_QUADS; ++i)
|
for (i = 0; i <= NUM_QUADS; ++i)
|
||||||
{
|
{
|
||||||
const float ANGLE = 0.5f * M_PI * (float) i / (float) NUM_QUADS;
|
angle = 0.5f * M_PI * (float) i / (float) NUM_QUADS;
|
||||||
|
|
||||||
//By inverting the use of sin and cos we get corners that are
|
//By inverting the use of sin and cos we get corners that are
|
||||||
//drawn from left to right instead of right to left
|
//drawn from left to right instead of right to left
|
||||||
const float CIRCLE_X = radius * sin(ANGLE);
|
circle_x = radius * sin(angle);
|
||||||
const float CIRCLE_Y = radius * cos(ANGLE);
|
circle_y = radius * cos(angle);
|
||||||
|
|
||||||
float VERTEX_X = m_width - radius + CIRCLE_X;
|
vertex_x = m_width - radius + circle_x;
|
||||||
float VERTEX_YA = m_height + ((m_round_corners &
|
|
||||||
WGT_AREA_NE) ? (CIRCLE_Y - radius) : 0);
|
|
||||||
float VERTEX_YB = m_round_corners & WGT_AREA_SE ?
|
|
||||||
radius - CIRCLE_Y : 0;
|
|
||||||
|
|
||||||
glTexCoord2f(VERTEX_X / m_width,
|
if( m_round_corners & WGT_AREA_NE )
|
||||||
VERTEX_YA / m_height);
|
{
|
||||||
glVertex2f(VERTEX_X, VERTEX_YA);
|
vertex_ya = m_height + circle_y - radius;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertex_ya = m_height;
|
||||||
|
}
|
||||||
|
|
||||||
glTexCoord2f((VERTEX_X) / m_width,
|
if( m_round_corners & WGT_AREA_SE )
|
||||||
(VERTEX_YB) / m_height);
|
{
|
||||||
glVertex2f(VERTEX_X, VERTEX_YB);
|
vertex_yb = radius - circle_y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertex_yb = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
glTexCoord2f(vertex_x / m_width, vertex_ya / m_height);
|
||||||
|
glVertex2f(vertex_x - half_width, vertex_ya - half_height);
|
||||||
|
|
||||||
|
glTexCoord2f(vertex_x / m_width, vertex_yb / m_height);
|
||||||
|
glVertex2f(vertex_x - half_width, vertex_yb - half_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,8 +133,7 @@ class Widget
|
|||||||
int m_x, m_y;
|
int m_x, m_y;
|
||||||
int m_width, m_height;
|
int m_width, m_height;
|
||||||
|
|
||||||
/* On/off features, these are not dependant on the delta time and are not
|
/* Low level features. They are off by default. */
|
||||||
* animated. They are off by default. */
|
|
||||||
bool m_enable_rect;
|
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.
|
//possibly rounded corners.
|
||||||
@ -157,13 +156,18 @@ class Widget
|
|||||||
int m_scroll_speed_x;
|
int m_scroll_speed_x;
|
||||||
int m_scroll_speed_y;
|
int m_scroll_speed_y;
|
||||||
|
|
||||||
|
bool m_enable_rotation;
|
||||||
|
float m_rotation_angle;
|
||||||
|
int m_rotation_speed;
|
||||||
|
|
||||||
|
|
||||||
//The widget calls the Track::drawScaled2D() function to draw a given
|
//The widget calls the Track::drawScaled2D() function to draw a given
|
||||||
//track, and m_track_num tells which track to draw.
|
//track, and m_track_num tells which track to draw.
|
||||||
int m_enable_track;
|
int m_enable_track;
|
||||||
int m_track_num;
|
int m_track_num;
|
||||||
|
|
||||||
/* Delta time dependant features, these deactivate after a certain time,
|
/* High level, pattern following features; they deactivate themselves
|
||||||
* and are dependant on the delta time. They have animations. */
|
* after they follow their pattern, and might use low level features.*/
|
||||||
static const float MAX_TEXT_SCALE;
|
static const float MAX_TEXT_SCALE;
|
||||||
static const float MIN_TEXT_SCALE;
|
static const float MIN_TEXT_SCALE;
|
||||||
float m_text_scale; //Used for the pulse effect
|
float m_text_scale; //Used for the pulse effect
|
||||||
|
@ -90,6 +90,10 @@ bool WidgetManager::addWgt
|
|||||||
new_id.widget->m_scroll_speed_x = m_default_scroll_x_speed;
|
new_id.widget->m_scroll_speed_x = m_default_scroll_x_speed;
|
||||||
new_id.widget->m_scroll_speed_y = m_default_scroll_y_speed;
|
new_id.widget->m_scroll_speed_y = m_default_scroll_y_speed;
|
||||||
|
|
||||||
|
new_id.widget->m_enable_rotation = m_default_enable_rotation;
|
||||||
|
new_id.widget->m_rotation_angle = m_default_rotation_angle;
|
||||||
|
new_id.widget->m_rotation_speed = m_default_rotation_speed;
|
||||||
|
|
||||||
new_id.widget->m_enable_track = m_default_show_track;
|
new_id.widget->m_enable_track = m_default_show_track;
|
||||||
new_id.widget->m_track_num = m_default_track_num;
|
new_id.widget->m_track_num = m_default_track_num;
|
||||||
|
|
||||||
@ -778,6 +782,19 @@ void WidgetManager::setInitialScrollState
|
|||||||
m_default_scroll_y_speed = Y_SPEED;
|
m_default_scroll_y_speed = Y_SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void WidgetManager::setInitialRotationState
|
||||||
|
(
|
||||||
|
const bool ENABLE,
|
||||||
|
const float ANGLE,
|
||||||
|
const int SPEED
|
||||||
|
)
|
||||||
|
{
|
||||||
|
m_default_enable_rotation = ENABLE;
|
||||||
|
m_default_rotation_angle = ANGLE;
|
||||||
|
m_default_rotation_speed = SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void WidgetManager::setInitialTrackState
|
void WidgetManager::setInitialTrackState
|
||||||
(
|
(
|
||||||
@ -808,6 +825,9 @@ void WidgetManager::restoreDefaultStates()
|
|||||||
m_default_scroll_preset_y = WGT_SCROLL_CENTER;
|
m_default_scroll_preset_y = WGT_SCROLL_CENTER;
|
||||||
m_default_scroll_x_speed = 0;
|
m_default_scroll_x_speed = 0;
|
||||||
m_default_scroll_y_speed = 0;
|
m_default_scroll_y_speed = 0;
|
||||||
|
m_default_enable_rotation = false;
|
||||||
|
m_default_rotation_angle = 0.0f;
|
||||||
|
m_default_rotation_speed = 0;
|
||||||
m_default_show_track = false;
|
m_default_show_track = false;
|
||||||
m_default_track_num = -1;
|
m_default_track_num = -1;
|
||||||
}
|
}
|
||||||
@ -1076,39 +1096,74 @@ void WidgetManager::setWgtYScrollPos
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void WidgetManager::setWgtXScrollSpeed( const int TOKEN, const int SPEED )
|
void WidgetManager::setWgtXScrollSpeed( const int TOKEN, const int SPEED )
|
||||||
{
|
|
||||||
const int ID = findId(TOKEN);
|
|
||||||
if( ID != WGT_NONE ) m_widgets[ID].widget->m_scroll_speed_x = SPEED;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "WARNING: tried to set the X scroll speed of an " <<
|
|
||||||
"unnamed widget with token " << TOKEN << '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
void WidgetManager::setWgtYScrollSpeed( const int TOKEN, const int SPEED )
|
|
||||||
{
|
|
||||||
const int ID = findId(TOKEN);
|
|
||||||
if( ID != WGT_NONE ) m_widgets[ID].widget->m_scroll_speed_y = SPEED;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "WARNING: tried to set the Y scroll speed of an " <<
|
|
||||||
"unnamed widget with token " << TOKEN << '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** pulse_widget() passes the pulse order to the right widget.
|
|
||||||
*/
|
|
||||||
void WidgetManager::pulseWgt(const int TOKEN) const
|
|
||||||
{
|
{
|
||||||
const int ID = findId(TOKEN);
|
const int ID = findId(TOKEN);
|
||||||
if( ID != WGT_NONE ) m_widgets[ID].widget->pulse();
|
if( ID != WGT_NONE ) m_widgets[ID].widget->m_scroll_speed_x = SPEED;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "WARNING: tried to pulse unnamed widget with token " <<
|
std::cerr << "WARNING: tried to set the X scroll speed of an " <<
|
||||||
TOKEN << '\n';
|
"unnamed widget with token " << TOKEN << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void WidgetManager::setWgtYScrollSpeed( const int TOKEN, const int SPEED )
|
||||||
|
{
|
||||||
|
const int ID = findId(TOKEN);
|
||||||
|
if( ID != WGT_NONE ) m_widgets[ID].widget->m_scroll_speed_y = SPEED;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "WARNING: tried to set the Y scroll speed of an " <<
|
||||||
|
"unnamed widget with token " << TOKEN << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void WidgetManager::enableWgtRotation( const int TOKEN )
|
||||||
|
{
|
||||||
|
const int ID = findId(TOKEN);
|
||||||
|
if( ID != WGT_NONE ) m_widgets[ID].widget->m_enable_rotation = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "WARNING: tried to enable rotation of an unnamed " <<
|
||||||
|
"widget with token " << TOKEN << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void WidgetManager::disableWgtRotation( const int TOKEN )
|
||||||
|
{
|
||||||
|
const int ID = findId(TOKEN);
|
||||||
|
if( ID != WGT_NONE ) m_widgets[ID].widget->m_enable_rotation = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "WARNING: tried to disable rotation of an unnamed " <<
|
||||||
|
"widget with token " << TOKEN << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void WidgetManager::setWgtRotationAngle( const int TOKEN, const float ANGLE )
|
||||||
|
{
|
||||||
|
const int ID = findId(TOKEN);
|
||||||
|
if( ID != WGT_NONE ) m_widgets[ID].widget->m_rotation_angle = ANGLE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "WARNING: tried to set the rotation angle of an "
|
||||||
|
"unnamed widget with token " << TOKEN << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void WidgetManager::setWgtRotationSpeed( const int TOKEN, const int SPEED )
|
||||||
|
{
|
||||||
|
const int ID = findId(TOKEN);
|
||||||
|
if( ID != WGT_NONE ) m_widgets[ID].widget->m_rotation_speed = SPEED;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "WARNING: tried to set the rotation speed of an "
|
||||||
|
"unnamed widget with token " << TOKEN << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1148,6 +1203,19 @@ void WidgetManager::setWgtTrackNum( const int TOKEN, const int TRACK )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** pulse_widget() passes the pulse order to the right widget.
|
||||||
|
*/
|
||||||
|
void WidgetManager::pulseWgt(const int TOKEN) const
|
||||||
|
{
|
||||||
|
const int ID = findId(TOKEN);
|
||||||
|
if( ID != WGT_NONE ) m_widgets[ID].widget->pulse();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "WARNING: tried to pulse unnamed widget with token " <<
|
||||||
|
TOKEN << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void WidgetManager::lightenWgtColor(const int TOKEN)
|
void WidgetManager::lightenWgtColor(const int TOKEN)
|
||||||
{
|
{
|
||||||
|
@ -110,6 +110,10 @@ class WidgetManager
|
|||||||
int m_default_scroll_x_speed;
|
int m_default_scroll_x_speed;
|
||||||
int m_default_scroll_y_speed;
|
int m_default_scroll_y_speed;
|
||||||
|
|
||||||
|
bool m_default_enable_rotation;
|
||||||
|
float m_default_rotation_angle;
|
||||||
|
int m_default_rotation_speed;
|
||||||
|
|
||||||
int m_default_show_track;
|
int m_default_show_track;
|
||||||
int m_default_track_num;
|
int m_default_track_num;
|
||||||
|
|
||||||
@ -193,6 +197,14 @@ public:
|
|||||||
const int Y_SPEED
|
const int Y_SPEED
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void setInitialRotationState
|
||||||
|
(
|
||||||
|
const bool ENABLE,
|
||||||
|
const float ANGLE,
|
||||||
|
const int SPEED
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
void setInitialTrackState
|
void setInitialTrackState
|
||||||
(
|
(
|
||||||
const bool SHOW,
|
const bool SHOW,
|
||||||
@ -232,6 +244,11 @@ public:
|
|||||||
void setWgtXScrollSpeed( const int TOKEN, const int SPEED );
|
void setWgtXScrollSpeed( const int TOKEN, const int SPEED );
|
||||||
void setWgtYScrollSpeed( const int TOKEN, const int SPEED );
|
void setWgtYScrollSpeed( const int TOKEN, const int SPEED );
|
||||||
|
|
||||||
|
void enableWgtRotation( const int TOKEN );
|
||||||
|
void disableWgtRotation( const int TOKEN );
|
||||||
|
void setWgtRotationAngle( const int TOKEN, const float ANGLE );
|
||||||
|
void setWgtRotationSpeed( const int TOKEN, const int SPEED );
|
||||||
|
|
||||||
void showWgtTrack( const int TOKEN );
|
void showWgtTrack( const int TOKEN );
|
||||||
void hideWgtTrack( const int TOKEN );
|
void hideWgtTrack( const int TOKEN );
|
||||||
void setWgtTrackNum( const int TOKEN, const int TRACK );
|
void setWgtTrackNum( const int TOKEN, const int TRACK );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user