-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrapherView.cpp
More file actions
77 lines (61 loc) · 2.43 KB
/
Copy pathGrapherView.cpp
File metadata and controls
77 lines (61 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <thread>
#include "GrapherView.h"
#include <Ixtli/Graphics/PathEffect.h>
using namespace Ixtli;
GrapherView::GrapherView() : View(){
setBackgroundColor(Color::parse("#222222"));
graphWindow = new Grapher2D(getWidth(), getHeight());
//std::cout << "GRAPHER VIEW create window with size" << Point2D<int>(width(), height()) << std::endl;
graphAxisPaint = Paint().setColor(Color::WHITE).setStrokeWidth(1.7f).setTextSize(10.0f);
graphPrimaryGridLinesPaint =
Paint()
.setColor(Color::GRAY)
.setStrokeWidth(1.5)
.setPathEffect(PathEffect().setFactor(3).setPattern(0xCCCC));
graphSecondaryGridLinesPaint =
Paint()
.setColor(Color::DARK_GRAY)
.setStrokeWidth(1)
.setPathEffect(PathEffect().setFactor(3).setPattern(0xAAAA));
graphWindow->invalidate();
}
void GrapherView::onSizeChanged(int w, int h, int oldW, int oldH){
//std::cout << "GraphView viewport: " << getViewport() << std::endl;
graphWindow->onViewSizeChanged(w, h);
invalidate();
//std::cout << "GRAPHER VIEW resized window to " << Point2D<int>(width(), height()) << std::endl;
//std::cout << "GRAPHER VIEW resized viewport change " << getViewport() << std::endl;
}
void GrapherView::setExpressionType(size_t idx, Equation2D::Type type)
{
graphWindow->setGraphExpression(idx, graphWindow->getExpression(idx), type);
}
void GrapherView::onDraw(Canvas& canvas){
graphWindow->drawGridTo(canvas, graphAxisPaint, graphPrimaryGridLinesPaint, graphSecondaryGridLinesPaint);
graphWindow->drawTo(canvas);
graphWindow->drawGridValuesTo(canvas, graphAxisPaint);
}
void GrapherView::onMouseEvent(MouseButton button, MouseAction action, int x, int y){
static MouseAction lastAction = MouseAction::NONE;
static Point2D<int> lastPoint(0,0);
Point p(x, y);
if(action == MouseAction::MOVE){
if(lastAction == MouseAction::PRESSED_DOWN){
lastPoint = p;
}else if(lastAction == MouseAction::MOVE){
if(lastPoint != p){
auto offset = p - lastPoint;
graphWindow->translateWindow(offset);
invalidate();
}
}
}else if(action == MouseAction::SCROLL_DOWN){
graphWindow->scale(1.2f, p);
invalidate();
}else if(action == MouseAction::SCROLL_UP){
graphWindow->scale(0.833f, p);
invalidate();
}
lastPoint = p;
lastAction = action;
}