Removed bounding_box.hpp, not needed

This commit is contained in:
2018-08-06 05:54:42 +10:00
parent 13e810df0a
commit d087ff2858
5 changed files with 35 additions and 91 deletions
+11 -2
View File
@@ -1,10 +1,19 @@
## Outline ## Outline
TurtleGUI requires SDL2, SDL_image and SDL_ttf. Other than that, it should be a self contained package. TurtleGUI requires SDL2, SDL2_image and SDL2_ttf. Other than that, it should be a self contained package.
## Contents
* Image - For loading and rendering an image to the screen
* Button - For on-screen buttons that can be clicked
* TextLine - For rendering a single line of text to the screen
* TextBox - A collection of TextLines, and utilities for managing them
* TextField - For inputting text, rendered to the screen
* Vector2 - I don't know where else to put this
## Copyright ## Copyright
Copyright (c) 2013-2016 Kayne Ruse Copyright (c) 2013-2018 Kayne Ruse
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
-75
View File
@@ -1,75 +0,0 @@
/* Copyright: (c) Kayne Ruse 2013-2016
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#pragma once
#include <type_traits>
#include <algorithm>
class BoundingBox {
public:
//This is explicitly a POD
int x, y;
int w, h;
BoundingBox() = default;
BoundingBox(int i, int j): x(i), y(j), w(0), h(0) {};
BoundingBox(int i, int j, int k, int l): x(i), y(j), w(k), h(l) {};
~BoundingBox() = default;
BoundingBox& operator=(BoundingBox const&) = default;
int Size() {
return std::max(w*h,0);
}
bool CheckOverlap(BoundingBox rhs) {
return !(
x >= rhs.x + rhs.w ||
y >= rhs.y + rhs.h ||
rhs.x >= x + w ||
rhs.y >= y + h);
}
BoundingBox CalcOverlap(BoundingBox rhs) {
if (!CheckOverlap(rhs)) {
return {0, 0, 0, 0};
}
BoundingBox ret;
ret.x = std::max(x, rhs.x);
ret.y = std::max(y, rhs.y);
ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x;
ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y;
return ret;
}
};
//This is explicitly a POD
static_assert(std::is_pod<BoundingBox>::value, "BoundingBox is not a POD");
#include "vector2.hpp"
//operators
inline BoundingBox operator+(BoundingBox b, Vector2 v) {
return {b.x + (int)v.x, b.y + (int)v.y, b.w, b.h};
}
inline BoundingBox operator+(Vector2 v, BoundingBox b) {
return b + v;
}
+18 -9
View File
@@ -69,19 +69,28 @@ std::string TextField::GetText() {
} }
bool TextField::MouseButtonDown(SDL_MouseButtonEvent const& event) { bool TextField::MouseButtonDown(SDL_MouseButtonEvent const& event) {
BoundingBox cursorBox = {event.x, event.y, 0, 0}; focus =
BoundingBox fieldBox = bounds; event.x > posX &&
fieldBox.x += posX; event.y > posY &&
fieldBox.y += posY; event.x < posX + width &&
return focus = fieldBox.CheckOverlap(cursorBox); event.y < posY + height;
return focus;
} }
BoundingBox TextField::SetBounds(BoundingBox b) { int TextField::SetWidth(int w) {
return bounds = b; return width = w;
} }
BoundingBox TextField::GetBounds() { int TextField::SetHeight(int h) {
return bounds; return height = h;
}
int TextField::GetWidth() {
return width;
}
int TextField::GetHeight() {
return height;
} }
bool TextField::SetFocus(bool b) { bool TextField::SetFocus(bool b) {
+5 -5
View File
@@ -21,8 +21,6 @@
*/ */
#pragma once #pragma once
#include "bounding_box.hpp"
#include "SDL2/SDL.h" #include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h" #include "SDL2/SDL_ttf.h"
@@ -44,8 +42,10 @@ public:
bool MouseButtonDown(SDL_MouseButtonEvent const& event); bool MouseButtonDown(SDL_MouseButtonEvent const& event);
BoundingBox SetBounds(BoundingBox b); int SetWidth(int w);
BoundingBox GetBounds(); int SetHeight(int h);
int GetWidth();
int GetHeight();
bool SetFocus(bool b); bool SetFocus(bool b);
bool GetFocus(); bool GetFocus();
@@ -59,7 +59,7 @@ public:
private: private:
SDL_Texture* texture = nullptr; SDL_Texture* texture = nullptr;
std::string text; std::string text;
BoundingBox bounds;
bool focus = false; bool focus = false;
int posX = 0, posY = 0; int posX = 0, posY = 0;
int width = 0, height = 0;
}; };
+1
View File
@@ -34,6 +34,7 @@ public:
void DrawTo(SDL_Renderer*); void DrawTo(SDL_Renderer*);
//TODO: replace TTF_Font* with a font class
void SetText(SDL_Renderer*, TTF_Font*, SDL_Color, std::string); void SetText(SDL_Renderer*, TTF_Font*, SDL_Color, std::string);
void ClearText(); void ClearText();