blob: a73ffc8463d5641faf5cd6a42c5bba10f32ce5e2 (
plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKCANVASWIDGET_H_
#define SKCANVASWIDGET_H_
#include <QWidget>
#include <QHBoxLayout>
#include "SkStream.h"
#include "SkRasterWidget.h"
#include "SkGLWidget.h"
class SkCanvasWidget : public QWidget {
Q_OBJECT
public:
SkCanvasWidget(QWidget* parent);
~SkCanvasWidget() {}
enum WidgetType {
kRaster_8888_WidgetType = 1 << 0,
kGPU_WidgetType = 1 << 1,
};
/**
Returns the visibility of the command at the specified index.
@param index The index of the draw command
*/
bool commandIsVisibleAtIndex(int index) {
return fDebugCanvas->getDrawCommandVisibilityAt(index);
}
/**
Toggles the visibility / execution of the draw command at index i with
the value of toggle.
*/
void setCommandVisibliltyAtIndex(int index, bool toggle) {
fDebugCanvas->toggleCommand(index, toggle);
}
/**
Returns a vector of strings with all the current canvas draw
commands.
*/
std::vector<std::string>* getDrawCommands() {
return fDebugCanvas->getDrawCommandsAsStrings();
}
SkDebugCanvas* getCurrentDebugCanvas() {
return fDebugCanvas;
}
void drawTo(int index);
void setWidgetVisibility(WidgetType type, bool isHidden);
/**
Toggles drawing filter on all drawing commands previous to current.
*/
void toggleCurrentCommandFilter(bool toggle) {
fDebugCanvas->toggleFilter(toggle);
}
/**
TODO(chudy): Refactor into a struct of char**
Returns parameter information about the ith draw command.
@param: i The index of the draw command we are accessing
*/
std::vector<std::string>* getCurrentCommandInfo(int i) {
return fDebugCanvas->getCommandInfoAt(i);
}
const SkMatrix& getCurrentMatrix() {
return fRasterWidget.getCurrentMatrix();
}
const SkIRect& getCurrentClip() {
return fRasterWidget.getCurrentClip();
}
void loadPicture(QString filename);
// TODO(chudy): Not full proof since fRasterWidget isn't always drawn to.
int getBitmapHeight() {
return fRasterWidget.getBitmapHeight();
}
int getBitmapWidth() {
return fRasterWidget.getBitmapWidth();
}
SkRasterWidget* getRasterWidget() {
return &fRasterWidget;
}
void zoom(float zoomIncrement);
signals:
void scaleFactorChanged(float newScaleFactor);
void commandChanged(int newCommand);
void hitChanged(int hit);
private slots:
void keyZoom(int zoomIncrement) {
zoom(zoomIncrement);
}
private:
QHBoxLayout fHorizontalLayout;
SkRasterWidget fRasterWidget;
SkGLWidget fGLWidget;
SkDebugCanvas* fDebugCanvas;
SkIPoint fPreviousPoint;
SkIPoint fTransform;
float fScaleFactor;
int fIndex;
enum TransformType {
kTranslate = 1 << 0,
kScale = 1 << 1,
};
void resetWidgetTransform();
void updateWidgetTransform(TransformType type);
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event) {
zoom(event->delta()/120);
}
};
#endif /* SKCANVASWIDGET_H_ */
|