LIBURANIA
GUI library (a wrapper of Win32 API) in C++
読み取り中…
検索中…
一致する文字列を見つけられません
paintdev.h
[詳解]
1/*
2 * Copyright 2002-2021 oZ/acy (名賀月晃嗣)
3 * Redistribution and use in source and binary forms,
4 * with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
45#ifndef INCLUDE_GUARD_URANIA_PAINTDEVICE_H
46#define INCLUDE_GUARD_URANIA_PAINTDEVICE_H
47
48// windows.hのmin/maxマクロの抑止
49#ifndef NOMINMAX
50#define NOMINMAX
51#endif
52
53#include <windows.h>
54#include <eunomia/picture.h>
55#include <eunomia/picture_indexed.h>
56
57namespace urania
58{
60 class Color
61 {
62 public:
63 std::uint8_t blue;
64 std::uint8_t green;
65 std::uint8_t red;
66
67 public:
68 constexpr Color() noexcept : blue(0), green(0), red(0) {}
69 constexpr Color(std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept
70 : blue(b), green(g), red(r)
71 {}
72 constexpr Color(const eunomia::RgbColour& org) noexcept
73 : blue(org.blue), green(org.green), red(org.red)
74 {}
75 constexpr explicit Color(COLORREF cr) noexcept
76 : blue(GetBValue(cr)), green(GetGValue(cr)), red(GetRValue(cr))
77 {}
78
79 Color& operator=(const eunomia::RgbColour& org) noexcept
80 {
81 red = org.red;
82 green = org.green;
83 blue = org.blue;
84 return *this;
85 }
86
87 constexpr COLORREF getColorref() const noexcept
88 {
89 return
90 (std::uint8_t)red
91 | ((std::uint8_t)green << 8)
92 | ((std::uint8_t)blue << 16);
93 }
94
95 constexpr operator eunomia::RgbColour() const noexcept
96 {
97 return eunomia::RgbColour(red, green, blue);
98 }
99 };
100
101
102 // class宣言
103 class PaintDevice;
104 class PaintMemDevice;
105 class PaintMemDeviceIndexed;
106
107
108}// end of namespace urania
109
110
111
112
116class urania::PaintMemDevice : public eunomia::ImageBuffer<urania::Color>
117{
119
120protected:
121 HDC hdc_;
122 HBITMAP oldbmp_;
123
124
125protected:
126 PaintMemDevice(unsigned ww, unsigned hh);
127
128public:
130
135 static std::unique_ptr<PaintMemDevice> create(unsigned w, unsigned h);
136
142 static
143 std::unique_ptr<PaintMemDevice> duplicate(const eunomia::Picture& pct);
144
148 std::unique_ptr<eunomia::Picture> duplicatePicture() const;
149
151 std::unique_ptr<PaintMemDevice> clone() const;
152};
153
154
155
159class urania::PaintMemDeviceIndexed : public eunomia::ImageBuffer<std::uint8_t>
160{
162
163protected:
164 HDC hdc_;
166 HPALETTE hpal_;
167 HBITMAP oldbmp_;
169
170 PaintMemDeviceIndexed(unsigned ww, unsigned hh);
171
172 public:
174
179 static std::unique_ptr<PaintMemDeviceIndexed> create(unsigned w, unsigned h);
180
186 static std::unique_ptr<PaintMemDeviceIndexed>
187 duplicate(const eunomia::PictureIndexed& pct);
188
192 std::unique_ptr<eunomia::PictureIndexed> duplicatePictureIndexed() const;
193
195 std::unique_ptr<PaintMemDeviceIndexed> clone() const;
196
197 urania::Color& palette(int id) { return pal_[id]; }
198 const urania::Color& palette(int id) const { return pal_[id]; }
199 urania::Color* paletteBuffer() noexcept { return pal_; }
200 const urania::Color* paletteBuffer() const noexcept { return pal_; }
201
203 void updatePalette();
204};
205
206
207
211class urania::PaintDevice : eunomia::Noncopyable<urania::PaintDevice>
212{
213public:
214 typedef void (*DestProc)(HDC, void*);
215
216protected:
217 HDC hdc_;
219
220 HBRUSH obr_;
221 HPEN opn_;
222 HFONT oft_;
223 int obm_;
224
225 void* app_;
227
228
229protected:
230 PaintDevice(HDC dc, DestProc dp, void* a, int w, int h);
231
232public:
233 ~PaintDevice();
234
235
243 static
244 std::unique_ptr<PaintDevice>
245 create(HDC dc, DestProc dp, void* a, int w, int h);
246
247
250 void clear(const urania::Color& col);
251
256 void dotset(int x, int y, const urania::Color& col);
257
264 void line(int x1, int y1, int x2, int y2, const urania::Color& col);
265
273 void box(
274 int x1, int y1, int x2, int y2, const urania::Color& col, bool f =false);
275
283 void ellipse(
284 int x, int y, int a, int b, const urania::Color& col, bool f =false);
285
292 void circle(int x, int y, int r, const urania::Color& col, bool f =false)
293 {
294 ellipse(x, y, r, r, col, f);
295 }
296
303 eunomia::Point
304 text(int x, int y, const std::wstring& str, const urania::Color& col);
305
313 eunomia::Point
314 text(int x, int y, int w, const std::wstring& str, const urania::Color& col);
315
325 void
327 int size, const std::wstring& fn, bool ro, bool fx,
328 bool bo, bool itl, bool ul, bool sk);
329
330
332 int width() const { return width_; }
333
335 int height() const { return height_; }
336
337
347 void blt(
348 const urania::PaintMemDevice& src, int sx, int sy, int w, int h,
349 int dx, int dy,
350 const std::optional<eunomia::Rect>& cliprect = std::nullopt);
351
361 void blt(
362 urania::PaintMemDeviceIndexed& src, int sx, int sy, int w, int h,
363 int dx, int dy,
364 const std::optional<eunomia::Rect>& cliprect = std::nullopt);
365
371 void stretchBlt(const urania::PaintMemDevice& src);
372
379
386 void blt(const urania::PaintMemDevice& src);
387
395
396
401 {
402 return Color(::GetSysColor(id));
403 }
404
408 static void setSysColor(int id, const urania::Color& col);
409
410
411private:
412 void changeBrush_(const urania::Color& col);
413 void changePen_(const urania::Color& col);
414};
415
416
417
418
419#endif // INCLUDE_GUARD_URANIA_PAINTDEVICE_H
Windows用BGRカラー構造體
Definition paintdev.h:61
Color & operator=(const eunomia::RgbColour &org) noexcept
Definition paintdev.h:79
std::uint8_t green
Definition paintdev.h:64
constexpr Color(COLORREF cr) noexcept
Definition paintdev.h:75
constexpr Color(const eunomia::RgbColour &org) noexcept
Definition paintdev.h:72
constexpr Color() noexcept
Definition paintdev.h:68
constexpr Color(std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept
Definition paintdev.h:69
std::uint8_t red
Definition paintdev.h:65
constexpr COLORREF getColorref() const noexcept
Definition paintdev.h:87
std::uint8_t blue
Definition paintdev.h:63
Definition paintdev.h:212
int width_
Definition paintdev.h:218
void blt(const urania::PaintMemDevice &src, int sx, int sy, int w, int h, int dx, int dy, const std::optional< eunomia::Rect > &cliprect=std::nullopt)
轉送
Definition pdev.cpp:115
void stretchBlt(const urania::PaintMemDevice &src)
轉送
Definition pdev.cpp:186
static std::unique_ptr< PaintDevice > create(HDC dc, DestProc dp, void *a, int w, int h)
Definition pdev.cpp:84
HFONT oft_
Definition paintdev.h:222
void circle(int x, int y, int r, const urania::Color &col, bool f=false)
Definition paintdev.h:292
HDC hdc_
Definition paintdev.h:217
DestProc dst_
Definition paintdev.h:226
void(* DestProc)(HDC, void *)
Definition paintdev.h:214
static void setSysColor(int id, const urania::Color &col)
システムカラーの設定
Definition pdev.cpp:95
void * app_
Definition paintdev.h:225
void dotset(int x, int y, const urania::Color &col)
Definition pdev2.cpp:138
PaintDevice(HDC dc, DestProc dp, void *a, int w, int h)
Definition pdev.cpp:45
int height() const
描畫領域の高さを取得する。
Definition paintdev.h:335
int width() const
描畫領域の幅を取得する。
Definition paintdev.h:332
eunomia::Point text(int x, int y, const std::wstring &str, const urania::Color &col)
Definition pdev2.cpp:150
void line(int x1, int y1, int x2, int y2, const urania::Color &col)
Definition pdev2.cpp:104
void clear(const urania::Color &col)
Definition pdev.cpp:103
int height_
Definition paintdev.h:218
void ellipse(int x, int y, int a, int b, const urania::Color &col, bool f=false)
Definition pdev2.cpp:118
int obm_
Definition paintdev.h:223
static urania::Color getSysColor(int id)
システムカラーの取得
Definition paintdev.h:400
HPEN opn_
Definition paintdev.h:221
void changeFont(int size, const std::wstring &fn, bool ro, bool fx, bool bo, bool itl, bool ul, bool sk)
Definition pdev2.cpp:217
HBRUSH obr_
Definition paintdev.h:220
void box(int x1, int y1, int x2, int y2, const urania::Color &col, bool f=false)
Definition pdev2.cpp:72
~PaintDevice()
Definition pdev.cpp:64
Definition paintdev.h:160
static std::unique_ptr< PaintMemDeviceIndexed > duplicate(const eunomia::PictureIndexed &pct)
PictureIndexedからのPaintMemDeviceIndexedの複製
Definition pmdidx.cpp:223
urania::Color oldpal_[256]
Definition paintdev.h:168
HDC hdc_
Definition paintdev.h:164
urania::Color pal_[256]
Definition paintdev.h:165
const urania::Color * paletteBuffer() const noexcept
Definition paintdev.h:200
urania::Color * paletteBuffer() noexcept
Definition paintdev.h:199
HPALETTE hpal_
Definition paintdev.h:166
static std::unique_ptr< PaintMemDeviceIndexed > create(unsigned w, unsigned h)
生成
Definition pmdidx.cpp:205
std::unique_ptr< PaintMemDeviceIndexed > clone() const
複製
Definition pmdidx.cpp:286
~PaintMemDeviceIndexed()
Definition pmdidx.cpp:160
urania::Color & palette(int id)
Definition paintdev.h:197
const urania::Color & palette(int id) const
Definition paintdev.h:198
std::unique_ptr< eunomia::PictureIndexed > duplicatePictureIndexed() const
PictureIndexed複製
Definition pmdidx.cpp:259
PaintMemDeviceIndexed(unsigned ww, unsigned hh)
Definition pmdidx.cpp:80
void updatePalette()
パレットハンドルを更新する。
Definition pmdidx.cpp:177
HBITMAP oldbmp_
Definition paintdev.h:167
PaintDevice互換メモリ上假想デバイス(24bit color)
Definition paintdev.h:117
HDC hdc_
Definition paintdev.h:121
static std::unique_ptr< PaintMemDevice > duplicate(const eunomia::Picture &pct)
PictureからのPaintMemDeviceの複製
Definition pmdev.cpp:124
PaintMemDevice(unsigned ww, unsigned hh)
Definition pmdev.cpp:43
~PaintMemDevice()
Definition pmdev.cpp:96
std::unique_ptr< eunomia::Picture > duplicatePicture() const
Picture複製
Definition pmdev.cpp:150
std::unique_ptr< PaintMemDevice > clone() const
複製
Definition pmdev.cpp:169
HBITMAP oldbmp_
Definition paintdev.h:122
static std::unique_ptr< PaintMemDevice > create(unsigned w, unsigned h)
生成
Definition pmdev.cpp:108
Definition clkpanel.h:43