• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1801 (tree)
日時2010-04-24 22:58:09
作者satofumi

ログメッセージ

added TextFadeSurface.h

変更サマリ

差分

--- trunk/libs/lua/luabindGui.cpp (revision 1800)
+++ trunk/libs/lua/luabindGui.cpp (revision 1801)
@@ -16,6 +16,7 @@
1616 #include "Layer.h"
1717 #include "Font.h"
1818 #include "TextSurface.h"
19+#include "TextFadeSurface.h"
1920 #include "ColorSurface.h"
2021 #include "FillSurface.h"
2122 #include "ImageSurface.h"
@@ -118,6 +119,12 @@
118119 .def("setAlpha", &TextSurface::setAlpha)
119120 .def("draw", &TextSurface::draw),
120121
122+ class_<TextFadeSurface, Surface>("TextFadeSurface")
123+ .def(constructor<const Font&, const char*>())
124+ .def("rect", &TextFadeSurface::rect)
125+ .def("setAlpha", &TextFadeSurface::setAlpha)
126+ .def("draw", &TextFadeSurface::draw),
127+
121128 class_<ColorSurface, Surface>("ColorSurface")
122129 .def(constructor<const Rect<long>&, const Color&>())
123130 .def("rect", &ColorSurface::rect)
--- trunk/libs/lua/Makefile (revision 1800)
+++ trunk/libs/lua/Makefile (revision 1801)
@@ -85,10 +85,11 @@
8585 luabindGui.o: ../gui/EventUtils.h ../gui/LayerManager.h
8686 luabindGui.o: ../gui/LayerInterface.h ../gui/Layer.h ../gui/Font.h
8787 luabindGui.o: ../common/Color.h ../gui/TextSurface.h ../gui/Surface.h
88-luabindGui.o: ../gui/ColorSurface.h ../gui/FillSurface.h
89-luabindGui.o: ../gui/ImageSurface.h ../gui/MultiSurface.h ../gui/Label.h
90-luabindGui.o: ../gui/Component.h ../gui/Button.h ../gui/Menu.h
91-luabindGui.o: ../gui/ChatMessage.h ../gui/CallbackEvent.h ../gui/AlignUtils.h
88+luabindGui.o: ../gui/TextFadeSurface.h ../gui/ColorSurface.h
89+luabindGui.o: ../gui/FillSurface.h ../gui/ImageSurface.h
90+luabindGui.o: ../gui/MultiSurface.h ../gui/Label.h ../gui/Component.h
91+luabindGui.o: ../gui/Button.h ../gui/Menu.h ../gui/ChatMessage.h
92+luabindGui.o: ../gui/CallbackEvent.h ../gui/AlignUtils.h
9293 luabindInit.o: luabindInit.h LuaHandler.h ../system/log_printf.h
9394 luabindInput.o: luabindInput.h ../input/convertToRoman.h
9495 luabindInput.o: ../input/convertToJp.h ../input/Utf8.h ../input/utf8_string.h
--- trunk/libs/gui/TextFadeSurface.h (nonexistent)
+++ trunk/libs/gui/TextFadeSurface.h (revision 1801)
@@ -0,0 +1,49 @@
1+#ifndef TEXT_FADE_SURFACE_H
2+#define TEXT_FADE_SURFACE_H
3+
4+/*!
5+ \file
6+ \brief 部分透過できる文字列サーフェス
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include "Surface.h"
14+#include <cstddef>
15+#include <memory>
16+
17+
18+namespace qrk
19+{
20+ class Font;
21+
22+
23+ class TextFadeSurface : public Surface
24+ {
25+ public:
26+ explicit TextFadeSurface(const Font& font, const char* text);
27+ ~TextFadeSurface(void);
28+
29+ bool isValid(void) const;
30+ Rect<long> rect(void) const;
31+ void setAlpha(float alpha);
32+ float alpha(void) const;
33+ void setRotateAngle(const Angle& angle);
34+ void draw(const Rect<long>* src, const Rect<long>* dest);
35+
36+ // !!! フェードのモードを指定するメソッド
37+ void setFadePercent(size_t percent);
38+
39+ private:
40+ TextFadeSurface(void);
41+ TextFadeSurface(const TextFadeSurface& rhs);
42+ TextFadeSurface& operator = (const TextFadeSurface& rhs);
43+
44+ struct pImpl;
45+ std::auto_ptr<pImpl> pimpl;
46+ };
47+}
48+
49+#endif /* !TEXT_FADE_SURFACE_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/libs/gui/Makefile (revision 1800)
+++ trunk/libs/gui/Makefile (revision 1801)
@@ -4,7 +4,7 @@
44 # Compile options
55 CC = $(CXX)
66 CXXFLAGS = -g -O0 -Wall -W -Werror $(INCLUDES) `sdl-config --cflags`
7-INCLUDES = -I../geometry -I../system/sdl -I../system -I../common -I../math
7+INCLUDES = -I../geometry -I../system/sdl -I../system -I../common -I../math -I../input
88
99 # Target
1010 GUI_LIB = gui.a
@@ -33,6 +33,7 @@
3333 $(GUI_LIB)(EventUtils.o) \
3434 $(GUI_LIB)(SDL_GL_Texture.o) \
3535 $(GUI_LIB)(TextSurface.o) \
36+ $(GUI_LIB)(TextFadeSurface.o) \
3637 $(GUI_LIB)(ColorSurface.o) \
3738 $(GUI_LIB)(FillSurface.o) \
3839 $(GUI_LIB)(SwitchSurface.o) \
@@ -66,6 +67,7 @@
6667 Screen.o: ../geometry/Rect.h
6768 Surface.o: ../geometry/Rect.h
6869 SwitchSurface.o: Surface.h ../geometry/Rect.h
70+TextFadeSurface.o: Surface.h ../geometry/Rect.h
6971 TextInput.o: Event.h ../geometry/Point.h
7072 TextSurface.o: Surface.h ../geometry/Rect.h
7173 AlignUtils.o: AlignUtils.h Component.h ../geometry/Rect.h ../geometry/Point.h
@@ -106,6 +108,8 @@
106108 SdlTtfInit.o: ../system/sdl/SdlInit.h SdlTtfInit.h
107109 SdlVideoInit.o: SdlVideoInit.h ../system/sdl/SdlInit.h
108110 SwitchSurface.o: SwitchSurface.h Surface.h ../geometry/Rect.h
111+TextFadeSurface.o: TextFadeSurface.h Surface.h ../geometry/Rect.h
112+TextFadeSurface.o: TextSurface.h ../input/Utf8.h
109113 TextInput.o: TextInput.h Event.h ../geometry/Point.h LayerManager.h
110114 TextInput.o: LayerInterface.h CallbackEvent.h ../geometry/Rect.h
111115 TextSurface.o: TextSurface.h Surface.h ../geometry/Rect.h Font.h
--- trunk/libs/gui/TextFadeSurface.cpp (nonexistent)
+++ trunk/libs/gui/TextFadeSurface.cpp (revision 1801)
@@ -0,0 +1,153 @@
1+/*!
2+ \file
3+ \brief 部分透過できる文字列サーフェス
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "TextFadeSurface.h"
11+#include "TextSurface.h"
12+#include "Utf8.h"
13+#include <vector>
14+
15+using namespace qrk;
16+using namespace std;
17+
18+
19+struct TextFadeSurface::pImpl
20+{
21+ enum {
22+ FadeWidthPixel = 100,
23+ };
24+
25+ typedef vector<Surface*> Surfaces;
26+ Surfaces text_surfaces_;
27+ Rect<long> rect_;
28+ float base_alpha_;
29+ size_t percent_;
30+
31+
32+ pImpl(const Font& font, const char* text) : base_alpha_(1.0), percent_(100)
33+ {
34+ // 文字毎にサーフェスを作る
35+ Utf8 utf8_text(text);
36+ size_t n = utf8_text.size();
37+ for (size_t i = 0; i < n; ++i) {
38+ string ch = utf8_text.substr(i, 1).c_str();
39+ Surface* surface = new TextSurface(font, ch.c_str());
40+ text_surfaces_.push_back(surface);
41+ rect_.w += surface->rect().w;
42+ rect_.h = max(rect_.h, surface->rect().h);
43+ }
44+ }
45+
46+
47+ ~pImpl(void)
48+ {
49+ for (Surfaces::iterator it = text_surfaces_.begin();
50+ it != text_surfaces_.end(); ++it) {
51+ delete *it;
52+ }
53+ }
54+
55+
56+ void draw(const Rect<long>* src, const Rect<long>* dest)
57+ {
58+ Rect<long> sub_dest(*dest);
59+ for (Surfaces::iterator it = text_surfaces_.begin();
60+ it != text_surfaces_.end(); ++it) {
61+ Surface* surface = *it;
62+ sub_dest.w = surface->rect().w;
63+ sub_dest.h = surface->rect().h;
64+ surface->draw(src, &sub_dest);
65+ sub_dest.x += surface->rect().w;
66+ }
67+ }
68+
69+
70+ void setAlpha(void)
71+ {
72+ int moved_width =
73+ static_cast<int>((rect_.w + FadeWidthPixel) * percent_ / 100.0);
74+ int first = -FadeWidthPixel + moved_width;
75+ int last = 0 + moved_width;
76+ int x = 0;
77+ for (Surfaces::iterator it = text_surfaces_.begin();
78+ it != text_surfaces_.end(); ++it) {
79+ Surface* surface = *it;
80+
81+ float alpha = 100.0;
82+ if (x > last) {
83+ alpha = 0.0;
84+ } else if (x <= first) {
85+ alpha = 1.0;
86+ } else {
87+ alpha = (last - x) / static_cast<float>(FadeWidthPixel);
88+ }
89+ surface->setAlpha(alpha * base_alpha_);
90+ x += surface->rect().w;
91+ }
92+ }
93+};
94+
95+
96+TextFadeSurface::TextFadeSurface(const Font& font, const char* text)
97+ : pimpl(new pImpl(font, text))
98+{
99+}
100+
101+
102+TextFadeSurface::~TextFadeSurface(void)
103+{
104+}
105+
106+
107+bool TextFadeSurface::isValid(void) const
108+{
109+ if (pimpl->text_surfaces_.empty()) {
110+ return false;
111+ }
112+ return pimpl->text_surfaces_.front()->isValid();
113+}
114+
115+
116+Rect<long> TextFadeSurface::rect(void) const
117+{
118+ return pimpl->rect_;
119+}
120+
121+
122+void TextFadeSurface::setAlpha(float alpha)
123+{
124+ pimpl->base_alpha_ = alpha;
125+ pimpl->setAlpha();
126+}
127+
128+
129+float TextFadeSurface::alpha(void) const
130+{
131+ return pimpl->base_alpha_;
132+}
133+
134+
135+void TextFadeSurface::setRotateAngle(const Angle& angle)
136+{
137+ (void)angle;
138+
139+ // !!!
140+}
141+
142+
143+void TextFadeSurface::draw(const Rect<long>* src, const Rect<long>* dest)
144+{
145+ pimpl->draw(src, dest);
146+}
147+
148+
149+void TextFadeSurface::setFadePercent(size_t percent)
150+{
151+ pimpl->percent_ = percent;
152+ pimpl->setAlpha();
153+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/libs/gui/samples/fadeText.cpp (nonexistent)
+++ trunk/libs/gui/samples/fadeText.cpp (revision 1801)
@@ -0,0 +1,41 @@
1+/*!
2+ \example TextFadeSurafce.cpp の動作サンプル
3+
4+ \author Satofumi KAMIMURA
5+
6+ $Id$
7+*/
8+
9+#include "Screen.h"
10+#include "Font.h"
11+#include "TextFadeSurface.h"
12+
13+using namespace qrk;
14+
15+
16+int main(int argc, char *argv[])
17+{
18+ Screen screen;
19+ screen.show(SDL_OPENGL);
20+
21+ // フォントの読み出し
22+ const char* font_file = (argc <= 1) ? "font.ttf" : argv[1];
23+ Font font(font_file, 32);
24+
25+ // 文字列の描画
26+ TextFadeSurface surface(font, "This is sample text.");
27+ Rect<long> dest_rect = surface.rect();
28+
29+ // 描画した文字列のをフェードさせる
30+ for (size_t j = 0; j < 2; ++j) {
31+ for (size_t i = 0; i <= 100; ++i) {
32+ screen.clear();
33+ surface.setFadePercent(i);
34+ surface.draw(NULL, &dest_rect);
35+ SDL_GL_SwapBuffers();
36+ SDL_Delay(10);
37+ }
38+ SDL_Delay(100);
39+ }
40+ return 0;
41+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/libs/gui/samples/Makefile (revision 1800)
+++ trunk/libs/gui/samples/Makefile (revision 1801)
@@ -12,6 +12,7 @@
1212
1313 # Target
1414 TARGET = \
15+ fadeText \
1516 simpleScreen \
1617 glScreen \
1718 glTextureDraw \
@@ -36,12 +37,12 @@
3637
3738 .PHONY : all clean depend
3839 ######################################################################
39-REQUIRE_LIBS = ../gui.a ../../geometry/geometry.a ../../system/system.a ../../system/sdl/system_sdl.a
40+REQUIRE_LIBS = ../gui.a ../../input/input.a ../../geometry/geometry.a ../../system/system.a ../../system/sdl/system_sdl.a
4041
4142 $(REQUIRE_LIBS) :
4243 cd $(@D)/ && $(MAKE) $(@F)
4344
44-PROGRAMS = drawText handleEvent inputDraw chatMessageSample rectMove buttonSample menuSample drawColorSurface
45+PROGRAMS = drawText handleEvent inputDraw chatMessageSample rectMove buttonSample menuSample drawColorSurface fadeText
4546 $(PROGRAMS) : $(REQUIRE_LIBS)
4647
4748 # DO NOT DELETE
@@ -61,6 +62,8 @@
6162 drawColorSurface.o: ../Surface.h ../ImageSurface.h ../../common/Color.h
6263 drawText.o: ../Screen.h ../../geometry/Rect.h ../Font.h ../../common/Color.h
6364 drawText.o: ../TextSurface.h ../Surface.h
65+fadeText.o: ../Screen.h ../../geometry/Rect.h ../Font.h ../../common/Color.h
66+fadeText.o: ../TextFadeSurface.h ../Surface.h
6467 handleEvent.o: ../Screen.h ../../geometry/Rect.h ../CallbackEvent.h
6568 handleEvent.o: ../Event.h ../../geometry/Point.h ../LayerManager.h
6669 handleEvent.o: ../LayerInterface.h ../../system/delay.h
旧リポジトリブラウザで表示