5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #ifndef _COMPOUNDPART_H
21 #define _COMPOUNDPART_H
24 #include "renderable.h"
33 bool operator()(const class CompoundPart
*s1
, const class CompoundPart
*s2
) const;
36 class CompoundPart
: public renderable
{
38 std::multiset
<CompoundPart
*, partzorder
>::iterator zorder_iter
;
41 CompoundPart(Agent
*p
, unsigned int _id
, int _x
, int _y
, int _z
);
45 unsigned int zorder
, id
;
50 virtual void render(class Surface
*renderer
, int xoffset
, int yoffset
);
51 virtual void partRender(class Surface
*renderer
, int xoffset
, int yoffset
) = 0;
52 virtual void tick() { }
54 virtual bool canGainFocus() { return false; }
55 virtual void gainFocus();
56 virtual void loseFocus();
57 virtual int handleClick(float, float);
58 virtual void handleKey(char c
);
59 virtual void handleSpecialKey(char c
);
61 virtual unsigned int getWidth() = 0;
62 virtual unsigned int getHeight() = 0;
64 virtual bool showOnRemoteCameras();
66 Agent
*getParent() const { return parent
; }
67 unsigned int getZOrder() const;
71 bool operator < (const CompoundPart
&b
) const {
72 return zorder
< b
.zorder
;
75 virtual ~CompoundPart();
78 class AnimatablePart
: public CompoundPart
{
81 AnimatablePart(Agent
*p
, unsigned int _id
, int _x
, int _y
, int _z
) : CompoundPart(p
, _id
, _x
, _y
, _z
) { frameno
= 0; }
84 bytestring_t animation
;
85 virtual void setPose(unsigned int p
) = 0;
86 virtual void setFrameNo(unsigned int f
) = 0;
87 unsigned int getFrameNo() { return frameno
; }
90 class SpritePart
: public AnimatablePart
{
92 shared_ptr
<creaturesImage
> origsprite
, sprite
;
93 unsigned int firstimg
, pose
, base
, spriteno
;
94 SpritePart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
100 unsigned char framerate
;
101 unsigned int framedelay
;
102 shared_ptr
<creaturesImage
> getSprite() { return sprite
; }
103 virtual void partRender(class Surface
*renderer
, int xoffset
, int yoffset
);
105 unsigned int getPose() { return pose
; }
106 unsigned int getBase() { return base
; }
107 unsigned int getCurrentSprite() { return spriteno
; }
108 unsigned int getFirstImg() { return firstimg
; }
109 unsigned int getWidth();
110 unsigned int getHeight();
111 void setFrameNo(unsigned int f
);
112 void setPose(unsigned int p
);
113 void setFramerate(unsigned char f
) { framerate
= f
; framedelay
= 0; }
114 void setBase(unsigned int b
);
115 void changeSprite(std::string spritefile
, unsigned int fimg
);
116 void tint(unsigned char r
, unsigned char g
, unsigned char b
, unsigned char rotation
, unsigned char swap
);
117 virtual bool isTransparent() { return is_transparent
; }
118 bool transparentAt(unsigned int x
, unsigned int y
);
120 virtual ~SpritePart();
123 class ButtonPart
: public SpritePart
{
125 bool hitopaquepixelsonly
;
127 bytestring_t hoveranimation
;
130 ButtonPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
131 unsigned int _z
, const bytestring_t
&animhover
, int msgid
, int option
);
132 int handleClick(float, float);
133 bool isTransparent() { return hitopaquepixelsonly
; }
136 class DullPart
: public SpritePart
{
138 DullPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
, unsigned int _z
);
143 unsigned int offset
, width
;
145 void reset(unsigned int o
) { offset
= o
; text
= ""; width
= 0; }
146 linedata() { reset(0); }
149 struct texttintinfo
{
150 shared_ptr
<creaturesImage
> sprite
;
154 enum horizontalalign
{ leftalign
, centeralign
, rightalign
};
155 enum verticalalign
{ top
, middle
, bottom
};
157 class TextPart
: public SpritePart
{
159 std::vector
<texttintinfo
> tints
;
160 std::vector
<linedata
> lines
;
161 std::vector
<unsigned int> pages
;
162 std::vector
<unsigned int> pageheights
;
163 unsigned int currpage
;
166 shared_ptr
<creaturesImage
> textsprite
;
168 int leftmargin
, topmargin
, rightmargin
, bottommargin
;
169 int linespacing
, charspacing
;
170 horizontalalign horz_align
;
171 verticalalign vert_align
;
172 bool last_page_scroll
;
174 TextPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
, unsigned int _z
, std::string fontsprite
);
176 void recalculateData();
177 unsigned int calculateWordWidth(std::string word
);
178 void addTint(std::string tintinfo
);
181 virtual void setText(std::string t
);
182 std::string
getText() { return text
; }
183 unsigned int noPages() { return pages
.size(); }
184 void setPage(unsigned int p
) { currpage
= p
; }
185 unsigned int getPage() { return currpage
; }
186 void partRender(class Surface
*renderer
, int xoffset
, int yoffset
, class TextEntryPart
*caretdata
);
187 void partRender(class Surface
*renderer
, int xoffset
, int yoffset
) { partRender(renderer
, xoffset
, yoffset
, 0); }
188 void setFormat(int left
, int top
, int right
, int bottom
, int line
, int _char
, horizontalalign horza
, verticalalign verta
, bool lastpagescroll
);
191 class FixedTextPart
: public TextPart
{
193 FixedTextPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
194 unsigned int _z
, std::string fontsprite
);
197 class GraphPart
: public SpritePart
{
199 GraphPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
200 unsigned int _z
, unsigned int novalues
);
203 class TextEntryPart
: public TextPart
{
205 static shared_ptr
<creaturesImage
> caretsprite
;
206 unsigned int caretpose
;
208 unsigned int caretpos
;
209 unsigned int messageid
;
210 void renderCaret(class Surface
*renderer
, int xoffset
, int yoffset
);
212 friend class TextPart
;
215 TextEntryPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
216 unsigned int _z
, unsigned int msgid
, std::string fontsprite
);
217 void setText(std::string t
);
218 bool canGainFocus() { return true; }
219 void gainFocus() { focused
= true; caretpose
= 0; }
220 void loseFocus() { focused
= false; }
221 int handleClick(float, float);
222 void handleKey(char c
);
223 void handleSpecialKey(char c
);
225 virtual void partRender(class Surface
*renderer
, int xoffset
, int yoffset
);
226 bool isTransparent() { return false; }