mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[wip] Clean Rect and drawing
This commit is contained in:
committed by
Émilie Feral
parent
d71ad9b288
commit
a0319905d7
@@ -61,6 +61,12 @@ mp_obj_t modpyplot_axis(mp_obj_t arg) {
|
||||
return mp_obj_new_tuple(4, coords);
|
||||
}
|
||||
|
||||
mp_obj_t modpyplot_bar(mp_obj_t x, mp_obj_t height) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
mp_obj_t modpyplot_grid(mp_obj_t b) {
|
||||
if (mp_obj_is_type(b, &mp_type_bool)) {
|
||||
sPlotStore->setGridRequested(mp_obj_is_true(b));
|
||||
|
||||
@@ -4,6 +4,7 @@ mp_obj_t modpyplot___init__();
|
||||
void modpyplot_gc_collect();
|
||||
|
||||
mp_obj_t modpyplot_axis(mp_obj_t arg);
|
||||
mp_obj_t modpyplot_bar(mp_obj_t x, mp_obj_t height);
|
||||
mp_obj_t modpyplot_grid(mp_obj_t b);
|
||||
mp_obj_t modpyplot_plot(mp_obj_t x, mp_obj_t y);
|
||||
mp_obj_t modpyplot_scatter(mp_obj_t x, mp_obj_t y);
|
||||
|
||||
@@ -79,6 +79,27 @@ public:
|
||||
void addSegment(mp_obj_t xStart, mp_obj_t yStart, mp_obj_t xEnd, mp_obj_t yEnd, KDColor c);
|
||||
Iterable<ListIterator<Segment>> segments() { return Iterable<ListIterator<Segment>>(m_segments); }
|
||||
|
||||
// Rect
|
||||
|
||||
class Rect {
|
||||
public:
|
||||
Rect(mp_obj_t tuple);
|
||||
float x() const { return m_x; }
|
||||
float y() const { return m_y; }
|
||||
float width() const { return m_width; }
|
||||
float height() const { return m_height; }
|
||||
KDColor color() const { return m_color; }
|
||||
private:
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_width;
|
||||
float m_height;
|
||||
KDColor m_color;
|
||||
};
|
||||
|
||||
void addRect(mp_obj_t x, mp_obj_t y, mp_obj_t width, mp_obj_t height, KDColor c);
|
||||
Iterable<ListIterator<Rect>> rects() { return Iterable<ListIterator<Rect>>(m_segments); }
|
||||
|
||||
// Label
|
||||
|
||||
class Label {
|
||||
|
||||
@@ -16,26 +16,49 @@ void PlotView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
}
|
||||
|
||||
for (PlotStore::Dot dot : m_store->dots()) {
|
||||
drawDot(ctx, rect, dot.x(), dot.y(), dot.color());
|
||||
traceDot(ctx, rect, dot);
|
||||
}
|
||||
|
||||
for (PlotStore::Label label : m_store->labels()) {
|
||||
drawLabel(ctx, rect,
|
||||
label.x(), label.y(), label.string(),
|
||||
KDColorBlack,
|
||||
CurveView::RelativePosition::Before,
|
||||
CurveView::RelativePosition::None
|
||||
);
|
||||
traceLabel(ctx, rect, label);
|
||||
}
|
||||
|
||||
for (PlotStore::Segment segment : m_store->segments()) {
|
||||
drawSegment2(
|
||||
ctx, rect,
|
||||
segment.xStart(), segment.yStart(),
|
||||
segment.xEnd(), segment.yEnd(),
|
||||
segment.color()
|
||||
);
|
||||
traceSegment(ctx, rect, segment);
|
||||
}
|
||||
}
|
||||
|
||||
void PlotView::traceDot(KDContext * ctx, KDRect r, PlotStore::Dot dot) const {
|
||||
drawDot(ctx, r, dot.x(), dot.y(), dot.color());
|
||||
}
|
||||
|
||||
void PlotView::traceSegment(KDContext * ctx, KDRect r, PlotStore::Segment segment) const {
|
||||
drawSegment2(
|
||||
ctx, r,
|
||||
segment.xStart(), segment.yStart(),
|
||||
segment.xEnd(), segment.yEnd(),
|
||||
segment.color()
|
||||
);
|
||||
}
|
||||
|
||||
void PlotView::traceRect(KDContext * ctx, KDRect r, PlotStore::Rect rect) const {
|
||||
KDRect pixelRect(
|
||||
floatToPixel(Axis::Horizontal, rect.x()),
|
||||
floatToPixel(Axis::Vertical, rect.y()),
|
||||
rect.width() / pixelWidth(),
|
||||
rect.height() / pixelHeight()
|
||||
);
|
||||
ctx->fillRect(pixelRect, rect.color());
|
||||
}
|
||||
|
||||
void PlotView::traceLabel(KDContext * ctx, KDRect r, PlotStore::Label label) const {
|
||||
drawLabel(ctx, r,
|
||||
label.x(), label.y(), label.string(),
|
||||
KDColorBlack,
|
||||
RelativePosition::Before,
|
||||
RelativePosition::None
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ public:
|
||||
PlotView(PlotStore * s) : Shared::LabeledCurveView(s), m_store(s) {}
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
void traceDot(KDContext * ctx, KDRect r, PlotStore::Dot dot) const;
|
||||
void traceSegment(KDContext * ctx, KDRect r, PlotStore::Segment segment) const;
|
||||
void traceRect(KDContext * ctx, KDRect r, PlotStore::Rect rect) const;
|
||||
void traceLabel(KDContext * ctx, KDRect r, PlotStore::Label label) const;
|
||||
PlotStore * m_store;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user