don't include OpenALBackend.h in qtgui/qtopenc2e.cpp
[openc2e.git] / CompoundPart.h
blob99e1cdf7252fe0a73d0b8200f65f65481bf678de
1 /*
2 * CompoundPart.h
3 * openc2e
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
23 #include "openc2e.h"
24 #include "renderable.h"
25 #include <map>
26 #include <string>
27 #include <vector>
29 class Agent;
30 class creaturesImage;
32 struct partzorder {
33 bool operator()(const class CompoundPart *s1, const class CompoundPart *s2) const;
36 class CompoundPart : public renderable {
37 protected:
38 std::multiset<CompoundPart *, partzorder>::iterator zorder_iter;
39 Agent *parent;
41 CompoundPart(Agent *p, unsigned int _id, int _x, int _y, int _z);
43 public:
44 int x, y;
45 unsigned int zorder, id;
47 bool has_alpha;
48 unsigned char alpha;
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 void 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;
61 void zapZOrder();
62 void addZOrder();
64 bool operator < (const CompoundPart &b) const {
65 return zorder < b.zorder;
68 virtual ~CompoundPart();
71 class AnimatablePart : public CompoundPart {
72 protected:
73 unsigned int frameno;
74 AnimatablePart(Agent *p, unsigned int _id, int _x, int _y, int _z) : CompoundPart(p, _id, _x, _y, _z) { frameno = 0; }
76 public:
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 {
84 protected:
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,
88 unsigned int _z);
90 public:
91 bool is_transparent;
92 bool draw_mirrored;
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);
97 virtual void tick();
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 {
117 protected:
118 bool hitopaquepixelsonly;
119 int messageid;
120 bytestring_t hoveranimation;
122 public:
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 void handleClick(float, float);
126 bool isTransparent() { return hitopaquepixelsonly; }
129 class DullPart : public SpritePart {
130 public:
131 DullPart(Agent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y, unsigned int _z);
134 struct linedata {
135 std::string text;
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;
144 unsigned int offset;
147 enum horizontalalign { leftalign, centeralign, rightalign };
148 enum verticalalign { top, middle, bottom };
150 class TextPart : public SpritePart {
151 protected:
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;
157 std::string text;
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);
168 ~TextPart();
169 void recalculateData();
170 unsigned int calculateWordWidth(std::string word);
171 void addTint(std::string tintinfo);
173 public:
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 {
185 public:
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 {
191 public:
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 {
197 private:
198 static shared_ptr<creaturesImage> caretsprite;
199 unsigned int caretpose;
200 bool focused;
201 unsigned int caretpos;
202 unsigned int messageid;
203 void renderCaret(class Surface *renderer, int xoffset, int yoffset);
205 friend class TextPart;
207 public:
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 void handleClick(float, float);
214 void handleKey(char c);
215 void handleSpecialKey(char c);
216 void tick();
217 virtual void partRender(class Surface *renderer, int xoffset, int yoffset);
218 bool isTransparent() { return false; }
221 #endif
223 /* vim: set noet: */