From 1162be37102b24df11f469495c0184f3f9a26ba0 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 12 Aug 2012 16:34:36 +0200 Subject: [PATCH] pass point as reference in graphics Draw functions --- src/graphics/Font.cpp | 8 ++++---- src/graphics/Font.h | 8 ++++---- src/graphics/Frame.cpp | 2 +- src/graphics/Frame.h | 2 +- src/graphics/Gauge.cpp | 2 +- src/graphics/Gauge.h | 2 +- src/graphics/Menu.h | 4 ++-- src/graphics/Sprite.cpp | 2 +- src/graphics/Sprite.h | 8 ++++---- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index 3e46249..1dc9051 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -18,13 +18,13 @@ using std::pow; namespace graphics { -void Font::DrawChar(char c, SDL_Surface *dest, Point position) const { +void Font::DrawChar(char c, SDL_Surface *dest, const Point &position) const { int col(colOffset + (c % 0x10)); int row(rowOffset + (c / 0x10)); sprite->Draw(dest, position, col, row); } -void Font::DrawString(const char *s, SDL_Surface *dest, Point positionIn, int maxChars) const { +void Font::DrawString(const char *s, SDL_Surface *dest, const Point &positionIn, int maxChars) const { Point position(positionIn); Vector step(CharWidth(), 0); for (int i(0); s[i] && (maxChars <= 0 || i < maxChars); ++i, position += step) { @@ -32,11 +32,11 @@ void Font::DrawString(const char *s, SDL_Surface *dest, Point positionIn, i } } -void Font::DrawDigit(int digit, SDL_Surface *dest, Point position) const { +void Font::DrawDigit(int digit, SDL_Surface *dest, const Point &position) const { DrawChar(digit + 0x30, dest, position); } -void Font::DrawNumber(int numberIn, SDL_Surface *dest, Point positionIn, int digits) const { +void Font::DrawNumber(int numberIn, SDL_Surface *dest, const Point &positionIn, int digits) const { int number(numberIn); if (digits > 0 && numberIn >= pow(10.0, digits)) { numberIn = pow(10.0, digits) - 1; diff --git a/src/graphics/Font.h b/src/graphics/Font.h index 70f451c..c48ea16 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -26,10 +26,10 @@ public: public: int CharWidth() const { return sprite->Width(); } int CharHeight() const { return sprite->Height(); } - void DrawChar(char c, SDL_Surface *dest, geometry::Point position) const; - void DrawString(const char *s, SDL_Surface *dest, geometry::Point position, int maxChars = 0) const; - void DrawDigit(int d, SDL_Surface *dest, geometry::Point position) const; - void DrawNumber(int n, SDL_Surface *dest, geometry::Point position, int digits = 0) const; + void DrawChar(char c, SDL_Surface *dest, const geometry::Point &position) const; + void DrawString(const char *s, SDL_Surface *dest, const geometry::Point &position, int maxChars = 0) const; + void DrawDigit(int d, SDL_Surface *dest, const geometry::Point &position) const; + void DrawNumber(int n, SDL_Surface *dest, const geometry::Point &position, int digits = 0) const; private: const Sprite *sprite; diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index ac394d1..c682fa0 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -12,7 +12,7 @@ using geometry::Point; namespace graphics { // TODO: maybe create a cache for frames? -void Frame::Draw(SDL_Surface *dest, Point position, int width, int height) const { +void Frame::Draw(SDL_Surface *dest, const Point &position, int width, int height) const { // top-left corner SDL_Rect srcRect; srcRect.x = xOffset; diff --git a/src/graphics/Frame.h b/src/graphics/Frame.h index 3743640..d2e8dd4 100644 --- a/src/graphics/Frame.h +++ b/src/graphics/Frame.h @@ -25,7 +25,7 @@ public: int MinHeight() const { return 2 * borderHeight; } int BorderWidth() const { return borderWidth; } int BorderHeight() const { return borderHeight; } - void Draw(SDL_Surface *dest, geometry::Point position, int width, int height) const; + void Draw(SDL_Surface *dest, const geometry::Point &position, int width, int height) const; private: SDL_Surface *surface; diff --git a/src/graphics/Gauge.cpp b/src/graphics/Gauge.cpp index 09405a2..027d6b1 100644 --- a/src/graphics/Gauge.cpp +++ b/src/graphics/Gauge.cpp @@ -11,7 +11,7 @@ using geometry::Point; namespace graphics { -void Gauge::Draw(SDL_Surface *dest, Point position, int width, Uint8 fill) const { +void Gauge::Draw(SDL_Surface *dest, const Point &position, int width, Uint8 fill) const { SDL_Rect srcRect, destRect; int filledWidth = fill * (width - startWidth - endWidth) / 255; diff --git a/src/graphics/Gauge.h b/src/graphics/Gauge.h index 01b7aeb..b5e30c2 100644 --- a/src/graphics/Gauge.h +++ b/src/graphics/Gauge.h @@ -23,7 +23,7 @@ public: public: int MinWidth() const { return startWidth + endWidth; } int Height() const { return height; } - void Draw(SDL_Surface *dest, geometry::Point position, int width, Uint8 fill) const; + void Draw(SDL_Surface *dest, const geometry::Point &position, int width, Uint8 fill) const; private: SDL_Surface *surface; diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index 4d448b6..c879cc9 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -61,7 +61,7 @@ public: void Reserve(int n) { entries.reserve(n); } void Clear() { entries.clear(); } - void Draw(SDL_Surface *dest, geometry::Point position) const; + void Draw(SDL_Surface *dest, const geometry::Point &position) const; private: int GetRow(int index) const { return index / cols; } @@ -196,7 +196,7 @@ void Menu::SelectIndex(int index) { template -void Menu::Draw(SDL_Surface *dest, geometry::Point position) const { +void Menu::Draw(SDL_Surface *dest, const geometry::Point &position) const { int start(topRow * cols); int slots(rows * cols); int items(entries.size() - start); diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index 363be11..87ce8af 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -11,7 +11,7 @@ using geometry::Point; namespace graphics { -void Sprite::Draw(SDL_Surface *dest, Point position, int col, int row) const { +void Sprite::Draw(SDL_Surface *dest, const Point &position, int col, int row) const { SDL_Rect srcRect, destRect; srcRect.x = xOffset + col * Width(); srcRect.y = yOffset + row * Height(); diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h index d56c691..6aa6c94 100644 --- a/src/graphics/Sprite.h +++ b/src/graphics/Sprite.h @@ -25,16 +25,16 @@ public: public: int Width() const { return width; } int Height() const { return height; } - void Draw(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const; - void DrawTopRight(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const { + void Draw(SDL_Surface *dest, const geometry::Point &position, int col = 0, int row = 0) const; + void DrawTopRight(SDL_Surface *dest, const geometry::Point &position, int col = 0, int row = 0) const { geometry::Vector offset(-Width(), 0); Draw(dest, position + offset, col, row); } - void DrawCenter(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const { + void DrawCenter(SDL_Surface *dest, const geometry::Point &position, int col = 0, int row = 0) const { geometry::Vector offset(-Width() / 2, -Height() / 2); Draw(dest, position + offset, col, row); } - void DrawCenterBottom(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const { + void DrawCenterBottom(SDL_Surface *dest, const geometry::Point &position, int col = 0, int row = 0) const { geometry::Vector offset(-Width() / 2, -Height()); Draw(dest, position + offset, col, row); } -- 2.39.2