[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src font.cpp
From: |
Jon Daniel |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src font.cpp |
Date: |
Fri, 04 Mar 2005 15:23:40 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Jon Daniel <address@hidden> 05/03/04 20:23:40
Modified files:
src : font.cpp
Log message:
* Added the complete utf8_string to text_surface again
* split only if necessary e.g. on the first call to width or height
* update set_text to set w_ and h_ to -1
* text_cache works again at least I get alot of hits in the campaign
selection dialog if scrolling up and down
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.114&tr2=1.115&r1=text&r2=text
Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.114 wesnoth/src/font.cpp:1.115
--- wesnoth/src/font.cpp:1.114 Fri Mar 4 16:52:07 2005
+++ wesnoth/src/font.cpp Fri Mar 4 20:23:40 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.114 2005/03/04 16:52:07 j_daniel Exp $ */
+/* $Id: font.cpp,v 1.115 2005/03/04 20:23:40 j_daniel Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -322,45 +322,47 @@
bool operator==(text_surface const &t) const {
return hash_ == t.hash_ && font_size_ == t.font_size_
- && color_ == t.color_ && style_ == t.style_ && chunks_
== t.chunks_;
+ && color_ == t.color_ && style_ == t.style_ && str_ ==
t.str_;
}
bool operator!=(text_surface const &t) const { return !operator==(t); }
private:
int hash_;
int font_size_;
- mutable std::vector<text_chunk> chunks_;
SDL_Color color_;
int style_;
mutable int w_, h_;
- mutable std::vector<surface> surfs_;
mutable bool initialized_;
- void hash(std::string const & str);
+ std::string str_;
+ mutable std::vector<text_chunk> chunks_;
+ mutable std::vector<surface> surfs_;
+ void hash();
};
text_surface::text_surface(std::string const &str, int size, SDL_Color color,
int style)
- : font_size_(size), color_(color), style_(style), w_(-1), h_(-1),
+ : font_size_(size), color_(color), style_(style), w_(-1), h_(-1), str_(str),
initialized_(false)
{
- hash(str);
- chunks_ = split_text(str);
+ hash();
}
text_surface::text_surface(int size, SDL_Color color, int style)
: hash_(0), font_size_(size), color_(color), style_(style), w_(-1), h_(-1),
initialized_(false)
-{}
+{
+}
void text_surface::set_text(std::string const &str)
{
- //FIXME hash and split should be done in the same loop.
- hash(str);
- chunks_ = split_text(str);
initialized_ = false;
+ w_ = -1;
+ h_ = -1;
+ str_ = str;
+ hash();
}
-void text_surface::hash(std::string const & str)
+void text_surface::hash()
{
int h = 0;
- for(std::string::const_iterator it = str.begin(), it_end = str.end();
it != it_end; ++it)
+ for(std::string::const_iterator it = str_.begin(), it_end = str_.end();
it != it_end; ++it)
h = ((h << 9) | (h >> (sizeof(int) * 8 - 9))) ^ (*it);
hash_ = h;
}
@@ -393,15 +395,21 @@
size_t text_surface::width() const
{
- if (w_ == -1)
+ if (w_ == -1) {
+ if(chunks_.empty())
+ chunks_ = split_text(str_);
measure();
+ }
return w_;
}
size_t text_surface::height() const
{
- if (h_ == -1)
+ if (h_ == -1) {
+ if(chunks_.empty())
+ chunks_ = split_text(str_);
measure();
+ }
return h_;
}
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Philippe Plantier, 2005/03/01
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp,
Jon Daniel <=
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, David White, 2005/03/07