Working on the ui, incomplete
This commit is contained in:
+1
-1
@@ -4,5 +4,5 @@ all:
|
|||||||
$(MAKE) -C graphics
|
$(MAKE) -C graphics
|
||||||
$(MAKE) -C map
|
$(MAKE) -C map
|
||||||
$(MAKE) -C network
|
$(MAKE) -C network
|
||||||
# $(MAKE) -C ui #TODO: reenable this
|
$(MAKE) -C ui
|
||||||
$(MAKE) -C utilities
|
$(MAKE) -C utilities
|
||||||
|
|||||||
+21
-54
@@ -21,71 +21,38 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "bounding_box.hpp"
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
|
||||||
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/* 3-phases, no toggle, centred text
|
|
||||||
* This class uses the size of the provided image as its bounds. Also,
|
|
||||||
* The provided image should be formatted correctly.
|
|
||||||
*
|
|
||||||
* The button's image should be divided into 3 sections virtucally,
|
|
||||||
* which act as the different button images. The clip width & height of the
|
|
||||||
* Image should be set manually, and the height should be 1/3 of the total
|
|
||||||
* graphical data.
|
|
||||||
*/
|
|
||||||
class Button {
|
class Button {
|
||||||
public:
|
public:
|
||||||
enum State {
|
//states available
|
||||||
NORMAL = 0, HOVER = 1, PRESSED = 2
|
enum class State {
|
||||||
|
NORMAL, HOVER, PRESSED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//methods
|
||||||
Button() = default;
|
Button() = default;
|
||||||
~Button() = default;
|
~Button() = default;
|
||||||
|
|
||||||
//handle input
|
void RenderText(std::string s);
|
||||||
State MouseMotion(SDL_MouseMotionEvent const&);
|
bool CaptureInput(int x, int y, bool pressed);
|
||||||
State MouseButtonDown(SDL_MouseButtonEvent const&);
|
void DrawTo(SDL_Renderer*, int camX, int camY);
|
||||||
State MouseButtonUp(SDL_MouseButtonEvent const&);
|
|
||||||
|
|
||||||
//yet another draw function
|
//accessors & mutators
|
||||||
void DrawTo(SDL_Surface* const);
|
int SetX(int x) { return posX = x; }
|
||||||
|
int SetY(int y) { return posY = y; }
|
||||||
|
int GetX() { return posX; }
|
||||||
|
int GetY() { return posY; }
|
||||||
|
Image* GetImage() { return ℑ }
|
||||||
|
BoundingBox* GetBoundingBox() { return &boundingBox; }
|
||||||
|
|
||||||
//accessors and mutators
|
protected:
|
||||||
Image* SetImage(Image* const ptr) { return image = ptr; }
|
Image image;
|
||||||
Image* GetImage() { return image; }
|
BoundingBox boundingBox;
|
||||||
RasterFont* SetFont(RasterFont* const ptr) { return font = ptr; }
|
int posX = 0, posY = 0;
|
||||||
RasterFont* GetFont() { return font; }
|
|
||||||
|
|
||||||
Sint16 SetX(Sint16 i) { return x = i; }
|
|
||||||
Sint16 SetY(Sint16 i) { return y = i; }
|
|
||||||
Sint16 GetX() const { return x; }
|
|
||||||
Sint16 GetY() const { return y; }
|
|
||||||
|
|
||||||
Sint16 SetTextX(Sint16 i) { return textX = i; }
|
|
||||||
Sint16 SetTextY(Sint16 i) { return textY = i; }
|
|
||||||
Sint16 GetTextX() const { return textX; }
|
|
||||||
Sint16 GetTextY() const { return textY; }
|
|
||||||
|
|
||||||
State SetState(State s) { return state = s; }
|
|
||||||
State GetState() const { return state; }
|
|
||||||
|
|
||||||
std::string SetText(std::string);
|
|
||||||
std::string GetText() const { return text; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
State CalcState(Sint16 x, Sint16 y, bool leftPressed);
|
|
||||||
|
|
||||||
//point to the provided external objects
|
|
||||||
Image* image = nullptr;
|
|
||||||
RasterFont* font = nullptr;
|
|
||||||
|
|
||||||
//positions
|
|
||||||
Sint16 x = 0, y = 0;
|
|
||||||
Sint16 textX = 0, textY = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
State state = State::NORMAL;
|
|
||||||
std::string text;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#include "raster_font.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
/* It might be more efficient to render to a different surface (like an Image)
|
|
||||||
* rather than calling this function with all of it's '%' and '/'.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) {
|
|
||||||
if (!image.GetSurface()) {
|
|
||||||
throw(std::runtime_error("RasterFont not loaded"));
|
|
||||||
}
|
|
||||||
const Uint16 w = image.GetClipW();
|
|
||||||
const Uint16 h = image.GetClipH();
|
|
||||||
for (int i = 0; i < s.size(); i++) {
|
|
||||||
image.SetClipX(s[i] % 16 * w);
|
|
||||||
image.SetClipY(s[i] / 16 * h);
|
|
||||||
image.DrawTo(dest, x + i * w, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Note: This class can only take a raster font with 16*16 characters, and the
|
|
||||||
* indevidual characters must have the same dimensions. Overall this class is too
|
|
||||||
* restrictive; I suggest using a 3rd party library.
|
|
||||||
*/
|
|
||||||
|
|
||||||
SDL_Surface* RasterFont::LoadSurface(std::string fname) {
|
|
||||||
image.LoadSurface(fname);
|
|
||||||
image.SetClipW(image.GetSurface()->w/16);
|
|
||||||
image.SetClipH(image.GetSurface()->h/16);
|
|
||||||
return image.GetSurface();
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface* RasterFont::SetSurface(SDL_Surface* p) {
|
|
||||||
image.SetSurface(p);
|
|
||||||
image.SetClipW(image.GetSurface()->w/16);
|
|
||||||
image.SetClipH(image.GetSurface()->h/16);
|
|
||||||
return image.GetSurface();
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "image.hpp"
|
|
||||||
|
|
||||||
class RasterFont {
|
|
||||||
public:
|
|
||||||
RasterFont() = default;
|
|
||||||
RasterFont(RasterFont const& rhs) { *this = rhs; }
|
|
||||||
RasterFont(RasterFont&& rhs) { *this = std::move(rhs); }
|
|
||||||
RasterFont(std::string fname) { LoadSurface(fname); }
|
|
||||||
RasterFont(SDL_Surface* p) { SetSurface(p); }
|
|
||||||
~RasterFont() = default;
|
|
||||||
|
|
||||||
RasterFont& operator=(RasterFont const& rhs) { image = rhs.image; }
|
|
||||||
RasterFont& operator=(RasterFont&& rhs) { image = std::move(rhs.image); }
|
|
||||||
|
|
||||||
void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y);
|
|
||||||
|
|
||||||
//Accessors and Mutators
|
|
||||||
SDL_Surface* LoadSurface(std::string);
|
|
||||||
SDL_Surface* SetSurface(SDL_Surface*);
|
|
||||||
SDL_Surface* GetSurface() const { return image.GetSurface(); }
|
|
||||||
void FreeSurface() { image.FreeSurface(); }
|
|
||||||
|
|
||||||
Uint16 GetCharW() const { return image.GetClipW(); }
|
|
||||||
Uint16 GetCharH() const { return image.GetClipH(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Image image;
|
|
||||||
};
|
|
||||||
@@ -33,9 +33,9 @@ clean:
|
|||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
else ifeq ($(shell uname), Linux)
|
else ifeq ($(shell uname), Linux)
|
||||||
find . -type f -name *.o -exec rm -f -r -v {} \;
|
find . -type f -name '*.o' -exec rm -f -r -v {} \;
|
||||||
find . -type f -name *.a -exec rm -f -r -v {} \;
|
find . -type f -name '*.a' -exec rm -f -r -v {} \;
|
||||||
rm -f -v out/client out/server
|
rm -f -v $(OUT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
rebuild: clean all
|
rebuild: clean all
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ ifeq ($(OS),Windows_NT)
|
|||||||
endif
|
endif
|
||||||
LIBS+=-lSDLmain -lSDL -llua -lsqlite3
|
LIBS+=-lSDLmain -lSDL -llua -lsqlite3
|
||||||
ifeq ($(shell uname), Linux)
|
ifeq ($(shell uname), Linux)
|
||||||
#I don't know what this does, but Ubuntu needs it
|
#I don't know what this does, but Ubuntu needs it (dynamic linking for lua)
|
||||||
LIBS+=-ldl
|
LIBS+=-ldl
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user