mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 05:36:59 -04:00
implemented resampled text ("high quality")
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@87 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/control/graph.hpp>
|
||||
#include <util/alignment.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
@@ -86,8 +87,11 @@ GraphData::GraphData(const GraphDataPre& d)
|
||||
|
||||
// ----------------------------------------------------------------------------- : Graph1D
|
||||
|
||||
bool Graph1D::findItem(const RealPoint& pos, vector<int>& out) const {
|
||||
int i = findItem(pos);
|
||||
void Graph1D::draw(RotatedDC& dc, const vector<int>& current) const {
|
||||
draw(dc, axis < current.size() ? current.at(axis) : -1);
|
||||
}
|
||||
bool Graph1D::findItem(const RealPoint& pos, const RealRect& rect, vector<int>& out) const {
|
||||
int i = findItem(pos, rect);
|
||||
if (i == -1) return false;
|
||||
else {
|
||||
out.clear();
|
||||
@@ -99,11 +103,86 @@ bool Graph1D::findItem(const RealPoint& pos, vector<int>& out) const {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Bar Graph
|
||||
|
||||
void BarGraph::draw(RotatedDC& dc) const {
|
||||
// TODO
|
||||
void BarGraph::draw(RotatedDC& dc, int current) const {
|
||||
if (!data) return;
|
||||
// Rectangle for bars
|
||||
RealRect rect = dc.getInternalRect().move(15, 5, -20, -20);
|
||||
// Bar sizes
|
||||
GraphAxis& axis = axis_data();
|
||||
int count = int(axis.groups.size());
|
||||
double width_space = rect.width / count; // including spacing
|
||||
double width = width_space / 5 * 4;
|
||||
double space = width_space / 5;
|
||||
double step_height = rect.height / axis.max; // multiplier for bar height
|
||||
// Highlight current column
|
||||
Color bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
if (current >= 0) {
|
||||
double x = rect.x + width_space * current;
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(lerp(bg, axis.groups[current].color, 0.25));
|
||||
dc.DrawRectangle(RealRect(x + space / 2 - 5, rect.bottom() + 1 + 15,
|
||||
width + 10, -step_height * axis.groups[current].size - 1.999 - 20));
|
||||
dc.SetBrush(lerp(bg, axis.groups[current].color, 0.5));
|
||||
dc.DrawRectangle(RealRect(x + space / 2 - 2, rect.bottom() + 1 + 2,
|
||||
width + 4, -step_height * axis.groups[current].size - 1.999 - 4));
|
||||
}
|
||||
// How many labels and lines to draw?
|
||||
dc.SetFont(*wxNORMAL_FONT);
|
||||
UInt label_step = max(1.0, dc.GetCharHeight() / step_height);
|
||||
// Draw backlines (horizontal) and value labels
|
||||
dc.SetPen(lerp(bg, fg, 0.5));
|
||||
for (UInt i = 0 ; i <= axis.max ; ++i) {
|
||||
if (i % label_step == 0) {
|
||||
int y = rect.bottom() - i * step_height;
|
||||
dc.DrawLine(RealPoint(rect.left() - 2, y), RealPoint(rect.right(), y));
|
||||
// draw label, aligned middle right
|
||||
String label; label << i;
|
||||
RealSize text_size = dc.GetTextExtent(label);
|
||||
dc.DrawText(label, align_in_rect(ALIGN_MIDDLE_RIGHT, text_size, RealRect(rect.x - 4, y, 0, 0)));
|
||||
}
|
||||
}
|
||||
// Draw axes
|
||||
dc.SetPen(fg);
|
||||
dc.DrawLine(rect.bottomLeft() - RealSize(2,0), rect.bottomRight());
|
||||
dc.DrawLine(rect.topLeft(), rect.bottomLeft());
|
||||
// Draw bars
|
||||
double x = rect.x;
|
||||
FOR_EACH_CONST(g, axis.groups) {
|
||||
// draw bar
|
||||
dc.SetBrush(g.color);
|
||||
dc.DrawRectangle(RealRect(x + space / 2, rect.bottom() + 1, width, -step_height * g.size - 1.999));
|
||||
// draw label, aligned bottom center
|
||||
RealSize text_size = dc.GetTextExtent(g.name);
|
||||
dc.SetClippingRegion(RealRect(x + 2, rect.bottom(), width_space - 4, text_size.height));
|
||||
dc.DrawText(g.name, align_in_rect(ALIGN_TOP_CENTER, text_size, RealRect(x, rect.bottom() + 3, width_space, 0)));
|
||||
dc.DestroyClippingRegion();
|
||||
x += width_space;
|
||||
}
|
||||
}
|
||||
int BarGraph::findItem(const RealPoint& pos) const {
|
||||
return -1; // TODO
|
||||
int BarGraph::findItem(const RealPoint& pos, const RealRect& rect1) const {
|
||||
if (!data) return -1;
|
||||
// Rectangle for bars
|
||||
RealRect rect = rect1.move(15, 5, -20, -20);
|
||||
// Bar sizes
|
||||
GraphAxis& axis = axis_data();
|
||||
int count = int(axis.groups.size());
|
||||
double width_space = rect.width / count; // including spacing
|
||||
double space = width_space / 5;
|
||||
// Find column in which this point could be located
|
||||
int col = (pos.x - rect.x) / width_space;
|
||||
double in_col = (pos.x - rect.x) - col * width_space;
|
||||
if (in_col < space / 2 || // left
|
||||
in_col > width_space - space / 2 || // right
|
||||
pos.y > rect.bottom() || // below
|
||||
pos.y < rect.top()) { // above
|
||||
return -1;
|
||||
}
|
||||
if (col < 0 || (size_t)col >= axis_data().groups.size()) {
|
||||
return -1;
|
||||
} else {
|
||||
return col;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Pie Graph
|
||||
@@ -136,7 +215,7 @@ void GraphControl::onPaint(wxPaintEvent&) {
|
||||
rdc.SetPen(*wxTRANSPARENT_PEN);
|
||||
rdc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
rdc.DrawRectangle(rdc.getInternalRect());
|
||||
if (graph) graph->draw(rdc);
|
||||
if (graph) graph->draw(rdc, current_item);
|
||||
}
|
||||
|
||||
void GraphControl::onSize(wxSizeEvent&) {
|
||||
@@ -146,7 +225,9 @@ void GraphControl::onSize(wxSizeEvent&) {
|
||||
void GraphControl::onMouseDown(wxMouseEvent& ev) {
|
||||
if (!graph) return;
|
||||
wxSize cs = GetClientSize();
|
||||
graph->findItem(RealPoint((double)ev.GetX()/cs.GetWidth(), (double)ev.GetY()/cs.GetHeight()), current_item);
|
||||
if (graph->findItem(RealPoint(ev.GetX(), ev.GetY()), RealRect(RealPoint(0,0),cs), current_item)) {
|
||||
Refresh(false);
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(GraphControl, wxControl)
|
||||
|
||||
+14
-11
@@ -83,9 +83,9 @@ class GraphData {
|
||||
class Graph {
|
||||
public:
|
||||
/// Draw this graph, filling the internalRect() of the dc.
|
||||
virtual void draw(RotatedDC& dc) const = 0;
|
||||
/// Find the item at the given position, position is normalized to [0..1)
|
||||
virtual bool findItem(const RealPoint& pos, vector<int>& out) const { return false; }
|
||||
virtual void draw(RotatedDC& dc, const vector<int>& current) const = 0;
|
||||
/// Find the item at the given position, the rectangle gives the screen size
|
||||
virtual bool findItem(const RealPoint& pos, const RealRect& rect, vector<int>& out) const { return false; }
|
||||
/// Change the data
|
||||
virtual void setData(const GraphDataP& d) { data = d; }
|
||||
|
||||
@@ -98,19 +98,22 @@ class Graph {
|
||||
class Graph1D : public Graph {
|
||||
public:
|
||||
inline Graph1D(size_t axis) : axis(axis) {}
|
||||
virtual bool findItem(const RealPoint& pos, vector<int>& out) const;
|
||||
virtual void draw(RotatedDC& dc, const vector<int>& current) const;
|
||||
virtual bool findItem(const RealPoint& pos, const RealRect& rect, vector<int>& out) const;
|
||||
protected:
|
||||
size_t axis;
|
||||
/// Find an item, return the position along the axis, or -1 if not found
|
||||
virtual int findItem(const RealPoint& pos) const = 0;
|
||||
virtual int findItem(const RealPoint& pos, const RealRect& rect) const = 0;
|
||||
virtual void draw(RotatedDC& dc, int current) const = 0;
|
||||
inline GraphAxis& axis_data() const { return *data->axes.at(axis); }
|
||||
};
|
||||
|
||||
/// A bar graph
|
||||
class BarGraph : public Graph1D {
|
||||
public:
|
||||
inline BarGraph(size_t axis) : Graph1D(axis) {}
|
||||
virtual void draw(RotatedDC& dc) const;
|
||||
virtual int findItem(const RealPoint& pos) const;
|
||||
virtual void draw(RotatedDC& dc, int current) const;
|
||||
virtual int findItem(const RealPoint& pos, const RealRect& rect) const;
|
||||
};
|
||||
|
||||
// TODO
|
||||
@@ -121,16 +124,16 @@ class BarGraph : public Graph1D {
|
||||
class PieGraph : public Graph1D {
|
||||
public:
|
||||
inline PieGraph(size_t axis) : Graph1D(axis) {}
|
||||
virtual void draw(RotatedDC& dc) const;
|
||||
virtual int findItem(const RealPoint& pos) const;
|
||||
virtual void draw(RotatedDC& dc, int current) const;
|
||||
virtual int findItem(const RealPoint& pos, const RealRect& rect) const;
|
||||
};
|
||||
|
||||
/// The legend, used for pie graphs
|
||||
class GraphLegend : public Graph1D {
|
||||
public:
|
||||
inline GraphLegend(size_t axis) : Graph1D(axis) {}
|
||||
virtual void draw(RotatedDC& dc) const;
|
||||
virtual int findItem(const RealPoint& pos) const;
|
||||
virtual void draw(RotatedDC& dc, int current) const;
|
||||
virtual int findItem(const RealPoint& pos, const RealRect& rect) const;
|
||||
};
|
||||
|
||||
//class GraphTable {
|
||||
|
||||
Reference in New Issue
Block a user