ccdevnet / openc2e

openc2e

This URL has Read+Write access

openc2e / CompoundPart.h
100644 166 lines (142 sloc) 5.62 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* CompoundAgent.h
* openc2e
*
* Created by Alyssa Milburn on Tue May 25 2004.
* Copyright (c) 2004 Alyssa Milburn. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
 
#ifndef _COMPOUNDPART_H
#define _COMPOUNDPART_H
 
#include "openc2e.h"
#include "creaturesImage.h"
#include <map>
#include <string>
#include <vector>
 
class CompoundAgent;
 
class CompoundPart {
protected:
creaturesImage *origsprite, *sprite;
unsigned int firstimg, pose, frameno, base;
CompoundAgent *parent;
CompoundPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y,
unsigned int _z);
 
public:
std::vector<unsigned int> animation;
bool is_transparent;
unsigned char framerate;
unsigned int framedelay;
unsigned char transparency;
creaturesImage *getSprite() { return sprite; }
int x, y;
unsigned int zorder, id;
virtual void render(class SDLBackend *renderer, int xoffset, int yoffset);
virtual void tick();
unsigned int getWidth() { return sprite->width(firstimg); }
unsigned int getHeight() { return sprite->height(firstimg); }
unsigned int getPose() { return pose; }
unsigned int getBase() { return base; }
unsigned int getCurrentSprite() { return firstimg + base + pose; }
unsigned int getFrameNo() { return frameno; }
unsigned int getFirstImg() { return firstimg; }
void setFrameNo(unsigned int f) { frameno = f; pose = animation[f]; } // todo: assert it's in the range
void setPose(unsigned int p) { animation.clear(); pose = p; }
void setFramerate(unsigned char f) { framerate = f; framedelay = 0; }
void setBase(unsigned int b) { base = b; }
void tint(unsigned char r, unsigned char g, unsigned char b, unsigned char rotation, unsigned char swap);
 
bool operator < (const CompoundPart &b) const {
return zorder < b.zorder;
}
 
virtual ~CompoundPart();
};
 
class ButtonPart : public CompoundPart {
protected:
bool hitopaquepixelsonly;
int messageid;
bytestring hoveranimation;
 
friend class CompoundAgent;
 
public:
ButtonPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y,
unsigned int _z, const bytestring &animhover, int msgid, int option);
};
 
class CameraPart : public CompoundPart {
public:
CameraPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y,
unsigned int _z, unsigned int viewwidth, unsigned int viewheight,
unsigned int camerawidth, unsigned int cameraheight);
};
 
class DullPart : public CompoundPart {
public:
DullPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y, unsigned int _z);
};
 
struct linedata {
std::string text;
unsigned int width;
 
void reset() { text = ""; width = 0; }
linedata() { reset(); }
};
 
class TextPart : public CompoundPart {
protected:
std::vector<linedata> lines;
std::vector<unsigned int> pages;
unsigned int currpage;
std::string text;
creaturesImage *textsprite;
int leftmargin, topmargin, rightmargin, bottommargin;
int linespacing, charspacing;
bool left_align, center_align, bottom_align, middle_align, last_page_scroll;
TextPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y, unsigned int _z, std::string fontsprite);
~TextPart();
void recalculateData();
unsigned int calculateWordWidth(std::string word);
 
public:
virtual void setText(std::string t);
std::string getText() { return text; }
unsigned int noPages() { return pages.size(); }
void setPage(unsigned int p) { currpage = p; }
unsigned int getPage() { return currpage; }
void render(class SDLBackend *renderer, int xoffset, int yoffset, class TextEntryPart *caretdata);
void render(class SDLBackend *renderer, int xoffset, int yoffset) { render(renderer, xoffset, yoffset, 0); }
void setFormat(int left, int top, int right, int bottom, int line, int _char, bool lefta, bool centera, bool bottoma, bool middlea, bool lastpagescroll);
};
 
class FixedTextPart : public TextPart {
public:
FixedTextPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y,
unsigned int _z, std::string fontsprite);
};
 
class GraphPart : public CompoundPart {
public:
GraphPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y,
unsigned int _z, unsigned int novalues);
};
 
class TextEntryPart : public TextPart {
private:
static creaturesImage *caretsprite;
unsigned int caretpose;
bool focused;
unsigned int caretline, caretchar;
unsigned int messageid;
void renderCaret(class SDLBackend *renderer, int xoffset, int yoffset);
 
friend class TextPart;
 
public:
TextEntryPart(CompoundAgent *p, unsigned int _id, std::string spritefile, unsigned int fimg, int _x, int _y,
unsigned int _z, unsigned int msgid, std::string fontsprite);
void setText(std::string t);
void gainFocus() { focused = true; caretpose = 0; }
void loseFocus() { focused = false; }
void handleKey(char c);
void tick();
virtual void render(class SDLBackend *renderer, int xoffset, int yoffset);
};
 
#endif
 
/* vim: set noet: */