From be94bf0185a038345882081b2d7663f883ee75ea Mon Sep 17 00:00:00 2001 From: James Grogan Date: Mon, 14 Nov 2022 15:31:38 +0000 Subject: [PATCH] More resizing --- src/graphics/opengl/OpenGlPainter.cpp | 7 +++++++ src/ui_elements/desktop_elements/IPlatformWindow.h | 2 ++ src/ui_elements/desktop_elements/Window.cpp | 7 +++++++ src/ui_elements/ui_events/ResizeEvent.cpp | 4 ++-- src/ui_elements/widgets/HorizontalSpacer.cpp | 2 ++ src/windows/managers/DesktopManager.cpp | 2 +- src/windows/ui_interfaces/wayland/WaylandSurface.h | 5 +++++ src/windows/ui_interfaces/x11/XcbGlWindowInterface.cpp | 6 ++++++ src/windows/ui_interfaces/x11/XcbGlWindowInterface.h | 2 ++ src/windows/ui_interfaces/x11/XcbWindow.cpp | 8 ++++++++ src/windows/ui_interfaces/x11/XcbWindow.h | 2 ++ 11 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/graphics/opengl/OpenGlPainter.cpp b/src/graphics/opengl/OpenGlPainter.cpp index 11fda56..32f9926 100644 --- a/src/graphics/opengl/OpenGlPainter.cpp +++ b/src/graphics/opengl/OpenGlPainter.cpp @@ -19,6 +19,8 @@ void OpenGlPainter::paint(DrawingContext* context) const auto width = double(surface->getWidth()); const auto height = double(surface->getHeight()); + std::cout << "Painting into width " << width << " and height " << height << std::endl; + const auto num_mesh = context->getScene()->getNumMeshes(); glClearColor(1.0, 1.0, 1.0, 0.0); @@ -55,6 +57,11 @@ void OpenGlPainter::paint(DrawingContext* context) glVertex3f(x1, y1, 0); glVertex3f(x2, y2, 0); + // std::cout << "Verts0| " << x0 << " | " << y0 << " | "<< std::endl; + // std::cout << "Verts1| " << x1 << " | " << y1 << " | "<< std::endl; + // std::cout << "Verts2| " << x2 << " | " << y2 << " | "<< std::endl; + // std::cout << "****************" << std::endl; + glEnd(); counter++; diff --git a/src/ui_elements/desktop_elements/IPlatformWindow.h b/src/ui_elements/desktop_elements/IPlatformWindow.h index f9f3841..2f46b54 100644 --- a/src/ui_elements/desktop_elements/IPlatformWindow.h +++ b/src/ui_elements/desktop_elements/IPlatformWindow.h @@ -33,6 +33,8 @@ public: virtual void clear() = 0; + virtual void onResize(unsigned width, unsigned height) = 0; + protected: mt::Window* mWindow{nullptr}; }; diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp index 0823b8c..835f01e 100644 --- a/src/ui_elements/desktop_elements/Window.cpp +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -15,6 +15,8 @@ #include "Screen.h" #include "Image.h" +#include + namespace mt { @@ -41,6 +43,11 @@ void Window::setSize(unsigned width, unsigned height) { DrawingSurface::setSize(width, height); mWidget->setBounds(width, height); + + if (mPlatformWindow) + { + mPlatformWindow->onResize(width, height); + } } void Window::clearPlatformWindow() diff --git a/src/ui_elements/ui_events/ResizeEvent.cpp b/src/ui_elements/ui_events/ResizeEvent.cpp index 5b84462..676d6a7 100644 --- a/src/ui_elements/ui_events/ResizeEvent.cpp +++ b/src/ui_elements/ui_events/ResizeEvent.cpp @@ -2,8 +2,8 @@ ResizeEvent::ResizeEvent(unsigned width, unsigned height) : UiEvent(), - mWidth(), - mHeight() + mWidth(width), + mHeight(height) { mType = UiEvent::Type::Resize; } diff --git a/src/ui_elements/widgets/HorizontalSpacer.cpp b/src/ui_elements/widgets/HorizontalSpacer.cpp index 239acc2..2fff101 100644 --- a/src/ui_elements/widgets/HorizontalSpacer.cpp +++ b/src/ui_elements/widgets/HorizontalSpacer.cpp @@ -2,6 +2,7 @@ #include #include +#include HorizontalSpacer::HorizontalSpacer() : Widget(), @@ -35,6 +36,7 @@ void HorizontalSpacer::addChildLayers(const PaintEvent* event) { height = mSize.mMaxHeight; } + for(std::size_t idx=0; idx(event); mWindowManager->onResizeEvent(resize_event); - //mModified = true; + mModified = true; break; } case (UiEvent::Type::Mouse): diff --git a/src/windows/ui_interfaces/wayland/WaylandSurface.h b/src/windows/ui_interfaces/wayland/WaylandSurface.h index 926f222..0a3bd58 100644 --- a/src/windows/ui_interfaces/wayland/WaylandSurface.h +++ b/src/windows/ui_interfaces/wayland/WaylandSurface.h @@ -34,6 +34,11 @@ public: void clear(); + void onResize(unsigned width, unsigned height) + { + + } + private: void initialize(); diff --git a/src/windows/ui_interfaces/x11/XcbGlWindowInterface.cpp b/src/windows/ui_interfaces/x11/XcbGlWindowInterface.cpp index 289c08b..40e0868 100644 --- a/src/windows/ui_interfaces/x11/XcbGlWindowInterface.cpp +++ b/src/windows/ui_interfaces/x11/XcbGlWindowInterface.cpp @@ -2,6 +2,7 @@ #include "XcbGlInterface.h" #include "FileLogger.h" +#include #include @@ -56,6 +57,11 @@ bool XcbGlWindowInterface::initialize(xcb_window_t window) return true; } +void XcbGlWindowInterface::resizeViewPort(unsigned width, unsigned height) +{ + glViewport(0, 0, width, height); +} + void XcbGlWindowInterface::destroyWindow() { glXDestroyWindow(mGlInterface->getDisplay(), mWindow); diff --git a/src/windows/ui_interfaces/x11/XcbGlWindowInterface.h b/src/windows/ui_interfaces/x11/XcbGlWindowInterface.h index 871af1f..b034f14 100644 --- a/src/windows/ui_interfaces/x11/XcbGlWindowInterface.h +++ b/src/windows/ui_interfaces/x11/XcbGlWindowInterface.h @@ -16,6 +16,8 @@ public: void afterPaint(); + void resizeViewPort(unsigned width, unsigned height); + private: void destroyWindow(); void swapBuffers(); diff --git a/src/windows/ui_interfaces/x11/XcbWindow.cpp b/src/windows/ui_interfaces/x11/XcbWindow.cpp index 04832e8..f4d8219 100644 --- a/src/windows/ui_interfaces/x11/XcbWindow.cpp +++ b/src/windows/ui_interfaces/x11/XcbWindow.cpp @@ -112,3 +112,11 @@ void XcbWindow::map() xcb_map_window(mConnection, mHandle); xcb_flush(mConnection); } + +void XcbWindow::onResize(unsigned width, unsigned height) +{ + if (mGlInterface) + { + mGlInterface->resizeViewPort(width, height); + } +} diff --git a/src/windows/ui_interfaces/x11/XcbWindow.h b/src/windows/ui_interfaces/x11/XcbWindow.h index d39063b..0f4fd83 100644 --- a/src/windows/ui_interfaces/x11/XcbWindow.h +++ b/src/windows/ui_interfaces/x11/XcbWindow.h @@ -34,6 +34,8 @@ public: void map() override; + void onResize(unsigned width, unsigned height) override; + private: int mHandle{-1}; unsigned mGraphicsContext {0};