-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvasview.hpp
121 lines (90 loc) · 3.84 KB
/
canvasview.hpp
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
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Copyright (c) 2020-2024 plan44.ch / Lukas Zeller, Zurich, Switzerland
//
// Author: Lukas Zeller <[email protected]>
//
// This file is part of p44lrgraphics.
//
// p44lrgraphics is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// p44lrgraphics is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with p44lrgraphics. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _p44lrgraphics_canvasview_hpp__
#define _p44lrgraphics_canvasview_hpp__
#include "p44lrg_common.hpp"
#include "coloreffectview.hpp"
namespace p44 {
class CanvasView : public ColorEffectView
{
typedef ColorEffectView inherited;
PixelColor* mCanvasBuffer;
size_t mNumPixels;
public :
CanvasView();
virtual ~CanvasView();
static const char* staticTypeName() { return "canvas"; };
static P44View* newInstance() { return new CanvasView; };
virtual const char* getTypeName() const P44_OVERRIDE { return staticTypeName(); }
/// clear the content to all pixels transparent
virtual void clear() P44_OVERRIDE;
/// set pixel
void setPixel(PixelColor aColor, PixelCoord aPixelIndex);
void setPixel(PixelColor aColor, PixelPoint aPixelPoint);
/// draw line in foreground color (using gradient if enabled)
void drawLine(PixelPoint aStart, PixelPoint aEnd);
/// copy pixels in specified rectangle
/// @param aSourceView if set to nullptr, copying is from myself. Otherwise, pixels are copied from specified view
/// @param aFromContent if set, pixels are copied from content, otherwise from frame (including scroll/rotate/zoom transforms)
/// @param aSrcRect where from to copy the pixels (in aSourceView coordinates)
/// @param aDestOrigin where to copy the pixels to (bottom left)
/// @param aNonTransparentOnly if set, only non-fully-transparent pixels are copied
void copyPixels(P44ViewPtr aSourceView, bool aFromContent, PixelRect aSrcRect, PixelPoint aDestOrigin, bool aNonTransparentOnly);
/// color effect params have changed
virtual void recalculateColoring() P44_OVERRIDE;
/// @name trivial property getters/setters
/// @{
size_t getNumPixels() { return mNumPixels; }
size_t getCanvasBytes() { return mNumPixels*sizeof(PixelColor); }
/// @}
#if ENABLE_VIEWCONFIG && !ENABLE_P44SCRIPT
/// configure view from JSON
virtual ErrorPtr configureView(JsonObjectPtr aViewConfig) P44_OVERRIDE;
#endif // ENABLE_VIEWCONFIG && !ENABLE_P44SCRIPT
#if ENABLE_P44SCRIPT
/// @return ScriptObj representing this view
virtual P44Script::ScriptObjPtr newViewObj() P44_OVERRIDE;
#endif
/// get content color at aPt
virtual PixelColor contentColorAt(PixelPoint aPt) P44_OVERRIDE;
protected:
/// geometry has changed
virtual void geometryChanged(PixelRect aOldFrame, PixelRect aOldContent) P44_OVERRIDE;
private:
void clearData();
void resize();
};
typedef boost::intrusive_ptr<CanvasView> CanvasViewPtr;
#if ENABLE_P44SCRIPT
namespace P44Script {
/// represents a CanvasView
class CanvasViewObj : public ColorEffectViewObj
{
typedef ColorEffectViewObj inherited;
public:
CanvasViewObj(P44ViewPtr aView);
CanvasViewPtr canvas() { return boost::static_pointer_cast<CanvasView>(inherited::view()); };
};
} // namespace P44Script
#endif // ENABLE_P44SCRIPT
} // namespace p44
#endif /* _p44lrgraphics_canvasview_hpp__ */