From 7bf4af4eccbafdef7685166227cea5a728a5b9a6 Mon Sep 17 00:00:00 2001 From: Kieran Millar Date: Mon, 20 Nov 2017 13:11:19 +0000 Subject: [PATCH] More drawing functions out of editor and into canvas --- src/Editor/canvas.cpp | 59 +++++++++++++++++++++++++++++++++++++++---- src/Editor/canvas.hpp | 5 ++++ src/Editor/editor.cpp | 49 ----------------------------------- src/Editor/editor.hpp | 5 ---- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/Editor/canvas.cpp b/src/Editor/canvas.cpp index a44b10b..1d21a42 100644 --- a/src/Editor/canvas.cpp +++ b/src/Editor/canvas.cpp @@ -81,7 +81,7 @@ void Canvas::draw() { Level::Object &o = level_ptr->object[i->type][i->i]; int so = style_ptr->object_by_id(i->type, o.id); - editor_ptr->draw_selection_box((o.x - scroll_x)*zoom, (o.y - scroll_y)*zoom, style_ptr->object[i->type][so].width * 8 * zoom, style_ptr->object[i->type][so].height * 2 * zoom); + draw_selection_box((o.x - scroll_x)*zoom, (o.y - scroll_y)*zoom, style_ptr->object[i->type][so].width * 8 * zoom, style_ptr->object[i->type][so].height * 2 * zoom); } SDL_SetRenderDrawColor(window_ptr->screen_renderer, 0, 0, 0, 255); @@ -89,19 +89,19 @@ void Canvas::draw() //Draw dotted lines on the level border if (scroll_x < 0 && (scroll_x * zoom) + window_ptr->width > 0) { - editor_ptr->draw_dashed_level_border(Editor::vertical, ((0 - scroll_x) * zoom) - 1, scroll_y * zoom); + draw_dashed_level_border(vertical, ((0 - scroll_x) * zoom) - 1, scroll_y * zoom); } if (scroll_x < level_ptr->width && scroll_x + (window_ptr->width / zoom) > level_ptr->width) { - editor_ptr->draw_dashed_level_border(Editor::vertical, ((level_ptr->width - scroll_x) * zoom), scroll_y * zoom); + draw_dashed_level_border(vertical, ((level_ptr->width - scroll_x) * zoom), scroll_y * zoom); } if (scroll_y < 0 && (scroll_y * zoom) + window_ptr->height > 0) { - editor_ptr->draw_dashed_level_border(Editor::horizontal, ((0 - scroll_y) * zoom) - 1, scroll_x * zoom); + draw_dashed_level_border(horizontal, ((0 - scroll_y) * zoom) - 1, scroll_x * zoom); } if (scroll_y < level_ptr->height && scroll_y + (window_ptr->height / zoom) > level_ptr->height) { - editor_ptr->draw_dashed_level_border(Editor::horizontal, ((level_ptr->height - scroll_y) * zoom), scroll_x * zoom); + draw_dashed_level_border(horizontal, ((level_ptr->height - scroll_y) * zoom), scroll_x * zoom); } SDL_SetRenderTarget(window_ptr->screen_renderer, NULL); @@ -117,4 +117,53 @@ void Canvas::draw() SDL_RenderPresent(window_ptr->screen_renderer); +} + +void Canvas::draw_selection_box(int x, int y, int width, int height) +{ + if (x > window_ptr->width || y > (window_ptr->height - BAR_HEIGHT) || (x + width) < 0 || (x + height) < 0) + return; + SDL_SetRenderDrawColor(window_ptr->screen_renderer, 255, 0, 255, 255 / 8); + SDL_Rect r; + r.x = x - 1; + r.y = y - 1; + r.w = width + 1; + r.h = height + 1; + SDL_RenderFillRect(window_ptr->screen_renderer, &r); + SDL_SetRenderDrawColor(window_ptr->screen_renderer, 255, 0, 255, 255); + SDL_RenderDrawRect(window_ptr->screen_renderer, &r); +} + +void Canvas::draw_dashed_level_border(borderType type, int pos, int offset) +{ + //We have an offset so the lines don't scroll out of synch with the view when scrolling + int initialOffset = offset % 20; + SDL_SetRenderDrawColor(window_ptr->screen_renderer, 200, 200, 200, 255); + int end, x1, y1, x2, y2; + if (type == horizontal) + { + end = window_ptr->width; + x1 = 0 - initialOffset; + x2 = 10 - initialOffset; + y1 = pos; + y2 = pos; + for (x1; x1 < end; x1 += 20) + { + SDL_RenderDrawLine(window_ptr->screen_renderer, x1, y1, x2, y2); + x2 += 20; + } + } + if (type == vertical) + { + end = window_ptr->height; + x1 = pos; + x2 = pos; + y1 = 0 - initialOffset; + y2 = 10 - initialOffset; + for (y1; y1 < end; y1 += 20) + { + SDL_RenderDrawLine(window_ptr->screen_renderer, x1, y1, x2, y2); + y2 += 20; + } + } } \ No newline at end of file diff --git a/src/Editor/canvas.hpp b/src/Editor/canvas.hpp index 6fd5d1b..7c25eec 100644 --- a/src/Editor/canvas.hpp +++ b/src/Editor/canvas.hpp @@ -54,6 +54,11 @@ class Canvas void draw(void); + void draw_selection_box(int x, int y, int width, int height); + + enum borderType { horizontal, vertical }; + void draw_dashed_level_border(borderType type, int pos, int offset); + Canvas(void) { /* nothing to do */ } }; diff --git a/src/Editor/editor.cpp b/src/Editor/editor.cpp index c6dc347..9dccb76 100644 --- a/src/Editor/editor.cpp +++ b/src/Editor/editor.cpp @@ -236,53 +236,4 @@ bool Editor::scroll( signed int delta_x, signed int delta_y, bool drag ) } return false; -} - -void Editor::draw_selection_box(int x, int y, int width, int height) -{ - if (x > window_ptr->width || y > (window_ptr->height - BAR_HEIGHT) || (x + width) < 0 || (x + height) < 0) - return; - SDL_SetRenderDrawColor(window_ptr->screen_renderer, 255, 0, 255, 255 / 8); - SDL_Rect r; - r.x = x - 1; - r.y = y - 1; - r.w = width + 1; - r.h = height + 1; - SDL_RenderFillRect(window_ptr->screen_renderer, &r); - SDL_SetRenderDrawColor(window_ptr->screen_renderer, 255, 0, 255, 255); - SDL_RenderDrawRect(window_ptr->screen_renderer, &r); -} - -void Editor::draw_dashed_level_border(borderType type, int pos, int offset) -{ - //We have an offset so the lines don't scroll out of synch with the view when scrolling - int initialOffset = offset % 20; - SDL_SetRenderDrawColor(window_ptr->screen_renderer, 200, 200, 200, 255); - int end, x1, y1, x2, y2; - if (type == horizontal) - { - end = window_ptr->width; - x1 = 0 - initialOffset; - x2 = 10 - initialOffset; - y1 = pos; - y2 = pos; - for (x1; x1 < end; x1 += 20) - { - SDL_RenderDrawLine(window_ptr->screen_renderer, x1, y1, x2, y2); - x2 += 20; - } - } - if (type == vertical) - { - end = window_ptr->height; - x1 = pos; - x2 = pos; - y1 = 0 - initialOffset; - y2 = 10 - initialOffset; - for (y1; y1 < end; y1 += 20) - { - SDL_RenderDrawLine(window_ptr->screen_renderer, x1, y1, x2, y2); - y2 += 20; - } - } } \ No newline at end of file diff --git a/src/Editor/editor.hpp b/src/Editor/editor.hpp index 8fbd28e..682e613 100644 --- a/src/Editor/editor.hpp +++ b/src/Editor/editor.hpp @@ -72,11 +72,6 @@ class Editor bool load(int n, Window * w); bool save(int n); - - void draw_selection_box(int x, int y, int width, int height); - - enum borderType { horizontal, vertical }; - void draw_dashed_level_border(borderType type, int pos, int offset); Editor( void ); ~Editor( void ) { /* nothing to do */ }