}
void
-DrawingContext::draw_line(const Vector& topleft, const Vector& botright,
- Color color, int layer)
-{
- DrawingRequest request;
-
- request.type = LINE;
- request.layer = layer;
- request.pos = transform.apply(topleft);
-
- LineRequest* linerequest = new LineRequest;
- linerequest->botright = botright;
- linerequest->color = color;
- request.request_data = linerequest;
-
- drawingrequests.push_back(request);
-}
-
-void
DrawingContext::draw_surface_part(DrawingRequest& request)
{
SurfacePartRequest* surfacepartrequest
delete fillrectrequest;
}
-/* Needed for line calculations */
-#define SGN(x) ((x)>0 ? 1 : ((x)==0 ? 0:(-1)))
-#define ABS(x) ((x)>0 ? (x) : (-x))
-
-void
-DrawingContext::draw_line(DrawingRequest& request)
-{
- LineRequest* linerequest = (LineRequest*) request.request_data;
-
- float x1 = request.pos.x;
- float y1 = request.pos.y;
- float x2 = linerequest->botright.x;
- float y2 = linerequest->botright.y;
- int r = linerequest->color.red;
- int g = linerequest->color.green;
- int b = linerequest->color.blue;
- int a = linerequest->color.alpha;
-
-#ifndef NOOPENGL
- if(use_gl)
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4ub(r, g, b,a);
-
- glBegin(GL_LINES);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
- glEnd();
- glDisable(GL_BLEND);
- }
- else
- {
-#endif
- /* Basic unantialiased Bresenham line algorithm */
- int lg_delta, sh_delta, cycle, lg_step, sh_step;
- Uint32 color = SDL_MapRGBA(screen->format, r, g, b, a);
-
- lg_delta = (int)(x2 - x1);
- sh_delta = (int)(y2 - y1);
- lg_step = SGN(lg_delta);
- lg_delta = ABS(lg_delta);
- sh_step = SGN(sh_delta);
- sh_delta = ABS(sh_delta);
- if (sh_delta < lg_delta)
- {
- cycle = lg_delta >> 1;
- while (x1 != x2)
- {
- drawpixel((int)x1, (int)y1, color);
- cycle += sh_delta;
- if (cycle > lg_delta)
- {
- cycle -= lg_delta;
- y1 += sh_step;
- }
- x1 += lg_step;
- }
- drawpixel((int)x1, (int)y1, color);
- }
- cycle = sh_delta >> 1;
- while (y1 != y2)
- {
- drawpixel((int)x1, (int)y1, color);
- cycle += lg_delta;
- if (cycle > sh_delta)
- {
- cycle -= sh_delta;
- x1 += lg_step;
- }
- y1 += sh_step;
- }
- drawpixel((int)x1, (int)y1, color);
-#ifndef NOOPENGL
-
- }
-#endif
-
- delete linerequest;
-}
-
void
DrawingContext::do_drawing()
{
case FILLRECT:
draw_filled_rect(*i);
break;
- case LINE:
- draw_line(*i);
- break;
}
}
/** fills a rectangle */
void draw_filled_rect(const Vector& topleft, const Vector& size,
Color color, int layer);
- /** draws an one-pixel line */
- void draw_line(const Vector& topleft, const Vector& downright,
- Color color, int layer);
/** Processes all pending drawing requests and flushes the list */
void do_drawing();
enum RequestType
{
- SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, LINE
+ SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
};
struct SurfacePartRequest
Vector size;
};
- struct LineRequest
- {
- Color color;
- Vector botright;
- };
-
struct DrawingRequest
{
int layer;
void draw_text(DrawingRequest& request);
void draw_gradient(DrawingRequest& request);
void draw_filled_rect(DrawingRequest& request);
- void draw_line(DrawingRequest& request);
typedef std::vector<DrawingRequest> DrawingRequests;
DrawingRequests drawingrequests;
#endif
}
+/* Needed for line calculations */
+#define SGN(x) ((x)>0 ? 1 : ((x)==0 ? 0:(-1)))
+#define ABS(x) ((x)>0 ? (x) : (-x))
+
+void
+draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a)
+{
+#ifndef NOOPENGL
+ if(use_gl)
+ {
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4ub(r, g, b,a);
+
+ glBegin(GL_LINES);
+ glVertex2f(x1, y1);
+ glVertex2f(x2, y2);
+ glEnd();
+ glDisable(GL_BLEND);
+ }
+ else
+ {
+#endif
+ /* Basic unantialiased Bresenham line algorithm */
+ int lg_delta, sh_delta, cycle, lg_step, sh_step;
+ Uint32 color = SDL_MapRGBA(screen->format, r, g, b, a);
+
+ lg_delta = (int)(x2 - x1);
+ sh_delta = (int)(y2 - y1);
+ lg_step = SGN(lg_delta);
+ lg_delta = ABS(lg_delta);
+ sh_step = SGN(sh_delta);
+ sh_delta = ABS(sh_delta);
+ if (sh_delta < lg_delta)
+ {
+ cycle = lg_delta >> 1;
+ while (x1 != x2)
+ {
+ drawpixel((int)x1, (int)y1, color);
+ cycle += sh_delta;
+ if (cycle > lg_delta)
+ {
+ cycle -= lg_delta;
+ y1 += sh_step;
+ }
+ x1 += lg_step;
+ }
+ drawpixel((int)x1, (int)y1, color);
+ }
+ cycle = sh_delta >> 1;
+ while (y1 != y2)
+ {
+ drawpixel((int)x1, (int)y1, color);
+ cycle += lg_delta;
+ if (cycle > sh_delta)
+ {
+ cycle -= sh_delta;
+ x1 += lg_step;
+ }
+ y1 += sh_step;
+ }
+ drawpixel((int)x1, (int)y1, color);
+#ifndef NOOPENGL
+
+ }
+#endif
+}
+
#define LOOP_DELAY 20.0
void fadeout(int fade_time)
{
public:
Color()
- : red(0), green(0), blue(0), alpha(0)
+ : red(0), green(0), blue(0), alpha(255)
{}
- Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 0)
+ Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 255)
: red(red_), green(green_), blue(blue_), alpha(alpha_)
{}
void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
void drawpixel(int x, int y, Uint32 pixel);
void fillrect(float x, float y, float w, float h, int r, int g, int b, int a = 255);
+void draw_line(float x1, float y1, float x2, int r, int g, int b, int a = 255);
void fadeout(int fade_time);
void shrink_fade(const Vector& point, int fade_time);