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() { }
53 virtual int handleClick(float, float);
54 virtual unsigned int getWidth() = 0;
55 virtual unsigned int getHeight() = 0;
57 virtual bool showOnRemoteCameras();
59 Agent
*getParent() const { return parent
; }
60 unsigned int getZOrder() const;
64 bool operator < (const CompoundPart
&b
) const {
65 return zorder
< b
.zorder
;
68 virtual ~CompoundPart();
71 class AnimatablePart
: public CompoundPart
{
74 AnimatablePart(Agent
*p
, unsigned int _id
, int _x
, int _y
, int _z
) : CompoundPart(p
, _id
, _x
, _y
, _z
) { frameno
= 0; }
77 bytestring_t animation
;
78 virtual void setPose(unsigned int p
) = 0;
79 virtual void setFrameNo(unsigned int f
) = 0;
80 unsigned int getFrameNo() { return frameno
; }
83 class SpritePart
: public AnimatablePart
{
85 shared_ptr
<creaturesImage
> origsprite
, sprite
;
86 unsigned int firstimg
, pose
, base
, spriteno
;
87 SpritePart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
93 unsigned char framerate
;
94 unsigned int framedelay
;
95 shared_ptr
<creaturesImage
> getSprite() { return sprite
; }
96 virtual void partRender(class Surface
*renderer
, int xoffset
, int yoffset
);
98 unsigned int getPose() { return pose
; }
99 unsigned int getBase() { return base
; }
100 unsigned int getCurrentSprite() { return spriteno
; }
101 unsigned int getFirstImg() { return firstimg
; }
102 unsigned int getWidth();
103 unsigned int getHeight();
104 void setFrameNo(unsigned int f
);
105 void setPose(unsigned int p
);
106 void setFramerate(unsigned char f
) { framerate
= f
; framedelay
= 0; }
107 void setBase(unsigned int b
);
108 void changeSprite(std::string spritefile
, unsigned int fimg
);
109 void tint(unsigned char r
, unsigned char g
, unsigned char b
, unsigned char rotation
, unsigned char swap
);
110 virtual bool isTransparent() { return is_transparent
; }
111 bool transparentAt(unsigned int x
, unsigned int y
);
113 virtual ~SpritePart();
116 class ButtonPart
: public SpritePart
{
118 bool hitopaquepixelsonly
;
120 bytestring_t hoveranimation
;
123 ButtonPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
124 unsigned int _z
, const bytestring_t
&animhover
, int msgid
, int option
);
125 int handleClick(float, float);
126 bool isTransparent() { return hitopaquepixelsonly
; }
129 class DullPart
: public SpritePart
{
131 DullPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
, unsigned int _z
);
136 unsigned int offset
, width
;
138 void reset(unsigned int o
) { offset
= o
; text
= ""; width
= 0; }
139 linedata() { reset(0); }
142 struct texttintinfo
{
143 shared_ptr
<creaturesImage
> sprite
;
147 enum horizontalalign
{ leftalign
, centeralign
, rightalign
};
148 enum verticalalign
{ top
, middle
, bottom
};
150 class TextPart
: public SpritePart
{
152 std::vector
<texttintinfo
> tints
;
153 std::vector
<linedata
> lines
;
154 std::vector
<unsigned int> pages
;
155 std::vector
<unsigned int> pageheights
;
156 unsigned int currpage
;
159 shared_ptr
<creaturesImage
> textsprite
;
161 int leftmargin
, topmargin
, rightmargin
, bottommargin
;
162 int linespacing
, charspacing
;
163 horizontalalign horz_align
;
164 verticalalign vert_align
;
165 bool last_page_scroll
;
167 TextPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
, unsigned int _z
, std::string fontsprite
);
169 void recalculateData();
170 unsigned int calculateWordWidth(std::string word
);
171 void addTint(std::string tintinfo
);
174 virtual void setText(std::string t
);
175 std::string
getText() { return text
; }
176 unsigned int noPages() { return pages
.size(); }
177 void setPage(unsigned int p
) { currpage
= p
; }
178 unsigned int getPage() { return currpage
; }
179 void partRender(class Surface
*renderer
, int xoffset
, int yoffset
, class TextEntryPart
*caretdata
);
180 void partRender(class Surface
*renderer
, int xoffset
, int yoffset
) { partRender(renderer
, xoffset
, yoffset
, 0); }
181 void setFormat(int left
, int top
, int right
, int bottom
, int line
, int _char
, horizontalalign horza
, verticalalign verta
, bool lastpagescroll
);
184 class FixedTextPart
: public TextPart
{
186 FixedTextPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
187 unsigned int _z
, std::string fontsprite
);
190 class GraphPart
: public SpritePart
{
192 GraphPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
193 unsigned int _z
, unsigned int novalues
);
196 class TextEntryPart
: public TextPart
{
198 static shared_ptr
<creaturesImage
> caretsprite
;
199 unsigned int caretpose
;
201 unsigned int caretpos
;
202 unsigned int messageid
;
203 void renderCaret(class Surface
*renderer
, int xoffset
, int yoffset
);
205 friend class TextPart
;
208 TextEntryPart(Agent
*p
, unsigned int _id
, std::string spritefile
, unsigned int fimg
, int _x
, int _y
,
209 unsigned int _z
, unsigned int msgid
, std::string fontsprite
);
210 void setText(std::string t
);
211 void gainFocus() { focused
= true; caretpose
= 0; }
212 void loseFocus() { focused
= false; }
213 int handleClick(float, float);
214 void handleKey(char c
);
215 void handleSpecialKey(char c
);
217 virtual void partRender(class Surface
*renderer
, int xoffset
, int yoffset
);
218 bool isTransparent() { return false; }