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 {
|
||||
|
||||
+2
-20
@@ -124,7 +124,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
|
||||
addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8"), _("Keywords"), _("Keywords"), _("Define extra keywords for this set"));
|
||||
addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 3, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set"));
|
||||
// addPanel(*s, *menuWindow, *tabBar, new DraftPanel (&this, wxID_ANY), 4, _("F10"))
|
||||
selectPanel(ID_WINDOW_MIN + 0); // select cards panel
|
||||
selectPanel(ID_WINDOW_MIN + 4); // select cards panel
|
||||
|
||||
// loose ends
|
||||
tabBar->Realize();
|
||||
@@ -141,6 +141,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
|
||||
SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
|
||||
|
||||
setSet(set);
|
||||
current_panel->Layout();
|
||||
}
|
||||
|
||||
SetWindow::~SetWindow() {
|
||||
@@ -203,25 +204,6 @@ void SetWindow::selectPanel(int id) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Set actions
|
||||
|
||||
void SetWindow::onBeforeChangeSet() {
|
||||
// Make sure we don't own the set's scriptUpdater
|
||||
// if (set->scriptUpdater != &scriptUpdater) {
|
||||
// assert(!scriptUpdater.set);
|
||||
// return;
|
||||
// }
|
||||
// We do own the set's scriptUpdater
|
||||
// stop handling updates for the set
|
||||
// do this first, so events get send, which stop worker threads
|
||||
// scriptUpdater.setNullSet();
|
||||
// another window should take over the scriptUpdating
|
||||
// FOR_EACH(wnd, SetWindows) {
|
||||
// if (wnd != &this && wnd->getSet() == set) {
|
||||
// wnd->scriptUpdater.setSet(set);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void SetWindow::onChangeSet() {
|
||||
// make sure there is always at least one card
|
||||
// some things need this
|
||||
|
||||
@@ -76,8 +76,6 @@ class SetWindow : public wxFrame, public SetView {
|
||||
|
||||
// --------------------------------------------------- : Action related
|
||||
protected:
|
||||
/// We want to respond to set changes
|
||||
virtual void onBeforeChangeSet();
|
||||
/// We want to respond to set changes
|
||||
virtual void onChangeSet();
|
||||
/// Actions that change the set
|
||||
|
||||
+13
-6
@@ -40,6 +40,13 @@ void clearDC(DC& dc, const wxBrush& brush) {
|
||||
dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
|
||||
}
|
||||
|
||||
void clearDC_black(DC& dc) {
|
||||
#if !BITMAPS_DEFAULT_BLACK
|
||||
// On windows 9x it seems that bitmaps are not black by default
|
||||
clearDC(dc, *wxBLACK_BRUSH);
|
||||
#endif
|
||||
}
|
||||
|
||||
void draw_checker(RotatedDC& dc, const RealRect& rect) {
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(*wxWHITE_BRUSH);
|
||||
@@ -47,13 +54,13 @@ void draw_checker(RotatedDC& dc, const RealRect& rect) {
|
||||
dc.SetBrush(Color(235,235,235));
|
||||
const double checker_size = 10;
|
||||
int odd = 0;
|
||||
for (double y = 0 ; y < rect.size.height ; y += checker_size) {
|
||||
for (double x = odd * checker_size ; x < rect.size.width ; x += checker_size * 2) {
|
||||
for (double y = 0 ; y < rect.height ; y += checker_size) {
|
||||
for (double x = odd * checker_size ; x < rect.width ; x += checker_size * 2) {
|
||||
dc.DrawRectangle(RealRect(
|
||||
rect.position.x + x,
|
||||
rect.position.y + y,
|
||||
min(checker_size, rect.size.width - x),
|
||||
min(checker_size, rect.size.height - y)
|
||||
rect.x + x,
|
||||
rect.y + y,
|
||||
min(checker_size, rect.width - x),
|
||||
min(checker_size, rect.height - y)
|
||||
));
|
||||
}
|
||||
odd = 1 - odd;
|
||||
|
||||
+4
-1
@@ -26,7 +26,10 @@ int focused_control(const Window* window);
|
||||
// ----------------------------------------------------------------------------- : DC related
|
||||
|
||||
/// Fill a DC with a single color
|
||||
void clearDC(DC& dc, const wxBrush& brush = *wxBLACK_BRUSH);
|
||||
void clearDC(DC& dc, const wxBrush& brush);
|
||||
|
||||
/// Fill a newly allocated DC with black, if the platform doesn't do so automaticly
|
||||
void clearDC_black(DC& dc);
|
||||
|
||||
/// Draw a checkerboard pattern
|
||||
void draw_checker(RotatedDC& dc, const RealRect&);
|
||||
|
||||
Reference in New Issue
Block a user