diff --git a/core/core.hpp b/core/core.hpp index 7c235d2..002fefb 100644 --- a/core/core.hpp +++ b/core/core.hpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -203,6 +204,8 @@ struct Position { Position(); Position(signed x, signed y); + template + Position(X x, Y y) : Position((signed)x, (signed)y) {} explicit operator bool() const; auto operator==(const Position& source) const -> bool; @@ -230,6 +233,8 @@ struct Size { Size(); Size(signed width, signed height); + template + Size(W width, H height) : Size((signed)width, (signed)height) {} explicit operator bool() const; auto operator==(const Size& source) const -> bool; @@ -261,6 +266,8 @@ struct Geometry { Geometry(); Geometry(Position position, Size size); Geometry(signed x, signed y, signed width, signed height); + template + Geometry(X x, Y y, W width, H height) : Geometry((signed)x, (signed)y, (signed)width, (signed)height) {} explicit operator bool() const; auto operator==(const Geometry& source) const -> bool; diff --git a/gtk/widget/widget.cpp b/gtk/widget/widget.cpp index 8d7a783..e4474f7 100644 --- a/gtk/widget/widget.cpp +++ b/gtk/widget/widget.cpp @@ -41,7 +41,23 @@ auto pWidget::setFont(const Font& font) -> void { auto pWidget::setGeometry(Geometry geometry) -> void { if(!gtkWidget) return; if(gtkParent) gtk_fixed_move(GTK_FIXED(gtkParent), gtkWidget, geometry.x(), geometry.y()); - gtk_widget_set_size_request(gtkWidget, max(1, geometry.width()), max(1, geometry.height())); + if(geometry.width() < 1) geometry.setWidth (1); + if(geometry.height() < 1) geometry.setHeight(1); + gtk_widget_set_size_request(gtkWidget, geometry.width(), geometry.height()); + if(gtk_widget_get_realized(gtkWidget)) { + static bool locked = false; + if(!locked) { + locked = true; + auto time = chrono::millisecond(); + while(chrono::millisecond() - time < 20) { + gtk_main_iteration_do(false); + if(gtkWidget->allocation.width != geometry.width ()) continue; + if(gtkWidget->allocation.height != geometry.height()) continue; + break; + } + locked = false; + } + } self().doSize(); } diff --git a/gtk/window.cpp b/gtk/window.cpp index ef0d43c..f4c7e05 100644 --- a/gtk/window.cpp +++ b/gtk/window.cpp @@ -266,6 +266,8 @@ auto pWindow::setFullScreen(bool fullScreen) -> void { gtk_window_unfullscreen(GTK_WINDOW(widget)); state().geometry = windowedGeometry; } + auto time = chrono::millisecond(); + while(chrono::millisecond() - time < 20) gtk_main_iteration_do(false); } auto pWindow::setGeometry(Geometry geometry) -> void { @@ -278,7 +280,12 @@ auto pWindow::setGeometry(Geometry geometry) -> void { gtk_window_set_geometry_hints(GTK_WINDOW(widget), GTK_WIDGET(widget), &geom, GDK_HINT_MIN_SIZE); gtk_widget_set_size_request(formContainer, geometry.width(), geometry.height()); + auto time1 = chrono::millisecond(); + while(chrono::millisecond() - time1 < 20) gtk_main_iteration_do(false); + gtk_window_resize(GTK_WINDOW(widget), geometry.width(), geometry.height() + _menuHeight() + _statusHeight()); + auto time2 = chrono::millisecond(); + while(chrono::millisecond() - time2 < 20) gtk_main_iteration_do(false); } auto pWindow::setModal(bool modal) -> void { diff --git a/gtk/window.hpp b/gtk/window.hpp index ac6fc84..132f294 100644 --- a/gtk/window.hpp +++ b/gtk/window.hpp @@ -44,8 +44,8 @@ struct pWindow : pObject { GtkWidget* gtkMenu = nullptr; GtkWidget* gtkStatus = nullptr; GtkAllocation lastAllocation = {0}; - bool onSizePending = false; Geometry windowedGeometry{128, 128, 256, 256}; + bool onSizePending = false; }; } diff --git a/windows/widget/canvas.cpp b/windows/widget/canvas.cpp index 72278cb..99419c6 100644 --- a/windows/widget/canvas.cpp +++ b/windows/widget/canvas.cpp @@ -112,12 +112,12 @@ auto pCanvas::_paint() -> void { bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = -height; //GDI stores bitmaps upside now; negative height flips bitmap - bmi.bmiHeader.biSizeImage = pixels.size() * sizeof(uint32); + bmi.bmiHeader.biSizeImage = pixels.size() * sizeof(uint32_t); void* bits = nullptr; HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, nullptr, 0); if(bits) { - auto source = (const uint8*)pixels.data(); - auto target = (uint8*)bits; + auto source = (const uint8_t*)pixels.data(); + auto target = (uint8_t*)bits; for(auto n : range(width * height)) { target[0] = (source[0] * source[3]) / 255; target[1] = (source[1] * source[3]) / 255; @@ -155,7 +155,7 @@ auto pCanvas::_rasterize() -> void { pixels.resize(width * height); if(auto& icon = state().icon) { - memory::copy(pixels.data(), icon.data(), width * height * sizeof(uint32)); + memory::copy(pixels.data(), icon.data(), width * height * sizeof(uint32_t)); } else if(auto& gradient = state().gradient) { auto& colors = gradient.state.colors; image fill; @@ -163,7 +163,7 @@ auto pCanvas::_rasterize() -> void { fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value()); memory::copy(pixels.data(), fill.data(), fill.size()); } else { - uint32 color = state().color.value(); + uint32_t color = state().color.value(); for(auto& pixel : pixels) pixel = color; } }