[go: up one dir, main page]

Menu

[12172e]: / src / ypaint.h  Maximize  Restore  History

Download this file

248 lines (205 with data), 6.9 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#ifndef __YPAINT_H
#define __YPAINT_H
#include <X11/X.h>
#define ICON_SMALL 16 // small: 16x16 //!!! fix this
#define ICON_LARGE 32 // large: 32x32
#define ICON_HUGE 48 // huge: 48x48
class YWindow;
// !!! remove these if possible
#ifndef __YIMP_XLIB__
typedef struct _XDisplay Display;
typedef struct _XGC *GC;
typedef union _XEvent XEvent;
struct XFontStruct;
#ifdef I18N
typedef struct _XOC *XFontSet;
#endif
struct XPoint;
struct XExposeEvent;
struct XGraphicsExposeEvent;
struct XConfigureEvent;
struct XKeyEvent;
struct XButtonEvent;
struct XMotionEvent;
struct XCrossingEvent;
struct XPropertyEvent;
struct XColormapEvent;
struct XFocusChangeEvent;
struct XClientMessageEvent;
struct XMapEvent;
struct XUnmapEvent;
struct XDestroyWindowEvent;
struct XConfigureRequestEvent;
struct XMapRequestEvent;
struct XSelectionEvent;
struct XSelectionClearEvent;
struct XSelectionRequestEvent;
#endif
#ifndef __YIMP_XUTIL__
#ifdef SHAPE
struct XTextProperty;
#endif
#endif
#ifdef SHAPE
struct XShapeEvent;
#endif
enum Direction {
Up, Left, Down, Right
};
class YColor {
public:
YColor(unsigned short red, unsigned short green, unsigned short blue);
YColor(unsigned long pixel);
YColor(const char *clr);
void alloc();
unsigned long pixel() const { return fPixel; }
YColor *darker();
YColor *brighter();
static YColor *black;
static YColor *white;
private:
unsigned long fPixel;
unsigned short fRed;
unsigned short fGreen;
unsigned short fBlue;
YColor *fDarker; //!!! remove this (needs color caching...)
YColor *fBrighter; //!!! removethis
};
struct YDimension {
YDimension(unsigned w, unsigned h): w(w), h(h) {}
unsigned w, h;
};
class YFont {
public:
static YFont *getFont(const char *name);
~YFont();
unsigned height() const { return fontAscent + fontDescent; }
unsigned descent() const { return fontDescent; }
unsigned ascent() const { return fontAscent; }
unsigned textWidth(const char *str) const;
unsigned textWidth(const char *str, int len) const;
unsigned multilineTabPos(const char *str) const;
YDimension multilineAlloc(const char *str) const;
private:
#ifdef I18N
XFontSet font_set;
#endif
XFontStruct *afont;
int fontAscent, fontDescent;
YFont(const char *name);
#ifdef I18N
void GetFontNameElement(const char *, char *, int, int);
XFontSet CreateFontSetWithGuess(Display *, const char *, char ***, int *, char **);
#endif
void alloc();
friend class Graphics;//!!!fix
};
class YPixmap {
public:
static Pixmap YPixmap::createPixmap(int w, int h);
static Pixmap YPixmap::createMask(int w, int h);
YPixmap(const char *fileName);
YPixmap(const char *fileName, int w, int h);
YPixmap(int w, int h, bool mask = false);
YPixmap(Pixmap pixmap, Pixmap mask, int w, int h);
#ifdef CONFIG_IMLIB
YPixmap(Pixmap pixmap, Pixmap mask, int w, int h, int wScaled, int hScaled);
#endif
~YPixmap();
Pixmap pixmap() const { return fPixmap; }
Pixmap mask() const { return fMask; }
unsigned int width() const { return fWidth; }
unsigned int height() const { return fHeight; }
void replicate(bool horiz, bool copyMask);
private:
Pixmap fPixmap;
Pixmap fMask;
unsigned int fWidth, fHeight;
bool fOwned;
};
class YIcon {
public:
YIcon(const char *fileName);
YIcon(YPixmap *small, YPixmap *large, YPixmap *huge);
~YIcon();
YPixmap *huge();
YPixmap *large();
YPixmap *small();
const char *iconName() const { return fPath; }
YIcon *next() const { return fNext; }
private:
char *fPath;
YPixmap *fSmall;
YPixmap *fLarge;
YPixmap *fHuge;
YIcon *fNext;
bool loadedS;
bool loadedL;
bool loadedH;
bool findIcon(char *base, char **fullPath, int size);
bool findIcon(char **fullPath, int size);
YPixmap *loadIcon(int size);
};
class Graphics {
public:
Graphics(YWindow *window);
Graphics(YPixmap *pixmap);
Graphics(Drawable drawable);
virtual ~Graphics();
void copyArea(const int x, const int y, const int width, const int height,
const int dx, const int dy);
void copyDrawable(const Drawable d, const int x, const int y,
const int w, const int h, const int dx, const int dy);
void copyPixmap(const YPixmap *p, const int x, const int y,
const int w, const int h, const int dx, const int dy) {
if (p) copyDrawable(p->pixmap(), x, y, w, h, dx, dy);
}
void drawPoint(int x, int y);
void drawLine(int x1, int y1, int x2, int y2);
void drawLines(XPoint *points, int n, int mode);
void drawRect(int x, int y, int width, int height);
void drawArc(int x, int y, int width, int height, int a1, int a2);
void drawArrow(Direction direction, int x, int y, int size, bool pressed = false);
void drawChars(const char *data, int offset, int len, int x, int y);
void drawCharUnderline(int x, int y, const char *str, int charPos);
void drawCharsEllipsis(const char *data, int len, int x, int y, int maxWidth);
void drawCharsMultiline(const char *str, int x, int y);
void drawPixmap(YPixmap *pix, int x, int y);
void drawMask(YPixmap *pix, int x, int y);
void drawClippedPixmap(Pixmap pix, Pixmap clip,
int x, int y, int w, int h, int toX, int toY);
void fillRect(int x, int y, int width, int height);
void fillPolygon(XPoint *points, int n, int shape, int mode);
void fillArc(int x, int y, int width, int height, int a1, int a2);
void setColor(YColor *aColor);
void setFont(YFont const *aFont);
void setPenStyle(bool dotLine = false); ///!!!hack
void draw3DRect(int x, int y, int w, int h, bool raised);
void drawBorderW(int x, int y, int w, int h, bool raised);
void drawBorderM(int x, int y, int w, int h, bool raised);
void drawBorderG(int x, int y, int w, int h, bool raised);
void drawCenteredPixmap(int x, int y, int w, int h, YPixmap *pixmap);
void drawOutline(int l, int t, int r, int b, int iw, int ih);
void repHorz(Drawable drawable, int pw, int ph, int x, int y, int w);
void repVert(Drawable drawable, int pw, int ph, int x, int y, int h);
void fillPixmap(YPixmap const * pixmap, int x, int y, int w, int h);
void repHorz(YPixmap const * p, int x, int y, int w) {
if (p) repHorz(p->pixmap(), p->width(), p->height(), x, y, w);
}
void repVert(YPixmap const * p, int x, int y, int h) {
if (p) repVert(p->pixmap(), p->width(), p->height(), x, y, h);
}
YColor *getColor() const { return color; }
YFont const *getFont() const { return font; }
GC handle() const { return gc; }
private:
Display *display;
Drawable drawable;
GC gc;
YColor *color;
YFont const *font;
};
extern Colormap defaultColormap; //!!!???
YIcon *getIcon(const char *name);
void freeIcons();
#endif