23static constexpr IntersectResult intersect(
int xa,
int ya,
int wa,
int ha,
24 int xb,
int yb,
int wb,
int hb)
26 int x1 = std::max<int>(xa, xb);
27 int y1 = std::max<int>(ya, yb);
28 int x2 = std::min<int>(xa + wa, xb + wb);
29 int y2 = std::min<int>(ya + ha, yb + hb);
32 return {x1, y1, w, h};
37static constexpr void normalize(T& x, T& w)
53 SDL_Renderer* renderer;
54 std::optional<SDL_Rect> origClip;
61 ivec2 i_xy = round(xy);
auto [x, y] = i_xy;
62 ivec2 i_wh = round(wh);
auto [w, h] = i_wh;
63 normalize(x, w); normalize(y, h);
65 auto [xn, yn, wn, hn] = [&, x=x, y=y, w=w, h=h] {
66 if (SDL_RenderIsClipEnabled(renderer)) {
68 SDL_RenderGetClipRect(renderer, &*origClip);
70 return intersect(origClip->x, origClip->y, origClip->w, origClip->h,
76 SDL_Rect newClip = { Sint16(xn), Sint16(yn), Uint16(wn), Uint16(hn) };
77 SDL_RenderSetClipRect(renderer, &newClip);
82 SDL_RenderSetClipRect(renderer, origClip ? &*origClip :
nullptr);
97 std::optional<std::array<GLint, 4>> origClip;
105 normalize(x, w); normalize(y, h);
111 auto [iw, ih] = round(wh *
scale);
113 if (glIsEnabled(GL_SCISSOR_TEST) == GL_TRUE) {
115 glGetIntegerv(GL_SCISSOR_BOX, origClip->data());
116 auto [xn, yn, wn, hn] = intersect(
117 (*origClip)[0], (*origClip)[1], (*origClip)[2], (*origClip)[3],
119 glScissor(xn, yn, wn, hn);
121 glScissor(ix, iy, iw, ih);
122 glEnable(GL_SCISSOR_TEST);
129 glScissor((*origClip)[0], (*origClip)[1], (*origClip)[2], (*origClip)[3]);
131 glDisable(GL_SCISSOR_TEST);
141 , name(
std::move(name_))
147 widget->setParent(
this);
157 float widgetZ = widget->getZ();
158 if (subWidgets.empty() || (subWidgets.back()->getZ() <= widgetZ)) {
159 subWidgets.push_back(std::move(widget));
161 auto it =
begin(subWidgets);
162 while ((*it)->getZ() <= widgetZ) ++it;
163 subWidgets.insert(it, std::move(widget));
171 [](
const auto& p) {
return p.get(); });
172 subWidgets.erase(it);
178 auto it1 =
begin(subWidgets);
179 while (it1->get() != elem) ++it1;
181 float elemZ = elem->
getZ();
184 while ((it2 !=
end(subWidgets)) && ((*it2)->getZ() < elemZ)) ++it2;
186 rotate(it1, it1 + 1, it2);
191void OSDWidget::resortDown(OSDWidget* elem)
194 auto it1 =
begin(subWidgets);
195 float elemZ = elem->getZ();
196 while ((*it1)->getZ() <= elemZ) {
198 if (it1 ==
end(subWidgets))
return;
202 if ((it2 !=
begin(subWidgets)) && ((it2 - 1)->
get() == elem))
return;
203 while (it2->get() != elem) ++it2;
205 rotate(it1, it2, it2 + 1);
214 if (propName ==
"-type") {
216 }
else if (propName ==
"-mousecoord") {
218 }
else if (propName ==
"-x") {
220 }
else if (propName ==
"-y") {
222 }
else if (propName ==
"-z") {
236 }
else if (propName ==
"-relx") {
238 }
else if (propName ==
"-rely") {
240 }
else if (propName ==
"-scaled") {
242 if (scaled != scaled2) {
246 }
else if (propName ==
"-clip") {
248 }
else if (propName ==
"-suppressErrors") {
257 if (propName ==
"-type") {
259 }
else if (propName ==
"-x") {
261 }
else if (propName ==
"-y") {
263 }
else if (propName ==
"-z") {
265 }
else if (propName ==
"-relx") {
267 }
else if (propName ==
"-rely") {
269 }
else if (propName ==
"-scaled") {
271 }
else if (propName ==
"-clip") {
273 }
else if (propName ==
"-mousecoord") {
274 auto [x, y] = getMouseCoord();
276 }
else if (propName ==
"-suppressErrors") {
277 result = suppressErrors;
296 for (
auto& s : subWidgets) {
297 s->invalidateRecursive();
303 if (suppressErrors)
return true;
305 return p->needSuppressErrors();
314 std::optional<SDLScopedClip> scopedClip;
318 scopedClip.emplace(output, clipPos,
size);
321 for (
auto& s : subWidgets) {
322 s->paintSDLRecursive(output);
332 std::optional<GLScopedClip> scopedClip;
336 scopedClip.emplace(output, clipPos,
size);
339 for (
auto& s : subWidgets) {
340 s->paintGLRecursive(output);
361 + (trRelPos *
getSize(output));
363 out = p->transformPos(output, out,
getRelPos());
371 trPos = p->transformReverse(output, trPos);
380vec2 OSDWidget::getMouseCoord()
const
383 if (!videoSystem.getCursorEnabled()) {
399 return vec2(std::numeric_limits<float>::infinity());
404 throw CommandException(
405 "Can't get mouse coordinates: no window visible");
408 vec2 out = transformReverse(*output,
vec2(videoSystem.getMouseCoord()));
410 if ((
size[0] == 0.0f) || (
size[1] == 0.0f)) {
411 throw CommandException(
412 "-can't get mouse coordinates: "
413 "widget has zero width or height");
424 bbSize = bottomRight - topLeft;
constexpr TO checked_cast(FROM *from)
Based on checked_cast implementation from the book: C++ Coding Standard item 93: Avoid using static_c...
Represents the output window/screen of openMSX.
VideoSystem & getVideoSystem()
OutputSurface * getOutputSurface()
GLScopedClip(const GLScopedClip &)=delete
GLScopedClip(OutputSurface &output, vec2 xy, vec2 wh)
GLScopedClip & operator=(const GLScopedClip &)=delete
A frame buffer where pixels can be written to.
int getLogicalWidth() const
gl::vec2 getViewScale() const
gl::ivec2 getViewOffset() const
int getLogicalHeight() const
A frame buffer where pixels can be written to.
SDLScopedClip & operator=(const SDLScopedClip &)=delete
SDLScopedClip(const SDLScopedClip &)=delete
SDLScopedClip(OutputSurface &output, vec2 xy, vec2 wh)
bool getBoolean(Interpreter &interp) const
float getFloat(Interpreter &interp) const
void addListElement(const T &t)
mat4 rotate(float angle, const vec3 &axis)
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
constexpr mat4 scale(const vec3 &xyz)
This file implemented 3 utility functions:
const T & get(const Event &event)
bool is_sorted(ForwardRange &&range, Compare comp={}, Proj proj={})
size_t size(std::string_view utf8)
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)