Improved TTextField widget: set cursor position when clicking, more efficient calculation of cursor position
Fixed several cppcheck messages git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@693 0420edf4-82e4-42fc-9478-35b55e6d67a3master
parent
bb23733009
commit
debff52b66
|
@ -86,9 +86,9 @@ void PrintVector4(const TVector4d& v) {
|
|||
std::cout << v.x << " " << v.y << " " << v.z << " " << v.w << '\n';
|
||||
}
|
||||
|
||||
void PrintColor(const sf::Color& v) {
|
||||
void PrintColor(const sf::Color& c) {
|
||||
std::cout.precision(3);
|
||||
std::cout << v.r << " " << v.g << " " << v.b << '\n';
|
||||
std::cout << c.r << " " << c.g << " " << c.b << '\n';
|
||||
}
|
||||
|
||||
void PrintVector2(const TVector2d& v) {
|
||||
|
|
|
@ -107,7 +107,7 @@ bool DirExists(const char *dirname);
|
|||
void Message(const char *msg, const char *desc);
|
||||
void Message(const char *msg);
|
||||
void Message(const std::string& a, const std::string& b);
|
||||
void Message(const std::string& a);
|
||||
void Message(const std::string& msg);
|
||||
void SaveMessages();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
|
|
@ -183,12 +183,12 @@ int resultlevel(std::size_t num, std::size_t numraces) {
|
|||
return q + 1;
|
||||
}
|
||||
|
||||
void CEvent::Loop(float timestep) {
|
||||
void CEvent::Loop(float time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow(timestep);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
DrawGUIBackground(Winsys.scale);
|
||||
|
|
|
@ -120,12 +120,12 @@ void CEventSelect::Enter() {
|
|||
Music.Play(param.menu_music, true);
|
||||
}
|
||||
|
||||
void CEventSelect::Loop(float timestep) {
|
||||
void CEventSelect::Loop(float time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow(timestep);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
|
|
@ -271,9 +271,9 @@ const std::string& CPlayers::GetDirectAvatarName(std::size_t avatar) const {
|
|||
// Character Administration
|
||||
// ********************************************************************
|
||||
|
||||
CKeyframe* TCharacter::GetKeyframe(TFrameType type_) {
|
||||
if (type_ < 0 || type_ >= NUM_FRAME_TYPES) return nullptr;
|
||||
return &frames[type_];
|
||||
CKeyframe* TCharacter::GetKeyframe(TFrameType frametype) {
|
||||
if (frametype < 0 || frametype >= NUM_FRAME_TYPES) return nullptr;
|
||||
return &frames[frametype];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ struct TCharacter {
|
|||
int type;
|
||||
bool finishframesok;
|
||||
|
||||
CKeyframe* GetKeyframe(TFrameType type);
|
||||
CKeyframe* GetKeyframe(TFrameType frametype);
|
||||
};
|
||||
|
||||
class CCharacter {
|
||||
|
|
44
src/gui.cpp
44
src/gui.cpp
|
@ -213,7 +213,7 @@ TTextField::TTextField(int x, int y, int width, int height, const sf::String& te
|
|||
: TWidget(x, y, width, height)
|
||||
, text(text_, FT.getCurrentFont(), FT.AutoSizeN(5))
|
||||
, frame(sf::Vector2f(width-6.f, height-6.f))
|
||||
, cursorShape(sf::Vector2f(2.f, 26.f * Winsys.scale))
|
||||
, cursorShape(sf::Vector2f(2.f, 30.f * Winsys.scale))
|
||||
, maxLng(32)
|
||||
, time(0.0)
|
||||
, cursor(false) {
|
||||
|
@ -233,10 +233,10 @@ void TTextField::Draw() const {
|
|||
Winsys.draw(cursorShape);
|
||||
}
|
||||
|
||||
void TTextField::TextEnter(char key) {
|
||||
if (key != '\b') {
|
||||
void TTextField::TextEnter(char c) {
|
||||
if (c != '\b') {
|
||||
sf::String string = text.getString();
|
||||
string.insert(cursorPos, key);
|
||||
string.insert(cursorPos, c);
|
||||
text.setString(string);
|
||||
SetCursorPos(cursorPos+1);
|
||||
}
|
||||
|
@ -244,16 +244,7 @@ void TTextField::TextEnter(char key) {
|
|||
|
||||
void TTextField::SetCursorPos(std::size_t new_pos) {
|
||||
cursorPos = new_pos;
|
||||
|
||||
float x = mouseRect.left + 20 - 2;
|
||||
if (cursorPos != 0) {
|
||||
sf::String temp = text.getString();
|
||||
|
||||
FT.AutoSizeN(5);
|
||||
x += FT.GetTextWidth(temp.substring(0, cursorPos));
|
||||
}
|
||||
|
||||
cursorShape.setPosition(x, mouseRect.top + 9);
|
||||
cursorShape.setPosition(text.findCharacterPos(cursorPos).x, mouseRect.top + 9);
|
||||
}
|
||||
|
||||
void TTextField::Focussed() {
|
||||
|
@ -268,6 +259,23 @@ void TTextField::Focussed() {
|
|||
}
|
||||
}
|
||||
|
||||
bool TTextField::Click(int x, int y) {
|
||||
if (TWidget::Click(x, y)) {
|
||||
cursorPos = 0;
|
||||
float first = text.findCharacterPos(cursorPos).x;
|
||||
for (;;) {
|
||||
float second = text.findCharacterPos(cursorPos + 1).x;
|
||||
if ((first + second) / 2.f >= x || cursorPos >= text.getString().getSize())
|
||||
break;
|
||||
cursorPos++;
|
||||
first = second;
|
||||
}
|
||||
cursorShape.setPosition(text.findCharacterPos(cursorPos).x, mouseRect.top + 9);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void eraseFromText(sf::Text& text, std::size_t pos) {
|
||||
sf::String str = text.getString();
|
||||
str.erase(pos, 1);
|
||||
|
@ -641,13 +649,13 @@ void DrawGUIFrame() {
|
|||
Winsys.draw(top_right);
|
||||
}
|
||||
|
||||
void DrawGUIBackground(float logoScale) {
|
||||
void DrawGUIBackground(float scale) {
|
||||
DrawGUIFrame();
|
||||
|
||||
static sf::Sprite logo(Tex.GetSFTexture(T_TITLE));
|
||||
logoScale *= 0.5f;
|
||||
logo.setScale(logoScale, logoScale);
|
||||
logo.setPosition((Winsys.resolution.width - logo.getTextureRect().width*logoScale)/2, 5);
|
||||
scale *= 0.5f;
|
||||
logo.setScale(scale, scale);
|
||||
logo.setPosition((Winsys.resolution.width - logo.getTextureRect().width*scale)/2, 5);
|
||||
Winsys.draw(logo);
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,8 @@ class TTextField : public TWidget {
|
|||
public:
|
||||
TTextField(int x, int y, int width, int height, const sf::String& text_);
|
||||
void Draw() const;
|
||||
void TextEnter(char text);
|
||||
void TextEnter(char c);
|
||||
bool Click(int x, int y);
|
||||
void Key(sf::Keyboard::Key key, bool released);
|
||||
void Focussed();
|
||||
void UpdateCursor(float timestep);
|
||||
|
@ -129,7 +130,7 @@ class TCheckbox : public TWidget {
|
|||
public:
|
||||
bool checked;
|
||||
|
||||
TCheckbox(int x, int y, int width_, const sf::String& tag_);
|
||||
TCheckbox(int x, int y, int width, const sf::String& tag_);
|
||||
void Draw() const;
|
||||
void SetPosition(int x, int y);
|
||||
void SetChecked(bool c) { checked = c; }
|
||||
|
|
|
@ -68,12 +68,12 @@ void CHelp::Enter() {
|
|||
footnote = AddLabel(Trans.Text(65), CENTER, AutoYPosN(90), colWhite);
|
||||
}
|
||||
|
||||
void CHelp::Loop(float timestep) {
|
||||
void CHelp::Loop(float time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow(timestep);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
void Update(float timestep);
|
||||
void UpdateTest(float timestep, CCharShape *shape);
|
||||
bool Load(const std::string& dir, const std::string& filename);
|
||||
void CalcKeyframe(std::size_t idx, CCharShape *shape, const TVector3d& refpos) const;
|
||||
void CalcKeyframe(std::size_t idx, CCharShape *shape, const TVector3d& refpos_) const;
|
||||
|
||||
// test and editing
|
||||
TKeyframe *GetFrame(std::size_t idx);
|
||||
|
|
|
@ -56,7 +56,7 @@ TMatrix<4, 4> RotateAboutVectorMatrix(const TVector3d& u, double angle);
|
|||
TQuaternion MultiplyQuaternions(const TQuaternion& q, const TQuaternion& r);
|
||||
TQuaternion ConjugateQuaternion(const TQuaternion& q);
|
||||
TMatrix<4, 4> MakeMatrixFromQuaternion(const TQuaternion& q);
|
||||
TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& mat);
|
||||
TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& m);
|
||||
TQuaternion MakeRotationQuaternion(const TVector3d& s, const TVector3d& t);
|
||||
TQuaternion InterpolateQuaternions(const TQuaternion& q, TQuaternion r, double t);
|
||||
TVector3d RotateVector(const TQuaternion& q, const TVector3d& v);
|
||||
|
|
|
@ -108,18 +108,18 @@ void CNewPlayer::Enter() {
|
|||
textfield = AddTextField(emptyString, area.left, frametop, framewidth, frameheight);
|
||||
}
|
||||
|
||||
void CNewPlayer::Loop(float timestep) {
|
||||
void CNewPlayer::Loop(float time_step) {
|
||||
sf::Color col;
|
||||
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow(timestep);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
textfield->UpdateCursor(timestep);
|
||||
textfield->UpdateCursor(time_step);
|
||||
|
||||
DrawGUIBackground(Winsys.scale);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ void check_gl_error();
|
|||
void InitOpenglExtensions();
|
||||
void PrintGLInfo();
|
||||
|
||||
void set_material_diffuse(const sf::Color& specular_colour);
|
||||
void set_material_diffuse(const sf::Color& diffuse_colour);
|
||||
void set_material(const sf::Color& diffuse_colour,
|
||||
const sf::Color& specular_colour,
|
||||
float specular_exp);
|
||||
|
|
|
@ -50,7 +50,7 @@ void COglTest::Keyb(sf::Keyboard::Key key, bool release, int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void COglTest::Loop(float timestep) {
|
||||
void COglTest::Loop(float time_step) {
|
||||
// ------------- 3d scenery ---------------------------------------
|
||||
ScopedRenderMode rm(TUX);
|
||||
ClearRenderContext(colDDBackgr);
|
||||
|
|
|
@ -473,27 +473,26 @@ void TFlake::Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float d
|
|||
|
||||
TFlakeArea::TFlakeArea(
|
||||
std::size_t num_flakes,
|
||||
float _xrange,
|
||||
float _ytop,
|
||||
float _yrange,
|
||||
float _zback,
|
||||
float _zrange,
|
||||
float _minSize,
|
||||
float _maxSize,
|
||||
float _speed,
|
||||
bool rotate) {
|
||||
xrange = _xrange;
|
||||
ytop = _ytop;
|
||||
yrange = _yrange;
|
||||
zback = _zback;
|
||||
zrange = _zrange;
|
||||
minSize = _minSize;
|
||||
maxSize = _maxSize;
|
||||
speed = _speed;
|
||||
float xrange_,
|
||||
float ytop_,
|
||||
float yrange_,
|
||||
float zback_,
|
||||
float zrange_,
|
||||
float minSize_,
|
||||
float maxSize_,
|
||||
float speed_,
|
||||
bool rotate)
|
||||
: flakes(num_flakes) {
|
||||
xrange = xrange_;
|
||||
ytop = ytop_;
|
||||
yrange = yrange_;
|
||||
zback = zback_;
|
||||
zrange = zrange_;
|
||||
minSize = minSize_;
|
||||
maxSize = maxSize_;
|
||||
speed = speed_;
|
||||
rotate_flake = rotate;
|
||||
left = right = bottom = top = front = back = 0.f;
|
||||
|
||||
flakes.resize(num_flakes);
|
||||
}
|
||||
|
||||
void TFlakeArea::Draw(const CControl *ctrl) const {
|
||||
|
|
|
@ -75,14 +75,14 @@ struct TFlakeArea {
|
|||
|
||||
TFlakeArea(
|
||||
std::size_t num_flakes,
|
||||
float xrange,
|
||||
float ytop,
|
||||
float yrange,
|
||||
float zback,
|
||||
float zrange,
|
||||
float minSize,
|
||||
float maxSize,
|
||||
float speed,
|
||||
float xrange_,
|
||||
float ytop_,
|
||||
float yrange_,
|
||||
float zback_,
|
||||
float zrange_,
|
||||
float minSize_,
|
||||
float maxSize_,
|
||||
float speed_,
|
||||
bool rotate);
|
||||
void Draw(const CControl* ctrl) const;
|
||||
void Update(float timestep, float xcoeff, float ycoeff, float zcoeff);
|
||||
|
@ -143,7 +143,7 @@ struct TCurtain {
|
|||
float base_speed,
|
||||
float start_angle,
|
||||
float min_height,
|
||||
int curt_texture);
|
||||
int dense);
|
||||
void SetStartParams(const CControl* ctrl);
|
||||
void Draw() const;
|
||||
void Update(float timestep, const TVector3d& drift, const CControl* ctrl);
|
||||
|
|
|
@ -1050,8 +1050,8 @@ void quadsquare::SetScale(double x, double z) {
|
|||
}
|
||||
|
||||
CourseFields* quadsquare::Fields;
|
||||
void quadsquare::SetFields(CourseFields* t) {
|
||||
Fields = t;
|
||||
void quadsquare::SetFields(CourseFields* fields) {
|
||||
Fields = fields;
|
||||
}
|
||||
|
||||
float HeightMapInfo::Sample(int x, int z) const {
|
||||
|
|
|
@ -100,7 +100,7 @@ struct quadsquare {
|
|||
void SetFields(CourseFields* fields);
|
||||
|
||||
private:
|
||||
quadsquare* EnableDescendant(int count, int stack[],
|
||||
quadsquare* EnableDescendant(int count, int path[],
|
||||
const quadcornerdata& cd);
|
||||
quadsquare* GetNeighbor(int dir, const quadcornerdata &cd);
|
||||
clip_result_t ClipSquare(const quadcornerdata &cd);
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
void StaticCullAux(const quadcornerdata &cd, float ThresholdDetail,
|
||||
int TargetLevel);
|
||||
void CreateChild(int index, const quadcornerdata &cd);
|
||||
void SetupCornerData(quadcornerdata *q, const quadcornerdata &pd,
|
||||
void SetupCornerData(quadcornerdata *q, const quadcornerdata &cd,
|
||||
int ChildIndex);
|
||||
void UpdateAux(const quadcornerdata &cd, const float ViewerLocation[3],
|
||||
float CenterError, clip_result_t vis);
|
||||
|
|
|
@ -185,12 +185,12 @@ void CRaceSelect::Enter() {
|
|||
SetFocus(course);
|
||||
}
|
||||
|
||||
void CRaceSelect::Loop(float timestep) {
|
||||
void CRaceSelect::Loop(float time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow(timestep);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
|
|
@ -120,12 +120,12 @@ void CRegist::Enter() {
|
|||
sCharFrame = AddFramedText(area.left + framewidth + arrowwidth, area.top, framewidth, frameheight, 3, colMBackgr, "", FT.GetSize());
|
||||
}
|
||||
|
||||
void CRegist::Loop(float timestep) {
|
||||
void CRegist::Loop(float time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow(timestep);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
|
|
@ -245,12 +245,12 @@ void CScore::Enter() {
|
|||
courseName = AddFramedText(area.left, frametop - 2 + frameheight + 20, framewidth, frameheight, 3, colMBackgr, "", FT.GetSize(), true);
|
||||
}
|
||||
|
||||
void CScore::Loop(float timestep) {
|
||||
void CScore::Loop(float time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow(timestep);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ void CSplashScreen::Enter() {
|
|||
Music.Play(param.menu_music, true);
|
||||
}
|
||||
|
||||
void CSplashScreen::Loop(float timestep) {
|
||||
void CSplashScreen::Loop(float time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
Trans.LoadTranslations(param.language); // Before first texts are being displayed
|
||||
|
|
|
@ -279,16 +279,16 @@ void CTools::Motion(int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void CTools::Loop(float timestep) {
|
||||
void CTools::Loop(float time_step) {
|
||||
switch (tool_mode) {
|
||||
case 0:
|
||||
RenderChar(timestep);
|
||||
RenderChar(time_step);
|
||||
break;
|
||||
case 1:
|
||||
RenderSingleFrame(timestep);
|
||||
RenderSingleFrame(time_step);
|
||||
break;
|
||||
case 2:
|
||||
RenderSequence(timestep);
|
||||
RenderSequence(time_step);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
10
src/tux.cpp
10
src/tux.cpp
|
@ -485,14 +485,14 @@ bool CCharShape::Load(const std::string& dir, const std::string& filename, bool
|
|||
return true;
|
||||
}
|
||||
|
||||
TVector3d CCharShape::AdjustRollvector(const CControl *ctrl, const TVector3d& vel_, const TVector3d& zvec) {
|
||||
TVector3d CCharShape::AdjustRollvector(const CControl *ctrl, const TVector3d& vel, const TVector3d& zvec) {
|
||||
TMatrix<4, 4> rot_mat;
|
||||
TVector3d vel = ProjectToPlane(zvec, vel_);
|
||||
vel.Norm();
|
||||
TVector3d v = ProjectToPlane(zvec, vel);
|
||||
v.Norm();
|
||||
if (ctrl->is_braking) {
|
||||
rot_mat = RotateAboutVectorMatrix(vel, ctrl->turn_fact * BRAKING_ROLL_ANGLE);
|
||||
rot_mat = RotateAboutVectorMatrix(v, ctrl->turn_fact * BRAKING_ROLL_ANGLE);
|
||||
} else {
|
||||
rot_mat = RotateAboutVectorMatrix(vel, ctrl->turn_fact * MAX_ROLL_ANGLE);
|
||||
rot_mat = RotateAboutVectorMatrix(v, ctrl->turn_fact * MAX_ROLL_ANGLE);
|
||||
}
|
||||
return TransformVector(rot_mat, zvec);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ float CWinsys::CalcScreenScale() const {
|
|||
else return (resolution.height / 768.f);
|
||||
}
|
||||
|
||||
void CWinsys::SetupVideoMode(const TScreenRes& resolution_) {
|
||||
void CWinsys::SetupVideoMode(const TScreenRes& res) {
|
||||
int bpp = 32;
|
||||
switch (param.bpp_mode) {
|
||||
case 16:
|
||||
|
@ -93,7 +93,7 @@ void CWinsys::SetupVideoMode(const TScreenRes& resolution_) {
|
|||
if (param.fullscreen)
|
||||
style |= sf::Style::Fullscreen;
|
||||
|
||||
resolution = resolution_;
|
||||
resolution = res;
|
||||
|
||||
ResetRenderMode();
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
const TScreenRes& GetResolution(std::size_t idx) const;
|
||||
std::string GetResName(std::size_t idx) const;
|
||||
void Init();
|
||||
void SetupVideoMode(const TScreenRes& resolution);
|
||||
void SetupVideoMode(const TScreenRes& res);
|
||||
void SetupVideoMode(std::size_t idx);
|
||||
void SetupVideoMode(int width, int height);
|
||||
void KeyRepeat(bool repeat);
|
||||
|
|
Loading…
Reference in New Issue