Cursor.h
1/* Copyright (C) 2015 Laurentiu-Gheorghe Crisan
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 As a special exception, you may use this file as part of a free
9 software library without restriction. Specifically, if other files
10 instantiate templates or use macros or inline functions from this
11 file, or you compile this file and link it with other files to
12 produce an executable, this file does not by itself cause the
13 resulting executable to be covered by the GNU General Public
14 License. This exception does not however invalidate any other
15 reasons why the executable file might be covered by the GNU Library
16 General Public License.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 MA 02110-1301 USA
27*/
28
29#ifndef Pt_Forms_Cursor_h
30#define Pt_Forms_Cursor_h
31
32#include <Pt/Forms/Api.h>
33#include <Pt/Gfx/Image.h>
34#include <Pt/Gfx/Color.h>
35#include <Pt/Types.h>
36
37#include <vector>
38#include <string>
39
40namespace Pt {
41
42namespace Forms {
43
44class PT_FORMS_API Cursor
45{
46 public:
47 Cursor();
48
49 virtual ~Cursor();
50
51 const std::vector<Pt::uint8_t>& andRgb888() const
52 {
53 return _andMask;
54 }
55
56 const std::vector<Pt::uint8_t>& xorRgb888() const
57 {
58 return _xorMask;
59 }
60
61 size_t width() const
62 {
63 return _width;
64 }
65
66 size_t height() const
67 {
68 return _height;
69 }
70
71 size_t xHotspot() const
72 {
73 return _xHotspot;
74 }
75
76 size_t yHotspot() const
77 {
78 return _yHotspot;
79 }
80
81 void setXHotspot(size_t v)
82 {
83 _xHotspot = v;
84 }
85
86 void setYHotspot(size_t v)
87 {
88 _yHotspot = v;
89 }
90
91 void setName( const std::string& n)
92 {
93 _name = n;
94 }
95
96 const std::string& name() const
97 {
98 return _name;
99 }
100
101 bool empty() const
102 {
103 return _andMask.empty() || _width == 0 || _height == 0;
104 }
105
106 void clear()
107 {
108 _andMask.clear();
109 _xorMask.clear();
110 _width = 0;
111 _height = 0;
112 }
113
114 public:
115 static const Cursor& defaultCursor();
116 static const Cursor& arrowCursor();
117 static const Cursor& waitCursor();
118 static const Cursor& sizeNWSECursor();
119 static const Cursor& sizeNESWCursor();
120 static const Cursor& sizeWECursor();
121 static const Cursor& sizeNSCursor();
122 static const Cursor& moveCursor();
123
124 public:
125 static void fromImage( const Gfx::Image& image, Cursor& cursor );
126 static void loadCursor( const char* pngFile, const Gfx::Color& alphaColor, Cursor& cursor );
127 static void loadCursor( std::istream& pngStream, const Gfx::Color& alphaColor, Cursor& cursor );
128 static void loadCursor( const Pt::uint8_t* pngBuffer, const size_t streamSize, const Gfx::Color& alphaColor, Cursor& cursor );
129
130 private:
131 std::vector<Pt::uint8_t> _andMask;
132 std::vector<Pt::uint8_t> _xorMask;
133 size_t _width;
134 size_t _height;
135 size_t _xHotspot;
136 size_t _yHotspot;
137 std::string _name;
138};
139
140} // namespace
141
142} // namespace
143
144#endif // include guard
145
uint_type uint8_t
Unsigned 8-bit integer type.
Definition Api-Types.h:24
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33