#include <cassert>
#include <iostream>
-#include "drawing_context.h"
-#include "surface.h"
-#include "font.h"
-#include "main.h"
-#include "gameconfig.h"
+#include "drawing_context.hpp"
+#include "surface.hpp"
+#include "font.hpp"
+#include "main.hpp"
+#include "gameconfig.hpp"
DrawingContext::DrawingContext(SDL_Surface* targetsurface)
{
void
DrawingContext::draw_surface(const Surface* surface, const Vector& position,
- int layer, uint32_t drawing_effect)
+ int layer)
{
assert(surface != 0);
return;
request.layer = layer;
- request.drawing_effect = transform.drawing_effect | drawing_effect;
+ request.drawing_effect = transform.drawing_effect;
request.zoom = transform.zoom;
request.alpha = transform.alpha;
request.request_data = const_cast<Surface*> (surface);
void
DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
- const Vector& size, const Vector& dest, int layer, uint32_t drawing_effect)
+ const Vector& size, const Vector& dest, int layer)
{
assert(surface != 0);
request.type = SURFACE_PART;
request.pos = transform.apply(dest);
request.layer = layer;
- request.drawing_effect = transform.drawing_effect | drawing_effect;
+ request.drawing_effect = transform.drawing_effect;
request.alpha = transform.alpha;
SurfacePartRequest* surfacepartrequest = new SurfacePartRequest();
void
DrawingContext::draw_text(const Font* font, const std::string& text,
- const Vector& position, FontAlignment alignment, int layer,
- uint32_t drawing_effect)
+ const Vector& position, FontAlignment alignment, int layer)
{
DrawingRequest request;
request.type = TEXT;
request.pos = transform.apply(position);
request.layer = layer;
- request.drawing_effect = transform.drawing_effect | drawing_effect;
+ request.drawing_effect = transform.drawing_effect;
request.zoom = transform.zoom;
request.alpha = transform.alpha;
void
DrawingContext::draw_center_text(const Font* font, const std::string& text,
- const Vector& position, int layer, uint32_t drawing_effect)
+ const Vector& position, int layer)
{
draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
- CENTER_ALLIGN, layer, drawing_effect);
+ CENTER_ALLIGN, layer);
}
void
FillRectRequest* fillrectrequest = new FillRectRequest;
fillrectrequest->size = size;
fillrectrequest->color = color;
+ fillrectrequest->color.alpha
+ = (int) ((float) fillrectrequest->color.alpha
+ * ((float) transform.alpha / 255.0));
request.request_data = fillrectrequest;
drawingrequests.push_back(request);
const Color& top = gradientrequest->top;
const Color& bottom = gradientrequest->bottom;
-#ifndef NOOPENGL
- if(config->use_gl)
- {
- glBegin(GL_QUADS);
- glColor3ub(top.red, top.green, top.blue);
- glVertex2f(0, 0);
- glVertex2f(SCREEN_WIDTH, 0);
- glColor3ub(bottom.red, bottom.green, bottom.blue);
- glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
- glVertex2f(0, SCREEN_HEIGHT);
- glEnd();
- }
- else
- {
-#endif
- if(&top == &bottom)
- {
- fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, top.red, top.green, top.blue);
- }
- else
- {
- float redstep = (float(bottom.red)-float(top.red)) / float(SCREEN_HEIGHT);
- float greenstep = (float(bottom.green)-float(top.green)) / float(SCREEN_HEIGHT);
- float bluestep = (float(bottom.blue) - float(top.blue)) / float(SCREEN_HEIGHT);
-
- for(float y = 0; y < SCREEN_HEIGHT; y += 2)
- fillrect(0, (int)y, SCREEN_WIDTH, 2,
- int(float(top.red) + redstep * y),
- int(float(top.green) + greenstep * y),
- int(float(top.blue) + bluestep * y), 255);
- }
-#ifndef NOOPENGL
-
- }
-#endif
+ glBegin(GL_QUADS);
+ glColor3ub(top.red, top.green, top.blue);
+ glVertex2f(0, 0);
+ glVertex2f(SCREEN_WIDTH, 0);
+ glColor3ub(bottom.red, bottom.green, bottom.blue);
+ glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
+ glVertex2f(0, SCREEN_HEIGHT);
+ glEnd();
delete gradientrequest;
}
float w = fillrectrequest->size.x;
float h = fillrectrequest->size.y;
-#ifndef NOOPENGL
- if(config->use_gl)
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4ub(fillrectrequest->color.red, fillrectrequest->color.green,
- fillrectrequest->color.blue, fillrectrequest->color.alpha);
-
- glBegin(GL_POLYGON);
- glVertex2f(x, y);
- glVertex2f(x+w, y);
- glVertex2f(x+w, y+h);
- glVertex2f(x, y+h);
- glEnd();
- glDisable(GL_BLEND);
- }
- else
- {
-#endif
- SDL_Rect src, rect;
- SDL_Surface *temp = NULL;
-
- rect.x = (int)x;
- rect.y = (int)y;
- rect.w = (int)w;
- rect.h = (int)h;
-
- if(fillrectrequest->color.alpha != 255)
- {
- temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel,
- screen->format->Rmask,
- screen->format->Gmask,
- screen->format->Bmask,
- screen->format->Amask);
-
-
- src.x = 0;
- src.y = 0;
- src.w = rect.w;
- src.h = rect.h;
-
- SDL_FillRect(temp, &src, SDL_MapRGB(screen->format,
- fillrectrequest->color.red, fillrectrequest->color.green,
- fillrectrequest->color.blue));
-
- SDL_SetAlpha(temp, SDL_SRCALPHA, fillrectrequest->color.alpha);
-
- SDL_BlitSurface(temp,0,screen,&rect);
-
- SDL_FreeSurface(temp);
- }
- else
- SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,
- fillrectrequest->color.red, fillrectrequest->color.green,
- fillrectrequest->color.blue));
-
-#ifndef NOOPENGL
-
- }
-#endif
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4ub(fillrectrequest->color.red, fillrectrequest->color.green,
+ fillrectrequest->color.blue, fillrectrequest->color.alpha);
+
+ glBegin(GL_POLYGON);
+ glVertex2f(x, y);
+ glVertex2f(x+w, y);
+ glVertex2f(x+w, y+h);
+ glVertex2f(x, y+h);
+ glEnd();
+ glDisable(GL_BLEND);
delete fillrectrequest;
}
}
}
- // update screen
- if(config->use_gl)
- SDL_GL_SwapBuffers();
- else
- SDL_Flip(screen);
-
drawingrequests.clear();
+
+ // update screen
+ SDL_GL_SwapBuffers();
}
void
}
void
-DrawingContext::set_drawing_effect(int effect)
+DrawingContext::set_drawing_effect(uint32_t effect)
{
transform.drawing_effect = effect;
}
+uint32_t
+DrawingContext::get_drawing_effect() const
+{
+ return transform.drawing_effect;
+}
+
void
DrawingContext::set_zooming(float zoom)
{
}
void
-DrawingContext::set_alpha(int alpha)
+DrawingContext::set_alpha(uint8_t alpha)
{
transform.alpha = alpha;
}
+
+uint8_t
+DrawingContext::get_alpha() const
+{
+ return transform.alpha;
+}