OpenCPN Partial API docs
Loading...
Searching...
No Matches
std_icon.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2025 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/ *
16 **************************************************************************/
17
24#include "model/svg_utils.h"
25#include "model/std_icon.h"
26
27static wxBitmap InvertColors(const wxBitmap& original) {
28 wxImage image = original.ConvertToImage();
29 unsigned char* data = image.GetData();
30 unsigned char* p_idata = data;
31 for (int i = 0; i < image.GetSize().y; i++) {
32 for (int j = 0; j < image.GetSize().x; j++) {
33 unsigned char v = *p_idata;
34 v = 255 - v;
35 *p_idata++ = v;
36 v = *p_idata;
37 v = 255 - v;
38 *p_idata++ = v;
39 v = *p_idata;
40 v = 255 - v;
41 *p_idata++ = v;
42 }
43 }
44 return wxBitmap(image);
45}
46
47StdIcon::StdIcon(const wxWindow* parent, const std::string& svg_file,
48 EventVar& color_change_evt, bool touch)
49 : m_color_change_evt(color_change_evt),
50 m_is_night(false),
51 m_day_bitmap(LoadSvgStdIcon(svg_file, parent, touch)),
52 m_night_bitmap(InvertColors(m_day_bitmap)),
53 m_bitmap(m_day_bitmap) {
54 m_color_change_lstnr.Init(m_color_change_evt, [&](const ObservedEvt& ev) {
55 m_bitmap = ev.GetInt() == 0 ? m_night_bitmap : m_day_bitmap;
56 });
57}
58
59const wxBitmap& StdIcon::GetBitmap() { return m_bitmap; }
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
void Init(const KeyProvider &kp, const std::function< void(ObservedEvt &ev)> &action)
Initiate an object yet not listening.
Definition observable.h:295
Custom event class for OpenCPN's notification system.
StdIcon(const wxWindow *parent, const std::string &svg_file, EventVar &color_change_evt, bool touch)
Create an icon.
Definition std_icon.cpp:47
const wxBitmap & GetBitmap()
Return bitmap, either day or inverted night variant.
Definition std_icon.cpp:59
Class StdIcon, typically a small monochrome svg icon.
SVG utilities.