summaryrefslogtreecommitdiff
path: root/include/shape.h
blob: 23dfc15d56a1471ec0ee93add168b14a1b15e335 (plain)
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
/*
 *  mogltk
 *  Copyright (C) 1999-2004 Nicolas "Pixel" Noble
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: shape.h,v 1.19 2007-07-27 14:10:19 pixel Exp $ */

#ifndef __SHAPE_H__
#define __SHAPE_H__

#include <vector>
#include <Exceptions.h>
#include <BString.h>
#include <mcolor.h>
#include <texture.h>
#include <font.h>

namespace mogltk {
    typedef enum {
	LEFT,
	CENTER,
	RIGHT
    } align_t;
    class fillwalker : public Base {
      public:
          fillwalker();
	  virtual ~fillwalker();
        virtual void step(int x, int y);
    };
    class segwalker : public Base {
      public:
          segwalker();
	  virtual ~segwalker();
	virtual void step(int x1, int y1, int x2, int y2);
    };
    class Fill : public Base {
      public:
          Fill();
	  virtual ~Fill();
	void walk(fillwalker *);
	void swalk(segwalker *);
	void insert(int, int, int, int);
	void insertfix(int, int);
	int GetMinX() const;
	int GetMinY() const;
	int GetMaxX() const;
	int GetMaxY() const;
	Texture * GetTexture();
	Texture * Talloc();
	Texture * GetSTexture();
	Texture * STalloc();
	Color last;
      private:
	void insert(int, int);
	struct segment {
	    int x1, y1, x2, y2;
	};
        class sline : public Base {
	  public:
	      sline(int, Fill *);
	      virtual ~sline();
	    int GetY() const;
	    void insert(int, int);
	    void insertfix(int, int);
	    void walk(fillwalker *);
	  private:
    	    class point : public Base {
	      public:
	          point(int, sline *);
		  virtual ~point();
		int GetX() const;
		int GetY() const;
		void walk(fillwalker *);
		point * look(int);
	      private:
	        int x;
		point * next;
		sline * header;
	    };
	    int y;
	    sline * next;
	    Fill * header;
	    sline * look(int);
	  protected:
	    point * pheader;
	    friend class point;
	  private:
	    int count() const;
	};
	int minX, minY, maxX, maxY;
	Texture * cached;
	Texture * scached;
	std::vector<segment> segments;
      protected:
        sline * header;
        friend class sline;
    };
    class Shape : public Base {
      public:
          Shape(SDL_Surface * = 0);
        virtual void pixel(int x, int y, ColorP = WHITE);
	virtual void circle(int x, int y, int r, ColorP = WHITE);
	virtual void pcircle(int x, int y, int r, ColorP = WHITE);
	virtual Fill * fcircle(int x, int y, int r);
	virtual void fdraw(Fill *, ColorP = WHITE, int sx = 0, int sy = 0);
	virtual void sdraw(Fill *, ColorP = WHITE, int sx = 0, int sy = 0);
        virtual void box(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE);
        virtual void box3d(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, int = 2, bool = false);
        virtual void box(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP);
        virtual void obox(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE);
        virtual void obox3d(int x1, int y1, int x2, int y2, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
        virtual void obox(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP);
	virtual void hline(int x1, int x2, int y, ColorP = DOS_WHITE);
	virtual void hline3d(int x1, int x2, int y, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
	virtual void hline(int x1, int x2, int y, ColorP, ColorP);
	virtual void vline(int x, int y1, int y2, ColorP = DOS_WHITE);
	virtual void vline3d(int x, int y1, int y2, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false);
	virtual void vline(int x, int y1, int y2, ColorP, ColorP);
	virtual void line(int x1, int y1, int x2, int y2, ColorP = WHITE);
        virtual void tbox(Texture *, int x1, int y1, int x2, int y2, int tx = 0, int ty = 0, double = 1.0, ColorP = WHITE);
        virtual void tbox(Texture *, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP = WHITE);
        virtual void tbox(Texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx = 0, int ty = 0, double = 1.0);
        virtual void tbox(Texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx1, int ty1, int tx2, int ty2);
	virtual void window(int x1, int y1, int x2, int y2,
			    const String & title = "",
	                    ColorP titlecolor = DOS_HIGH_WHITE, 
			    ColorP titlebackcolor = DOS_MAGENTA, 
			    ColorP front = DOS_WHITE, 
			    ColorP shade1 = DOS_HIGH_WHITE,
			    ColorP shade2 = DOS_GRAY);
	virtual void text(int x, int y, const String &,
			    ColorP textcolor = DOS_HIGH_WHITE,
                            align_t align = LEFT, mogltk::Font * = mogltk::SystemFont);
	virtual void text3d(int x, int y, const String &,
			    ColorP textcolor = DOS_BLACK,
			    ColorP shade1 = DOS_HIGH_WHITE,
			    ColorP shade2 = DOS_GRAY,
			    align_t align = LEFT,
			    bool bevel = false, mogltk::Font * = mogltk::SystemFont);
	virtual void button(int x1, int y1, int x2, int y2, const String &,
			    bool bevel = false,
			    ColorP front = DOS_WHITE,
			    ColorP shade1 = DOS_HIGH_WHITE,
			    ColorP shade2 = DOS_GRAY,
			    ColorP round = DOS_BLACK,
			    ColorP textcolor = DOS_BLACK,
			    ColorP tshade1 = DOS_HIGH_WHITE,
			    ColorP tshade2 = DOS_GRAY);
	SDL_Surface * GetSurf();
      private:
        void bsubline_1(int x1, int y1, int x2, int y2, ColorP = WHITE);
        void bsubline_2(int x1, int y1, int x2, int y2, ColorP = WHITE);
        void bsubline_3(int x1, int y1, int x2, int y2, ColorP = WHITE);
        void bsubline_4(int x1, int y1, int x2, int y2, ColorP = WHITE);
        virtual bool Enter();
	virtual void Leave(bool);
	SDL_Surface * surf;
    };

    class filldrawer : public fillwalker {
      public:
          filldrawer(Fill *, Texture *, ColorP = DOS_WHITE);
          virtual ~filldrawer();
        virtual void step(int x, int y);
      private:
	Fill * f;
        Texture * t;
        ColorP c;
        int oldx, oldy;
    };
    class segdrawer : public segwalker {
      public:
          segdrawer(Fill *, Texture *, ColorP = DOS_WHITE);
          virtual ~segdrawer();
        virtual void step(int x1, int y1, int x2, int y2);
      private:
	Fill * f;
        Texture * t;
        ColorP c;
	Shape * sh;
    };
};

#endif