projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'feature/c++11'
[supertux.git]
/
src
/
video
/
drawing_context.cpp
diff --git
a/src/video/drawing_context.cpp
b/src/video/drawing_context.cpp
index
5a31e4d
..
96d06ab
100644
(file)
--- a/
src/video/drawing_context.cpp
+++ b/
src/video/drawing_context.cpp
@@
-14,11
+14,12
@@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include "video/drawing_context.hpp"
+
#include <algorithm>
#include <config.h>
#include <algorithm>
#include <config.h>
-#include "video/drawing_context.hpp"
-
+#include "math/sizef.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "util/obstackpp.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "util/obstackpp.hpp"
@@
-30,18
+31,9
@@
#include "video/texture_manager.hpp"
#include "video/video_systems.hpp"
#include "video/texture_manager.hpp"
#include "video/video_systems.hpp"
-static inline int next_po2(int val)
-{
- int result = 1;
- while(result < val)
- result *= 2;
-
- return result;
-}
-
-DrawingContext::DrawingContext() :
- renderer(0),
- lightmap(0),
+DrawingContext::DrawingContext(Renderer& renderer, Lightmap& lightmap) :
+ renderer(renderer),
+ lightmap(lightmap),
transformstack(),
transform(),
blend_stack(),
transformstack(),
transform(),
blend_stack(),
@@
-61,23
+53,10
@@
DrawingContext::DrawingContext() :
DrawingContext::~DrawingContext()
{
DrawingContext::~DrawingContext()
{
- delete renderer;
- delete lightmap;
-
obstack_free(&obst, NULL);
}
void
obstack_free(&obst, NULL);
}
void
-DrawingContext::init_renderer()
-{
- delete renderer;
- delete lightmap;
-
- renderer = VideoSystem::new_renderer();
- lightmap = VideoSystem::new_lightmap();
-}
-
-void
DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
float angle, const Color& color, const Blend& blend,
int layer)
DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
float angle, const Color& color, const Blend& blend,
int layer)
@@
-155,7
+134,7
@@
DrawingContext::draw_surface_part(SurfacePtr surface, const Vector& source,
}
void
}
void
-DrawingContext::draw_text(
const Font*
font, const std::string& text,
+DrawingContext::draw_text(
FontPtr
font, const std::string& text,
const Vector& position, FontAlignment alignment, int layer, Color color)
{
DrawingRequest* request = new(obst) DrawingRequest();
const Vector& position, FontAlignment alignment, int layer, Color color)
{
DrawingRequest* request = new(obst) DrawingRequest();
@@
-169,7
+148,7
@@
DrawingContext::draw_text(const Font* font, const std::string& text,
request->color = color;
TextRequest* textrequest = new(obst) TextRequest();
request->color = color;
TextRequest* textrequest = new(obst) TextRequest();
- textrequest->font = font;
+ textrequest->font = font
.get()
;
textrequest->text = text;
textrequest->alignment = alignment;
request->request_data = textrequest;
textrequest->text = text;
textrequest->alignment = alignment;
request->request_data = textrequest;
@@
-178,7
+157,7
@@
DrawingContext::draw_text(const Font* font, const std::string& text,
}
void
}
void
-DrawingContext::draw_center_text(
const Font*
font, const std::string& text,
+DrawingContext::draw_center_text(
FontPtr
font, const std::string& text,
const Vector& position, int layer, Color color)
{
draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
const Vector& position, int layer, Color color)
{
draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
@@
-283,6
+262,14
@@
DrawingContext::draw_inverse_ellipse(const Vector& pos, const Vector& size, cons
requests->push_back(request);
}
requests->push_back(request);
}
+Rectf
+DrawingContext::get_cliprect() const
+{
+ return Rectf(get_translation().x, get_translation().y,
+ get_translation().x + SCREEN_WIDTH,
+ get_translation().y + SCREEN_HEIGHT);
+}
+
void
DrawingContext::get_light(const Vector& position, Color* color)
{
void
DrawingContext::get_light(const Vector& position, Color* color)
{
@@
-325,9
+312,9
@@
DrawingContext::do_drawing()
// PART1: create lightmap
if(use_lightmap) {
// PART1: create lightmap
if(use_lightmap) {
- lightmap
->
start_draw(ambient_color);
+ lightmap
.
start_draw(ambient_color);
handle_drawing_requests(lightmap_requests);
handle_drawing_requests(lightmap_requests);
- lightmap
->
end_draw();
+ lightmap
.
end_draw();
DrawingRequest* request = new(obst) DrawingRequest();
request->target = NORMAL;
DrawingRequest* request = new(obst) DrawingRequest();
request->target = NORMAL;
@@
-344,11
+331,11
@@
DrawingContext::do_drawing()
// if a screenshot was requested, take one
if (screenshot_requested) {
// if a screenshot was requested, take one
if (screenshot_requested) {
- renderer
->
do_take_screenshot();
+ renderer
.
do_take_screenshot();
screenshot_requested = false;
}
screenshot_requested = false;
}
- renderer
->
flip();
+ renderer
.
flip();
}
class RequestPtrCompare
}
class RequestPtrCompare
@@
-373,64
+360,64
@@
DrawingContext::handle_drawing_requests(DrawingRequests& requests)
case NORMAL:
switch(request.type) {
case SURFACE:
case NORMAL:
switch(request.type) {
case SURFACE:
- renderer
->
draw_surface(request);
+ renderer
.
draw_surface(request);
break;
case SURFACE_PART:
break;
case SURFACE_PART:
- renderer
->
draw_surface_part(request);
+ renderer
.
draw_surface_part(request);
break;
case GRADIENT:
break;
case GRADIENT:
- renderer
->
draw_gradient(request);
+ renderer
.
draw_gradient(request);
break;
case TEXT:
{
const TextRequest* textrequest = (TextRequest*) request.request_data;
break;
case TEXT:
{
const TextRequest* textrequest = (TextRequest*) request.request_data;
- textrequest->font->draw(renderer, textrequest->text, request.pos,
+ textrequest->font->draw(
&
renderer, textrequest->text, request.pos,
textrequest->alignment, request.drawing_effect, request.color, request.alpha);
}
break;
case FILLRECT:
textrequest->alignment, request.drawing_effect, request.color, request.alpha);
}
break;
case FILLRECT:
- renderer
->
draw_filled_rect(request);
+ renderer
.
draw_filled_rect(request);
break;
case INVERSEELLIPSE:
break;
case INVERSEELLIPSE:
- renderer
->
draw_inverse_ellipse(request);
+ renderer
.
draw_inverse_ellipse(request);
break;
case DRAW_LIGHTMAP:
break;
case DRAW_LIGHTMAP:
- lightmap
->
do_draw();
+ lightmap
.
do_draw();
break;
case GETLIGHT:
break;
case GETLIGHT:
- lightmap
->
get_light(request);
+ lightmap
.
get_light(request);
break;
}
break;
case LIGHTMAP:
switch(request.type) {
case SURFACE:
break;
}
break;
case LIGHTMAP:
switch(request.type) {
case SURFACE:
- lightmap
->
draw_surface(request);
+ lightmap
.
draw_surface(request);
break;
case SURFACE_PART:
break;
case SURFACE_PART:
- lightmap
->
draw_surface_part(request);
+ lightmap
.
draw_surface_part(request);
break;
case GRADIENT:
break;
case GRADIENT:
- lightmap
->
draw_gradient(request);
+ lightmap
.
draw_gradient(request);
break;
case TEXT:
{
const TextRequest* textrequest = (TextRequest*) request.request_data;
break;
case TEXT:
{
const TextRequest* textrequest = (TextRequest*) request.request_data;
- textrequest->font->draw(renderer, textrequest->text, request.pos,
+ textrequest->font->draw(
&
renderer, textrequest->text, request.pos,
textrequest->alignment, request.drawing_effect, request.color, request.alpha);
}
break;
case FILLRECT:
textrequest->alignment, request.drawing_effect, request.color, request.alpha);
}
break;
case FILLRECT:
- lightmap
->
draw_filled_rect(request);
+ lightmap
.
draw_filled_rect(request);
break;
case INVERSEELLIPSE:
assert(!"InverseEllipse doesn't make sense on the lightmap");
break;
case DRAW_LIGHTMAP:
break;
case INVERSEELLIPSE:
assert(!"InverseEllipse doesn't make sense on the lightmap");
break;
case DRAW_LIGHTMAP:
- lightmap
->
do_draw();
+ lightmap
.
do_draw();
break;
case GETLIGHT:
break;
case GETLIGHT:
- lightmap
->
get_light(request);
+ lightmap
.
get_light(request);
break;
}
break;
break;
}
break;