GlistEngine
Loading...
Searching...
No Matches
gGUIGraph.h
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2014 Nitra Games Ltd., Istanbul, Turkey *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice should not be *
13 * deleted from the source form of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
28
29/****************************************************************************
30 * Author: Noyan Culum, Utku Sarialan, 2022 *
31 ****************************************************************************/
32
33/*
34 * gGUIGraph.h
35 *
36 * Created on: Sep 23, 2022
37 * Author: noyan
38 */
39
40#ifndef UI_GGUIGRAPH_H_
41#define UI_GGUIGRAPH_H_
42
43#include "gGUIControl.h"
44#include "gMesh.h"
45#include <array>
46
51class gGUIGraph: public gGUIControl {
52public:
54 virtual ~gGUIGraph() override;
55
56 void set(gBaseApp* root, gBaseGUIObject* topParentGUIObject, gBaseGUIObject* parentGUIObject, int parentSlotLineNo, int parentSlotColumnNo, int x, int y, int w, int h) override;
57
58 virtual void setMaxX(float maxX);
59 int getMaxX();
60 virtual void setMinX(float minX);
61 int getMinX();
62 virtual void setMaxY(float maxY);
63 int getMaxY();
64 virtual void setMinY(float minY);
65 int getMinY();
66
69
70 void setAxislinesEnable(bool xaxis, bool yaxis);
71
72 void setTitleX(std::string titleX);
73 std::string getTitleX();
74 void setTitleY(std::string titleY);
75 std::string getTitleY();
76
77 virtual void setLabelCountX(int labelCount);
79 virtual void setLabelCountY(int labelCount);
81
82 virtual void enableRange(bool isRangeEnabled);
83 virtual void setRange(float rangeStart, float rangeEnd);
86
89
90 void draw() override;
91
92 virtual void clear();
93
94protected:
97 float axisxw, axisyh;
98 float maxy, miny, maxx, minx;
107
113 void setLabelsYForRange(float rangeMinY, float rangeMaxY);
114
115 class PolylineMesh : public gMesh {
116 public:
121
122 PolylineMesh(const PolylineMesh& other) : gMesh(other) {
123 isprojection2d = true;
125 }
126
127 void setRibbonVertices(std::shared_ptr<std::vector<gVertex>> vertices, std::shared_ptr<std::vector<gIndex>> indices) {
128 isprojection2d = true;
130 setVertices(vertices, indices);
131 }
132 };
133
137 bool hascore = false;
138 bool hasfringe = false;
139
140 void clear() {
141 hascore = false;
142 hasfringe = false;
143 coremesh.clear();
144 fringemesh.clear();
145 }
146 };
147
148 static bool buildPolylineRibbon(PolylineMesh& mesh, const std::vector<std::vector<std::array<float, 2>>>& runs, float halfWidth, bool roundedCorners);
149 static void buildPolylineStroke(PolylineStroke& stroke, const std::vector<std::vector<std::array<float, 2>>>& runs, float thickness, bool roundedCorners);
150 void drawPolylineStroke(PolylineStroke& stroke, const gColor& color);
151
152private:
153 void drawBackground();
154 void drawLabels();
155 virtual void drawGraph();
156 void updateLabelsX();
157 void updateLabelsY();
158 int countDigits(int number);
159 float labelwidthx, labelwidthy;
160 std::string axisytitle, axisxtitle;
161 std::vector<int> labelsx;
162 std::vector<int> labelsy;
163 std::vector<float> floatlabelsx;
164 std::vector<float> floatlabelsy;
165 std::vector<int> labelsteps;
166};
167
168#endif /* UI_GGUIGRAPH_H_ */
Definition gBaseApp.h:16
gBaseApp * root
Definition gBaseGUIObject.h:151
Definition gColor.h:17
Definition gGUIGraph.h:115
PolylineMesh(const PolylineMesh &other)
Definition gGUIGraph.h:122
void setRibbonVertices(std::shared_ptr< std::vector< gVertex > > vertices, std::shared_ptr< std::vector< gIndex > > indices)
Definition gGUIGraph.h:127
PolylineMesh()
Definition gGUIGraph.h:117
void setTitleX(std::string titleX)
void enableBackground(bool isEnabled)
float axisxw
Definition gGUIGraph.h:97
virtual void setLabelCountY(int labelCount)
float largestvaluex
Definition gGUIGraph.h:99
int labelcounty
Definition gGUIGraph.h:104
bool isBackgroundEnabled()
int rangestart
Definition gGUIGraph.h:105
bool yaxislenable
Definition gGUIGraph.h:101
int getMaxY()
static void buildPolylineStroke(PolylineStroke &stroke, const std::vector< std::vector< std::array< float, 2 > > > &runs, float thickness, bool roundedCorners)
int getLabelCountY()
float axisystart
Definition gGUIGraph.h:96
virtual void setRange(float rangeStart, float rangeEnd)
float axisxstart
Definition gGUIGraph.h:96
float largestvaluey
Definition gGUIGraph.h:99
virtual ~gGUIGraph() override
float smallestvaluex
Definition gGUIGraph.h:99
float axisx2
Definition gGUIGraph.h:96
float axisx1
Definition gGUIGraph.h:96
void setAxislinesEnable(bool xaxis, bool yaxis)
int getRangeStart()
int labelcountx
Definition gGUIGraph.h:104
void enableGridlinesX(bool isEnabled)
void setLabelsYForRange(float rangeMinY, float rangeMaxY)
int getRangeEnd()
float minx
Definition gGUIGraph.h:98
int getLabelCountX()
bool rangeenabled
Definition gGUIGraph.h:106
float smallestvaluey
Definition gGUIGraph.h:99
virtual void enableRange(bool isRangeEnabled)
void draw() override
int getMaxX()
float maxx
Definition gGUIGraph.h:98
virtual void setMaxY(float maxY)
int getMinY()
bool gridlinesxenabled
Definition gGUIGraph.h:100
float axisyh
Definition gGUIGraph.h:97
bool isbackgroundenabled
Definition gGUIGraph.h:95
std::string getTitleY()
bool floatlabelsxenabled
Definition gGUIGraph.h:102
bool isxaxislinenable
Definition gGUIGraph.h:101
float miny
Definition gGUIGraph.h:98
virtual void setMaxX(float maxX)
virtual void setMinX(float minX)
float maxy
Definition gGUIGraph.h:98
bool floatlabelsyenabled
Definition gGUIGraph.h:103
void setTitleY(std::string titleY)
virtual void clear()
bool gridlinesyenabled
Definition gGUIGraph.h:100
float axisy1
Definition gGUIGraph.h:96
int rangeend
Definition gGUIGraph.h:105
static bool buildPolylineRibbon(PolylineMesh &mesh, const std::vector< std::vector< std::array< float, 2 > > > &runs, float halfWidth, bool roundedCorners)
std::string getTitleX()
int getMinX()
virtual void setMinY(float minY)
virtual void setLabelCountX(int labelCount)
void enableGridlinesY(bool isEnabled)
void set(gBaseApp *root, gBaseGUIObject *topParentGUIObject, gBaseGUIObject *parentGUIObject, int parentSlotLineNo, int parentSlotColumnNo, int x, int y, int w, int h) override
void drawPolylineStroke(PolylineStroke &stroke, const gColor &color)
float axisy2
Definition gGUIGraph.h:96
static const int DRAWMODE_TRIANGLES
Definition gMesh.h:24
bool isprojection2d
Definition gMesh.h:136
void setDrawMode(int drawMode)
void setVertices(const std::vector< gVertex > &vertices, const std::vector< gIndex > &indices)
std::shared_ptr< std::vector< gVertex > > vertices
Definition gMesh.h:135
Definition gGUIGraph.h:134
bool hascore
Definition gGUIGraph.h:137
PolylineMesh coremesh
Definition gGUIGraph.h:135
void clear()
Definition gGUIGraph.h:140
bool hasfringe
Definition gGUIGraph.h:138
PolylineMesh fringemesh
Definition gGUIGraph.h:136