Added the SFML vector class. Need to extend it to have
the vector operations I want Changes to be committed: modified: CMakeLists.txt modified: README.md renamed: src/Curses.h -> include/Curses.h new file: include/Vector3.h new file: src/Vector3.cpp
This commit is contained in:
138
include/Curses.h
Normal file
138
include/Curses.h
Normal file
@@ -0,0 +1,138 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <list>
|
||||
|
||||
class Curses {
|
||||
public:
|
||||
|
||||
struct Slot {
|
||||
Slot(wchar_t unicode_value_,
|
||||
sf::Color font_color_,
|
||||
sf::Color backfill_color_) :
|
||||
unicode_value(unicode_value_),
|
||||
font_color(font_color_),
|
||||
backfill_color(backfill_color_)
|
||||
{};
|
||||
|
||||
wchar_t unicode_value;
|
||||
sf::Color font_color;
|
||||
sf::Color backfill_color;
|
||||
};
|
||||
|
||||
struct Tile {
|
||||
public:
|
||||
Tile(sf::Vector2i position_) :
|
||||
blank_standby(L'\u0020', sf::Color::Transparent, sf::Color::Black),
|
||||
position(position_)
|
||||
{ };
|
||||
|
||||
private:
|
||||
Slot blank_standby;
|
||||
|
||||
int index = 0; // What index in the vector are we. Backbone for blinking and scrolling
|
||||
int ratio_counter = 0; // Secondary counter to hold index positions for (ratio) length of time
|
||||
int ratio_value = 0;
|
||||
|
||||
std::vector<Slot> slot_stack; // The icon that aligns with the index
|
||||
|
||||
sf::Vector2i position; // Position of the text, and backfill
|
||||
|
||||
public:
|
||||
void set_ratio(int ratio_) {
|
||||
ratio_value = ratio_;
|
||||
}
|
||||
|
||||
sf::Vector2i getPosition() const {
|
||||
return position;
|
||||
}
|
||||
|
||||
void push_back(Slot s) {
|
||||
slot_stack.push_back(s);
|
||||
}
|
||||
|
||||
void clear_and_set(Slot s) {
|
||||
slot_stack.clear();
|
||||
slot_stack.push_back(s);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
slot_stack.clear();
|
||||
}
|
||||
|
||||
sf::Color current_font_color() {
|
||||
if (slot_stack.size() > 0)
|
||||
return slot_stack.at(index).font_color;
|
||||
else
|
||||
return blank_standby.font_color;
|
||||
}
|
||||
|
||||
sf::Color current_backfill_color() {
|
||||
if (slot_stack.size() > 0)
|
||||
return slot_stack.at(index).backfill_color;
|
||||
else
|
||||
return blank_standby.backfill_color;
|
||||
}
|
||||
|
||||
wchar_t current_unicode_value() {
|
||||
if (slot_stack.size() > 0)
|
||||
return slot_stack.at(index).unicode_value;
|
||||
else
|
||||
return blank_standby.unicode_value;
|
||||
}
|
||||
|
||||
void inc_index() {
|
||||
if (index >= slot_stack.size() - 1) {
|
||||
index = 0;
|
||||
}
|
||||
else if (ratio_counter == ratio_value) {
|
||||
ratio_counter = 0;
|
||||
index++;
|
||||
}
|
||||
else
|
||||
ratio_counter++;
|
||||
}
|
||||
};
|
||||
|
||||
Curses(sf::Vector2i tile_size_, sf::Vector2i grid_dimensions);
|
||||
~Curses();
|
||||
|
||||
|
||||
void Update(double delta_time_);
|
||||
void Render();
|
||||
|
||||
|
||||
void setTile(Tile tile_);
|
||||
void setTiles(std::vector<Tile> tiles_); // Can be seperate, non-adjacent tiles
|
||||
|
||||
void Clear();
|
||||
|
||||
Tile* getTile(sf::Vector2i position_);
|
||||
std::vector<Curses::Tile*> getTiles(sf::Vector2i start_, sf::Vector2i end_);
|
||||
|
||||
void ResizeTiles(sf::Vector2i size_);
|
||||
void ResizeTileGrid(sf::Vector2i grid_dimensions_);
|
||||
|
||||
void setBlink(int ratio_, sf::Vector2i position_);
|
||||
void setScroll(int ratio_, sf::Vector2i start_, sf::Vector2i end_);
|
||||
void setScroll(int ratio_, sf::Vector2i start_, std::list<Slot> tiles_);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
sf::Vector2i grid_dimensions;
|
||||
sf::Vector2i tile_pixel_dimensions;
|
||||
|
||||
sf::RenderWindow window;
|
||||
|
||||
std::vector<Tile> tiles;
|
||||
|
||||
sf::Font font;
|
||||
|
||||
int multi_to_linear(sf::Vector2i position_) const;
|
||||
sf::Vector2i linear_to_multi(int position_) const;
|
||||
|
||||
void set_tile_ratio(int ratio_, sf::Vector2i tile_position_);
|
||||
void append_slots(sf::Vector2i start_, std::list<Slot> values_);
|
||||
|
||||
};
|
||||
|
||||
140
include/Vector3.h
Normal file
140
include/Vector3.h
Normal file
@@ -0,0 +1,140 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef GAME_VECTOR3_H
|
||||
#define GAME_VECTOR3_H
|
||||
|
||||
template <typename T>
|
||||
class Vector3
|
||||
{
|
||||
public:
|
||||
|
||||
// Default constructor
|
||||
// Creates a Vector3(0, 0, 0).
|
||||
Vector3();
|
||||
|
||||
|
||||
// Construct the vector from its coordinates
|
||||
Vector3(T X, T Y, T Z);
|
||||
|
||||
|
||||
// Construct the vector from another type of vector
|
||||
// This constructor doesn't replace the copy constructor,
|
||||
// it's called only when U != T.
|
||||
// A call to this constructor will fail to compile if U
|
||||
// is not convertible to T.
|
||||
template <typename U>
|
||||
explicit Vector3(const Vector3<U>& vector);
|
||||
|
||||
// Member data
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
};
|
||||
|
||||
// Vector3
|
||||
// Overload of unary operator -
|
||||
// left Vector to negate
|
||||
// Memberwise opposite of the vector
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& left);
|
||||
|
||||
// Overload of binary operator +=
|
||||
// This operator performs a memberwise addition of both vectors,
|
||||
// and assigns the result to left.
|
||||
// returns Reference to left
|
||||
template <typename T>
|
||||
Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
// Overload of binary operator -=
|
||||
// This operator performs a memberwise subtraction of both vectors,
|
||||
// and assigns the result to left.
|
||||
// returns Reference to left
|
||||
template <typename T>
|
||||
Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
// Overload of binary operator +
|
||||
// returns Memberwise addition of both vectors
|
||||
template <typename T>
|
||||
Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right);
|
||||
// Overload of binary operator -
|
||||
// returns Memberwise subtraction of both vectors
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
// Overload of binary operator *
|
||||
// returns Memberwise multiplication by right
|
||||
template <typename T>
|
||||
Vector3<T> operator *(const Vector3<T>& left, T right);
|
||||
|
||||
// Overload of binary operator *
|
||||
// returns Memberwise multiplication by left
|
||||
template <typename T>
|
||||
Vector3<T> operator *(T left, const Vector3<T>& right);
|
||||
|
||||
// Overload of binary operator *=
|
||||
// This operator performs a memberwise multiplication by right,
|
||||
// and assigns the result to left.
|
||||
// returns Reference to left
|
||||
template <typename T>
|
||||
Vector3<T>& operator *=(Vector3<T>& left, T right);
|
||||
|
||||
// Overload of binary operator /
|
||||
// returns Memberwise division by right
|
||||
template <typename T>
|
||||
Vector3<T> operator /(const Vector3<T>& left, T right);
|
||||
|
||||
// Overload of binary operator /=
|
||||
// This operator performs a memberwise division by right,
|
||||
// and assigns the result to left.
|
||||
// returns Reference to left
|
||||
template <typename T>
|
||||
Vector3<T>& operator /=(Vector3<T>& left, T right);
|
||||
|
||||
// Overload of binary operator ==
|
||||
// This operator compares strict equality between two vectors.
|
||||
// returns True if left is equal to right
|
||||
template <typename T>
|
||||
bool operator ==(const Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
// Overload of binary operator !=
|
||||
// This operator compares strict difference between two vectors.
|
||||
// returns True if left is not equal to right
|
||||
template <typename T>
|
||||
bool operator !=(const Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
#include <SFML/System/Vector3.inl>
|
||||
|
||||
// Define the most common types
|
||||
typedef Vector3<int> Vector3i;
|
||||
typedef Vector3<float> Vector3f;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user