Gamp v0.0.7-36-g24b1eb6
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
gamp_wt.cpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright Gothel Software e.K.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11
12#include <gamp/GampTypes.hpp>
13#include <gamp/wt/Surface.hpp>
15#include <gamp/wt/Window.hpp>
17#include <stdexcept>
18#include <jau/basic_types.hpp>
19
20using namespace jau;
21using namespace gamp::wt::event;
22
24 public:
25 /** min. unicode value, inclusive */
26 uint16_t min;
27 /** max. unicode value, inclusive */
28 uint16_t max;
29 /** true if valid for keyChar values as well, otherwise only valid for keyCode and keySym due to collision. */
31
32 constexpr NonPrintableRange(uint16_t min_, uint16_t max_, bool inclKeyChar_) noexcept
33 : min(min_), max(max_), inclKeyChar(inclKeyChar_) {}
34};
35
36/**
37 * Non printable key ranges, currently fixed to an array of size 4.
38 * <p>
39 * Not included, queried upfront:
40 * <ul>
41 * <li>{@link #BACK_SPACE}</li>
42 * <li>{@link #TAB}</li>
43 * <li>{@link #ENTER}</li>
44 * </ul>
45 * </p>
46 */
47static constexpr NonPrintableRange nonPrintableKeys[] = {
48 { 0x0000, 0x001F, true }, // Unicode: Non printable controls: [0x00 - 0x1F], see exclusion above
49 { 0x0061, 0x0078, false}, // Small 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym - Re-used for Fn (collision)
50 { 0x008F, 0x009F, true }, // Unicode: Non printable controls: [0x7F - 0x9F], Numpad keys [0x7F - 0x8E] are printable!
51 { 0xE000, 0xF8FF, true } // Unicode: Private 0xE000 - 0xF8FF (Marked Non-Printable)
52};
53
54
55bool gamp::wt::event::isPrintableKey(uint16_t uniChar, bool isKeyChar) noexcept {
56 const VKeyCode uniCode = VKeyCode(uniChar);
57 if ( VKeyCode::VK_BACK_SPACE == uniCode || VKeyCode::VK_TAB == uniCode || VKeyCode::VK_ENTER == uniCode ) {
58 return true;
59 }
60 if( !isKeyChar ) {
61 if( ( /*nonPrintableKeys[0].min <= uniChar && */ uniChar <= nonPrintableKeys[0].max ) ||
62 ( nonPrintableKeys[1].min <= uniChar && uniChar <= nonPrintableKeys[1].max ) ||
63 ( nonPrintableKeys[2].min <= uniChar && uniChar <= nonPrintableKeys[2].max ) ||
64 ( nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) ) {
65 return false;
66 }
67 } else {
68 if( ( /* nonPrintableKeys[0].inclKeyChar && nonPrintableKeys[0].min <= uniChar && */ uniChar <= nonPrintableKeys[0].max ) ||
69 ( nonPrintableKeys[1].inclKeyChar && nonPrintableKeys[1].min <= uniChar && uniChar <= nonPrintableKeys[1].max ) ||
70 ( nonPrintableKeys[2].inclKeyChar && nonPrintableKeys[2].min <= uniChar && uniChar <= nonPrintableKeys[2].max ) ||
71 ( nonPrintableKeys[3].inclKeyChar && nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) ) {
72 return false;
73 }
74 }
75 return VKeyCode::none != uniCode;
76}
77
79 if( !is_set(m_state, WindowState::visible) ) {
80 return;
81 }
82 const jau::math::Recti viewport(0, 0, surfaceSize().x, surfaceSize().y);
83 const WindowRef& self = shared();
84 for(const RenderListenerRef& l : *m_render_listener.snapshot()) {
85 std::exception_ptr eptr;
86 try {
88 bool initOK = ctx && ctx->isValid();
89 if( initOK ) {
90 if( is_set(l->pendingActions(), RenderActions::init) ) {
91 if( l->init(self, when) ) {
92 write(l->pendingActions(), RenderActions::init, false);
93 } else {
94 initOK = false;
95 }
96 }
97 }
98 if( initOK ) {
99 if( is_set(l->pendingActions(), RenderActions::reshape) ) {
100 ::glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
101 l->reshape(self, viewport, when);
102 write(l->pendingActions(), RenderActions::reshape, false);
103 }
104 l->display(self, when);
105 }
106 } catch (const std::exception &e) {
107 eptr = std::current_exception();
108 ERR_PRINT2("Caught exception %s", e.what());
109 } catch (...) {
110 eptr = std::current_exception();
111 ERR_PRINT2("Caught unknown exception");
112 }
113 if( eptr ) {
114 try {
115 RenderListenerRef l2 = l;
116 m_render_listener.erase_if(false,
117 [l](const RenderListenerRef& a) noexcept -> bool { return a.get() == l.get(); } );
118 l2->dispose(self, when);
119 } catch (const std::exception &e) {
120 ERR_PRINT2("Caught exception %s", e.what());
121 } catch (...) {
122 ERR_PRINT2("Caught unknown exception");
123 }
124 WARN_PRINT("Removed listener (sz %zu)", m_render_listener.size());
125 }
126 }
127}
128
129void gamp::wt::Window::disposeRenderListener(bool clearRenderListener, const jau::fraction_timespec& when) noexcept {
130 const WindowRef& self = shared();
131 for(const RenderListenerRef& l : *m_render_listener.snapshot()) {
132 try {
133 l->dispose(self, when);
134 write(l->pendingActions(), RenderActions::init, true);
135 write(l->pendingActions(), RenderActions::reshape, true);
136 } catch (std::exception &err) {
137 ERR_PRINT("Window::display: %s: Caught exception %s", toString().c_str(), err.what());
138 }
139 }
140 if( clearRenderListener ) {
141 m_render_listener.clear(true);
142 }
143}
144
145std::string gamp::wt::Window::toString() const noexcept {
146 std::string res = "Window[";
147 res.append(to_string(m_state))
148 .append(", handle ").append(jau::to_hexstring(m_window_handle))
149 .append(", bounds ").append(m_window_bounds.toString())
150 .append(", listener[render ").append(std::to_string(m_render_listener.size()))
151 .append(", window ").append(std::to_string(windowListenerCount()))
152 .append(", key ").append(std::to_string(keyListenerCount()))
153 .append("], ").append(Surface::toString())
154 .append("]");
155 return res;
156}
uint16_t max
max.
Definition gamp_wt.cpp:28
uint16_t min
min.
Definition gamp_wt.cpp:26
constexpr NonPrintableRange(uint16_t min_, uint16_t max_, bool inclKeyChar_) noexcept
Definition gamp_wt.cpp:32
bool inclKeyChar
true if valid for keyChar values as well, otherwise only valid for keyCode and keySym due to collisio...
Definition gamp_wt.cpp:30
constexpr bool isValid() const noexcept
const gamp::render::RenderContext * renderContext() const noexcept
Definition Surface.hpp:129
std::string toString() const noexcept
Definition Surface.hpp:268
constexpr const Vec2i & surfaceSize() const noexcept
Returns the surface size of the client area excluding insets (window decorations) in pixel units.
Definition Surface.hpp:171
void display(const jau::fraction_timespec &when) noexcept
Definition gamp_wt.cpp:78
size_t windowListenerCount() const noexcept
Definition Window.hpp:297
const WindowRef shared()
Definition Window.hpp:227
std::string toString() const noexcept
Definition gamp_wt.cpp:145
size_t keyListenerCount() const noexcept
Definition Window.hpp:313
void disposeRenderListener(bool clearRenderListener, const jau::fraction_timespec &when) noexcept
Definition gamp_wt.cpp:129
constexpr value_type y() const noexcept
Definition recti.hpp:111
constexpr value_type height() const noexcept
Definition recti.hpp:113
constexpr value_type x() const noexcept
Definition recti.hpp:110
constexpr value_type width() const noexcept
Definition recti.hpp:112
#define ERR_PRINT(...)
Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
Definition debug.hpp:112
#define ERR_PRINT2(...)
Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
Definition debug.hpp:115
#define WARN_PRINT(...)
Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.
Definition debug.hpp:126
static constexpr NonPrintableRange nonPrintableKeys[]
Non printable key ranges, currently fixed to an array of size 4.
Definition gamp_wt.cpp:47
constexpr bool is_set(const E mask, const E bits) noexcept
constexpr E & write(E &store, const E bits, bool set) noexcept
If set==true, sets the bits in store, i.e.
VKeyCode
Virtual key code following UTF16 specification.
Definition KeyEvent.hpp:45
bool isPrintableKey(uint16_t uniChar, bool isKeyChar) noexcept
Returns true if given uniChar represents a printable character, i.e.
Definition gamp_wt.cpp:55
std::shared_ptr< RenderListener > RenderListenerRef
Definition Window.hpp:122
std::shared_ptr< Window > WindowRef
Definition Event.hpp:36
@ none
Alias for VK_UNDEFINED.
Definition KeyEvent.hpp:56
@ VK_BACK_SPACE
Constant for the BACK SPACE key "\b"u, matching ASCII.
Definition KeyEvent.hpp:76
@ VK_ENTER
Constant for the ENTER keyu, i.e.
Definition KeyEvent.hpp:91
@ VK_TAB
Constant for the HORIZ TAB key "\t"u, matching ASCII.
Definition KeyEvent.hpp:79
constexpr Vector2F< T > max(const Vector2F< T > &lhs, const Vector2F< T > &rhs) noexcept
Definition vec2f.hpp:398
constexpr Vector2F< T > min(const Vector2F< T > &lhs, const Vector2F< T > &rhs) noexcept
Definition vec2f.hpp:392
RectI< int > Recti
Definition recti.hpp:139
std::string to_string(const math_error_t v) noexcept
Returns std::string representation of math_error_t.
std::string to_hexstring(value_type const &v, const bool skipLeading0x=false) noexcept
Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given pointer.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition backtrace.hpp:32
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...