/usr/lib/Wt/examples/widgetgallery/PaintBrush.C is in witty-examples 3.1.10-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #include <boost/lexical_cast.hpp>
#include <iostream>
#include "PaintBrush.h"
#include <Wt/WCssDecorationStyle>
#include <Wt/WPainter>
#include <Wt/WPainterPath>
#include <Wt/WPointF>
#include <Wt/WRectF>
PaintBrush::PaintBrush(int width, int height, WContainerWidget *parent)
: WPaintedWidget(parent)
{
setSelectable(false);
resize(WLength(width), WLength(height));
decorationStyle().setCursor("icons/pencil.cur", CrossCursor);
mouseDragged().connect(this, &PaintBrush::mouseDrag);
mouseWentDown().connect(this, &PaintBrush::mouseDown);
touchStarted().connect(this, &PaintBrush::touchStart);
touchMoved().connect(this, &PaintBrush::touchMove);
touchMoved().preventDefaultAction();
color_ = WColor(black);
// setPreferredMethod(InlineSvgVml);
}
void PaintBrush::paintEvent(WPaintDevice *paintDevice)
{
WPainter painter(paintDevice);
painter.setRenderHint(WPainter::Antialiasing);
WPen pen;
pen.setWidth(3);
pen.setColor(color_);
painter.setPen(pen);
painter.drawPath(path_);
path_ = WPainterPath(path_.currentPosition());
}
void PaintBrush::mouseDown(const WMouseEvent& e)
{
Coordinates c = e.widget();
path_ = WPainterPath(WPointF(c.x, c.y));
}
void PaintBrush::touchStart(const WTouchEvent& e)
{
Coordinates c = e.touches()[0].widget();
path_ = WPainterPath(WPointF(c.x, c.y));
}
void PaintBrush::mouseDrag(const WMouseEvent& e)
{
Coordinates c = e.widget();
path_.lineTo(c.x, c.y);
update(PaintUpdate);
}
void PaintBrush::touchMove(const WTouchEvent& e)
{
Coordinates c = e.touches()[0].widget();
path_.lineTo(c.x, c.y);
update(PaintUpdate);
}
|