# Update
- Added GetTime funcs to utils - Added Time() to App class to gather the apps run time in seconds - Updated almost every part of the sourcecode to the D7 Style guide
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <amethyst/iron.hpp>
|
||||
|
||||
/** Setup for everything (oder so) */
|
||||
enum LiPathRectFlags_ : amy::ui {
|
||||
enum LiPathRectFlags_ : Amy::ui {
|
||||
LiPathRectFlags_None = 0,
|
||||
LiPathRectFlags_KeepTopLeft = (1 << 0),
|
||||
LiPathRectFlags_KeepTopRight = (1 << 1),
|
||||
@@ -13,69 +13,67 @@ enum LiPathRectFlags_ : amy::ui {
|
||||
LiPathRectFlags_KeepRight = (1 << 1) | (1 << 2),
|
||||
};
|
||||
|
||||
namespace amy {
|
||||
namespace Amy {
|
||||
constexpr auto __pi = std::numbers::pi;
|
||||
|
||||
void iron::drawlist::merge(iron::drawlist* list) {
|
||||
for (size_t i = 0; i < list->m_data.size(); i++) {
|
||||
m_data.push_back(std::move(list->m_data[i]));
|
||||
void Iron::Drawlist::Merge(Iron::Drawlist* list) {
|
||||
for (size_t i = 0; i < list->pData.size(); i++) {
|
||||
pData.push_back(std::move(list->pData[i]));
|
||||
}
|
||||
list->clear();
|
||||
list->Clear();
|
||||
}
|
||||
|
||||
void iron::drawlist::clear() { m_data.clear(); }
|
||||
void Iron::Drawlist::Clear() { pData.clear(); }
|
||||
|
||||
iron::command::ref iron::drawlist::newCommand() {
|
||||
auto ret = std::make_unique<command>();
|
||||
ret->layer = m_layer;
|
||||
ret->index = m_data.size();
|
||||
ret->tex = m_tex;
|
||||
Iron::Command::ref Iron::Drawlist::NewCommand() {
|
||||
auto ret = std::make_unique<Command>();
|
||||
ret->Layer = pLayer;
|
||||
ret->Index = pData.size();
|
||||
ret->Tex = pTex;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void iron::drawlist::clipCmd(command* ptr) {
|
||||
if (!clipRects.empty()) {
|
||||
ptr->scissorOn = true;
|
||||
ptr->scissorRect = ivec4(clipRects.top());
|
||||
void Iron::Drawlist::clipCmd(Command* ptr) {
|
||||
if (!ClipRects.empty()) {
|
||||
ptr->ScissorOn = true;
|
||||
ptr->ScissorRect = ivec4(ClipRects.top());
|
||||
}
|
||||
}
|
||||
|
||||
void iron::drawlist::push(command::ref cmd) {
|
||||
m_data.push_back(std::move(cmd));
|
||||
}
|
||||
void Iron::Drawlist::Push(Command::ref cmd) { pData.push_back(std::move(cmd)); }
|
||||
|
||||
void iron::drawlist::drawSolid() { m_tex = iron::whiteTex(); }
|
||||
void Iron::Drawlist::DrawSolid() { pTex = Iron::WhiteTex(); }
|
||||
|
||||
void iron::drawlist::pathArcToN(const fvec2& c, float radius, float a_min,
|
||||
void Iron::Drawlist::PathArcToN(const fvec2& c, float radius, float a_min,
|
||||
float a_max, int segments) {
|
||||
// pathAdd(c)
|
||||
pathReserve(segments + 1);
|
||||
PathReserve(segments + 1);
|
||||
for (int i = 0; i < segments; i++) {
|
||||
float a = a_min + ((float)i / (float)segments) * (a_max - a_min);
|
||||
pathAdd(fvec2(c.x + std::cos(a) * radius, c.y + std::sin(a) * radius));
|
||||
PathAdd(fvec2(c.x + std::cos(a) * radius, c.y + std::sin(a) * radius));
|
||||
}
|
||||
}
|
||||
|
||||
void iron::drawlist::pathFastArcToN(const fvec2& c, float r, float amin,
|
||||
void Iron::Drawlist::PathFastArcToN(const fvec2& c, float r, float amin,
|
||||
float amax, int s) {
|
||||
/**
|
||||
* Funcion with less division overhead
|
||||
* Usefull for stuff where a lot of calculations are required
|
||||
*/
|
||||
float d = (amax - amin) / s;
|
||||
pathReserve(s + 1);
|
||||
PathReserve(s + 1);
|
||||
for (int i = 0; i <= s; i++) {
|
||||
float a = amin + i * d;
|
||||
pathAdd(fvec2(c.x + std::cos(a) * r, c.y + std::sin(a) * r));
|
||||
PathAdd(fvec2(c.x + std::cos(a) * r, c.y + std::sin(a) * r));
|
||||
}
|
||||
}
|
||||
|
||||
void iron::drawlist::pathRect(const fvec2& a, const fvec2& b, float rounding) {
|
||||
void Iron::Drawlist::PathRect(const fvec2& a, const fvec2& b, float rounding) {
|
||||
if (rounding == 0.f) {
|
||||
pathAdd(a);
|
||||
pathAdd(fvec2(b.x, a.y));
|
||||
pathAdd(b);
|
||||
pathAdd(fvec2(a.x, b.y));
|
||||
PathAdd(a);
|
||||
PathAdd(fvec2(b.x, a.y));
|
||||
PathAdd(b);
|
||||
PathAdd(fvec2(a.x, b.y));
|
||||
} else {
|
||||
float r = std::min({rounding, (b.x - a.x) * 0.5f, (b.y - a.y) * 0.5f});
|
||||
/** Calculate Optimal segment count automatically */
|
||||
@@ -87,28 +85,28 @@ void iron::drawlist::pathRect(const fvec2& a, const fvec2& b, float rounding) {
|
||||
* The Commands need to be setup clockwise
|
||||
*/
|
||||
/** Top Left */
|
||||
pathAdd(fvec2(a.x + r, a.y));
|
||||
pathFastArcToN(fvec2(b.x - r, a.y + r), r, -__pi / 2.0f, 0.0f, segments);
|
||||
PathAdd(fvec2(a.x + r, a.y));
|
||||
PathFastArcToN(fvec2(b.x - r, a.y + r), r, -__pi / 2.0f, 0.0f, segments);
|
||||
/** Top Right */
|
||||
pathAdd(fvec2(b.x, b.y - r));
|
||||
pathFastArcToN(fvec2(b.x - r, b.y - r), r, 0.0f, __pi / 2.0f, segments);
|
||||
PathAdd(fvec2(b.x, b.y - r));
|
||||
PathFastArcToN(fvec2(b.x - r, b.y - r), r, 0.0f, __pi / 2.0f, segments);
|
||||
/** Bottom Right */
|
||||
pathAdd(fvec2(a.x + r, b.y));
|
||||
pathFastArcToN(fvec2(a.x + r, b.y - r), r, __pi / 2.0f, __pi, segments);
|
||||
PathAdd(fvec2(a.x + r, b.y));
|
||||
PathFastArcToN(fvec2(a.x + r, b.y - r), r, __pi / 2.0f, __pi, segments);
|
||||
/** Bottom Left */
|
||||
pathAdd(fvec2(a.x, a.y + r));
|
||||
pathFastArcToN(fvec2(a.x + r, a.y + r), r, __pi, 3.0f * __pi / 2.0f,
|
||||
PathAdd(fvec2(a.x, a.y + r));
|
||||
PathFastArcToN(fvec2(a.x + r, a.y + r), r, __pi, 3.0f * __pi / 2.0f,
|
||||
segments);
|
||||
}
|
||||
}
|
||||
|
||||
void iron::drawlist::pathRectEx(const fvec2& a, const fvec2& b, float rounding,
|
||||
void Iron::Drawlist::PathRectEx(const fvec2& a, const fvec2& b, float rounding,
|
||||
ui flags) {
|
||||
if (rounding == 0.f) {
|
||||
pathAdd(a);
|
||||
pathAdd(fvec2(b.x, a.y));
|
||||
pathAdd(b);
|
||||
pathAdd(fvec2(a.x, b.y));
|
||||
PathAdd(a);
|
||||
PathAdd(fvec2(b.x, a.y));
|
||||
PathAdd(b);
|
||||
PathAdd(fvec2(a.x, b.y));
|
||||
} else {
|
||||
float r = std::min({rounding, (b.x - a.x) * 0.5f, (b.y - a.y) * 0.5f});
|
||||
/** Calculate Optimal segment count automatically */
|
||||
@@ -121,95 +119,95 @@ void iron::drawlist::pathRectEx(const fvec2& a, const fvec2& b, float rounding,
|
||||
*/
|
||||
/** Top Left */
|
||||
if (flags & LiPathRectFlags_KeepTopLeft) {
|
||||
pathAdd(a);
|
||||
PathAdd(a);
|
||||
} else {
|
||||
pathAdd(fvec2(a.x + r, a.y));
|
||||
pathFastArcToN(fvec2(b.x - r, a.y + r), r, -__pi / 2.0f, 0.0f, segments);
|
||||
PathAdd(fvec2(a.x + r, a.y));
|
||||
PathFastArcToN(fvec2(b.x - r, a.y + r), r, -__pi / 2.0f, 0.0f, segments);
|
||||
}
|
||||
|
||||
/** Top Right */
|
||||
if (flags & LiPathRectFlags_KeepTopRight) {
|
||||
pathAdd(fvec2(b.x, a.y));
|
||||
PathAdd(fvec2(b.x, a.y));
|
||||
} else {
|
||||
pathAdd(fvec2(b.x, b.y - r));
|
||||
pathFastArcToN(fvec2(b.x - r, b.y - r), r, 0.0f, __pi / 2.0f, segments);
|
||||
PathAdd(fvec2(b.x, b.y - r));
|
||||
PathFastArcToN(fvec2(b.x - r, b.y - r), r, 0.0f, __pi / 2.0f, segments);
|
||||
}
|
||||
/** Bottom Right */
|
||||
if (flags & LiPathRectFlags_KeepBotRight) {
|
||||
pathAdd(b);
|
||||
PathAdd(b);
|
||||
} else {
|
||||
pathAdd(fvec2(a.x + r, b.y));
|
||||
pathFastArcToN(fvec2(a.x + r, b.y - r), r, __pi / 2.0f, __pi, segments);
|
||||
PathAdd(fvec2(a.x + r, b.y));
|
||||
PathFastArcToN(fvec2(a.x + r, b.y - r), r, __pi / 2.0f, __pi, segments);
|
||||
}
|
||||
/** Bottom Left */
|
||||
if (flags & LiPathRectFlags_KeepBotLeft) {
|
||||
pathAdd(fvec2(a.x, b.y));
|
||||
PathAdd(fvec2(a.x, b.y));
|
||||
} else {
|
||||
pathAdd(fvec2(a.x, a.y + r));
|
||||
pathFastArcToN(fvec2(a.x + r, a.y + r), r, __pi, 3.0f * __pi / 2.0f,
|
||||
PathAdd(fvec2(a.x, a.y + r));
|
||||
PathFastArcToN(fvec2(a.x + r, a.y + r), r, __pi, 3.0f * __pi / 2.0f,
|
||||
segments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void iron::drawlist::drawRect(const fvec2& pos, const fvec2& size, ui color,
|
||||
void Iron::Drawlist::DrawRect(const fvec2& pos, const fvec2& size, ui color,
|
||||
int thickness) {
|
||||
pathRect(pos, pos + size);
|
||||
pathStroke(color, thickness, 1);
|
||||
PathRect(pos, pos + size);
|
||||
PathStroke(color, thickness, 1);
|
||||
}
|
||||
|
||||
void iron::drawlist::drawRectFilled(const fvec2& pos, const fvec2& size,
|
||||
void Iron::Drawlist::DrawRectFilled(const fvec2& pos, const fvec2& size,
|
||||
ui color) {
|
||||
pathRect(pos, pos + size);
|
||||
pathFill(color);
|
||||
PathRect(pos, pos + size);
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
void iron::drawlist::drawTriangle(const fvec2& a, const fvec2& b,
|
||||
void Iron::Drawlist::DrawTriangle(const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, ui color, int thickness) {
|
||||
pathAdd(a);
|
||||
pathAdd(b);
|
||||
pathAdd(c);
|
||||
pathStroke(color, thickness, 1);
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathAdd(c);
|
||||
PathStroke(color, thickness, 1);
|
||||
}
|
||||
|
||||
void iron::drawlist::drawTriangleFilled(const fvec2& a, const fvec2& b,
|
||||
void Iron::Drawlist::DrawTriangleFilled(const fvec2& a, const fvec2& b,
|
||||
const fvec2& c, ui color) {
|
||||
pathAdd(a);
|
||||
pathAdd(b);
|
||||
pathAdd(c);
|
||||
pathFill(color);
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathAdd(c);
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
void iron::drawlist::drawCircle(const fvec2& center, float rad, ui color,
|
||||
void Iron::Drawlist::DrawCircle(const fvec2& center, float rad, ui color,
|
||||
int segments, int thickness) {
|
||||
if (segments <= 0) {
|
||||
// Auto Segment
|
||||
} else {
|
||||
float am = (__pi * 2.0f) * ((float)segments) / (float)segments;
|
||||
pathArcToN(center, rad, 0.f, am, segments);
|
||||
PathArcToN(center, rad, 0.f, am, segments);
|
||||
}
|
||||
drawSolid(); // Only Solid Color Supported
|
||||
pathStroke(color, thickness, 1);
|
||||
DrawSolid(); // Only Solid Color Supported
|
||||
PathStroke(color, thickness, 1);
|
||||
}
|
||||
|
||||
void iron::drawlist::drawCircleFilled(const fvec2& center, float rad, ui color,
|
||||
void Iron::Drawlist::DrawCircleFilled(const fvec2& center, float rad, ui color,
|
||||
int segments) {
|
||||
if (segments <= 0) {
|
||||
// Auto Segment
|
||||
} else {
|
||||
float am = (__pi * 2.0f) * ((float)segments) / (float)segments;
|
||||
pathArcToN(center, rad, 0.f, am, segments);
|
||||
PathArcToN(center, rad, 0.f, am, segments);
|
||||
}
|
||||
pathFill(color);
|
||||
PathFill(color);
|
||||
}
|
||||
|
||||
void iron::drawlist::drawPolyLine(const std::vector<fvec2>& points, ui clr,
|
||||
void Iron::Drawlist::DrawPolyLine(const std::vector<fvec2>& points, ui clr,
|
||||
ui flags, int thickness) {
|
||||
if (points.size() < 2) {
|
||||
return;
|
||||
}
|
||||
drawSolid();
|
||||
auto cmd = newCommand();
|
||||
DrawSolid();
|
||||
auto cmd = NewCommand();
|
||||
bool close = (flags & (1 << 0));
|
||||
int num_points = close ? (int)points.size() : (int)points.size() - 1;
|
||||
if (flags & (1 << 1)) {
|
||||
@@ -218,24 +216,24 @@ void iron::drawlist::drawPolyLine(const std::vector<fvec2>& points, ui clr,
|
||||
// Non antialiased lines look awful when rendering with thickness != 1
|
||||
for (int i = 0; i < num_points; i++) {
|
||||
int j = (i + 1) == (int)points.size() ? 0 : (i + 1);
|
||||
auto line = primLine(points[i], points[j], thickness);
|
||||
cmdQuad(cmd.get(), line, fvec4(0.f, 1.f, 1.f, 0.f), clr);
|
||||
auto line = PrimLine(points[i], points[j], thickness);
|
||||
CmdQuad(cmd.get(), line, fvec4(0.f, 1.f, 1.f, 0.f), clr);
|
||||
}
|
||||
}
|
||||
push(std::move(cmd));
|
||||
Push(std::move(cmd));
|
||||
}
|
||||
|
||||
void iron::drawlist::drawConvexPolyFilled(const std::vector<fvec2>& points,
|
||||
void Iron::Drawlist::DrawConvexPolyFilled(const std::vector<fvec2>& points,
|
||||
ui clr) {
|
||||
if (points.size() < 3) {
|
||||
return; // Need at least three points
|
||||
}
|
||||
auto cmd = newCommand();
|
||||
cmdConvexPolyFilled(cmd.get(), points, clr, m_tex);
|
||||
push(std::move(cmd));
|
||||
auto cmd = NewCommand();
|
||||
CmdConvexPolyFilled(cmd.get(), points, clr, pTex);
|
||||
Push(std::move(cmd));
|
||||
}
|
||||
|
||||
void iron::drawlist::drawText(const fvec2& pos, const std::string& text,
|
||||
void Iron::Drawlist::DrawText(const fvec2& pos, const std::string& text,
|
||||
ui color) {
|
||||
/*if (!pCurrentFont) {
|
||||
return;
|
||||
@@ -243,13 +241,13 @@ void iron::drawlist::drawText(const fvec2& pos, const std::string& text,
|
||||
std::vector<Command::Ref> cmds;
|
||||
pCurrentFont->CmdTextEx(cmds, pos, color, pFontScale, text);
|
||||
for (size_t i = 0; i < cmds.size(); i++) {
|
||||
cmds[i]->Index = pDrawList.size();
|
||||
cmds[i]->Index = pDrawlist.size();
|
||||
cmds[i]->Layer = Layer;
|
||||
AddCommand(std::move(cmds[i]));
|
||||
}*/
|
||||
}
|
||||
|
||||
void iron::drawlist::drawTextEx(const fvec2& p, const std::string& text,
|
||||
void Iron::Drawlist::DrawTextEx(const fvec2& p, const std::string& text,
|
||||
ui color, ui flags, const fvec2& box) {
|
||||
/*if (!pCurrentFont) {
|
||||
return;
|
||||
@@ -257,15 +255,15 @@ void iron::drawlist::drawTextEx(const fvec2& p, const std::string& text,
|
||||
std::vector<Command::Ref> cmds;
|
||||
pCurrentFont->CmdTextEx(cmds, p, color, pFontScale, text, flags, box);
|
||||
for (size_t i = 0; i < cmds.size(); i++) {
|
||||
cmds[i]->Index = pDrawList.size();
|
||||
cmds[i]->Index = pDrawlist.size();
|
||||
cmds[i]->Layer = Layer;
|
||||
AddCommand(std::move(cmds[i]));
|
||||
}*/
|
||||
}
|
||||
|
||||
void iron::drawlist::drawLine(const fvec2& a, const fvec2& b, ui color, int t) {
|
||||
pathAdd(a);
|
||||
pathAdd(b);
|
||||
pathStroke(color, t);
|
||||
void Iron::Drawlist::DrawLine(const fvec2& a, const fvec2& b, ui color, int t) {
|
||||
PathAdd(a);
|
||||
PathAdd(b);
|
||||
PathStroke(color, t);
|
||||
}
|
||||
} // namespace amy
|
||||
} // namespace Amy
|
||||
Reference in New Issue
Block a user