2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkDebugCanvas.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QtGui>
|
|
|
|
#include <QWidget>
|
2012-07-03 16:05:59 +00:00
|
|
|
#include <QWheelEvent>
|
2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
/** \class SkCanvasWidget
|
|
|
|
|
|
|
|
The QtWidget encompasses all skia screen drawing elements. It initializes
|
|
|
|
an SkBitmap in memory that our SkCanvas draws to directly in memory.
|
|
|
|
Then using QImage and QPainter we draw those pixels on the screen in
|
|
|
|
this widget.
|
|
|
|
*/
|
|
|
|
class SkCanvasWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructs a widget with the specified parent for layout purposes.
|
|
|
|
@param parent The parent container of this widget
|
|
|
|
*/
|
|
|
|
SkCanvasWidget(QWidget *parent);
|
|
|
|
|
|
|
|
~SkCanvasWidget();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Executes all saved draw commands up to the specified index.
|
|
|
|
@param index The position of the command we draw up to.
|
|
|
|
*/
|
|
|
|
void drawTo(int index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the height of the bitmap.
|
|
|
|
*/
|
2012-07-03 16:05:59 +00:00
|
|
|
int getBitmapHeight() { return fBitmap.height(); }
|
2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Returns the width of the bitmap.
|
|
|
|
*/
|
2012-07-03 16:05:59 +00:00
|
|
|
int getBitmapWidth() { return fBitmap.width(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns an array of values of the current matrix.
|
|
|
|
*/
|
|
|
|
const SkMatrix& getCurrentMatrix() {
|
|
|
|
return fCanvas->getTotalMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns an array of values of the current bounding clip.
|
|
|
|
*/
|
|
|
|
const SkIRect& getCurrentClip() {
|
|
|
|
return fCanvas->getTotalClip().getBounds();
|
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a vector of strings with all the current canvas draw
|
|
|
|
commands.
|
|
|
|
*/
|
|
|
|
std::vector<std::string>* getDrawCommands() {
|
|
|
|
return fDebugCanvas->getDrawCommandsAsStrings();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Loads a skia picture located at filename.
|
|
|
|
@param filename The name of the file we are loading.
|
|
|
|
*/
|
|
|
|
void loadPicture(QString filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Toggles the visibility / execution of the draw command at index i.
|
|
|
|
*/
|
|
|
|
void toggleCommand(int index) {
|
|
|
|
fDebugCanvas->toggleCommand(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Toggles the visibility / execution of the draw command at index i with
|
|
|
|
the value of toggle.
|
|
|
|
*/
|
|
|
|
void toggleCommand(int index, bool toggle) {
|
|
|
|
fDebugCanvas->toggleCommand(index, toggle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Toggles drawing filter on all drawing commands previous to current.
|
|
|
|
*/
|
|
|
|
void toggleCurrentCommandFilter(bool toggle) {
|
|
|
|
fDebugCanvas->toggleFilter(toggle);
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:05:59 +00:00
|
|
|
/**
|
|
|
|
Captures mouse clicks
|
|
|
|
@param event The event intercepted by Qt
|
|
|
|
*/
|
|
|
|
void mouseMoveEvent(QMouseEvent* event);
|
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent* event);
|
|
|
|
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent* event);
|
|
|
|
|
|
|
|
void resizeEvent(QResizeEvent* event);
|
|
|
|
|
|
|
|
void wheelEvent(QWheelEvent* event);
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2012-07-09 20:26:53 +00:00
|
|
|
signals:
|
|
|
|
void scaleFactorChanged(float newScaleFactor);
|
|
|
|
void commandChanged(int newCommand);
|
2012-07-12 14:31:25 +00:00
|
|
|
void hitChanged(int hit);
|
2012-07-09 20:26:53 +00:00
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
Draws the current state of the widget.
|
|
|
|
@param event The event intercepted by Qt
|
|
|
|
*/
|
|
|
|
void paintEvent(QPaintEvent *event);
|
|
|
|
|
|
|
|
private:
|
2012-07-03 16:05:59 +00:00
|
|
|
SkBitmap fBitmap;
|
2012-06-29 14:21:22 +00:00
|
|
|
SkCanvas* fCanvas;
|
|
|
|
SkDebugCanvas* fDebugCanvas;
|
|
|
|
SkDevice* fDevice;
|
2012-07-03 16:05:59 +00:00
|
|
|
|
|
|
|
SkIPoint fPreviousPoint;
|
|
|
|
SkIPoint fTransform;
|
|
|
|
|
|
|
|
int fIndex;
|
2012-07-09 20:26:53 +00:00
|
|
|
float fScaleFactor;
|
2012-06-29 14:21:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|