From 22d1a5c34e17f9aa84932951bd7dceb85ecf5634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 17 Jan 2015 14:53:34 +0100 Subject: [PATCH] Platform: AbstractXApplication cleanup. Using std::unique_ptr instead of raw pointer, consistent private variable naming. --- src/Magnum/Platform/AbstractXApplication.cpp | 64 ++++++++++---------- src/Magnum/Platform/AbstractXApplication.h | 20 +++--- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Magnum/Platform/AbstractXApplication.cpp b/src/Magnum/Platform/AbstractXApplication.cpp index 00e2b6a03..f926abc5f 100644 --- a/src/Magnum/Platform/AbstractXApplication.cpp +++ b/src/Magnum/Platform/AbstractXApplication.cpp @@ -37,11 +37,11 @@ namespace Magnum { namespace Platform { -AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments& arguments, const Configuration& configuration): AbstractXApplication(contextHandler, arguments, nullptr) { +AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments& arguments, const Configuration& configuration): AbstractXApplication{contextHandler, arguments, nullptr} { createContext(configuration); } -AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {} +AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments&, std::nullptr_t): _contextHandler{contextHandler}, _flags{Flag::Redraw} {} void AbstractXApplication::createContext() { createContext({}); } @@ -50,92 +50,92 @@ void AbstractXApplication::createContext(const Configuration& configuration) { } bool AbstractXApplication::tryCreateContext(const Configuration& configuration) { - CORRADE_ASSERT(!c, "AbstractXApplication::tryCreateContext(): context already created", false); + CORRADE_ASSERT(!_context, "AbstractXApplication::tryCreateContext(): context already created", false); - viewportSize = configuration.size(); + _viewportSize = configuration.size(); /* Get default X display */ - display = XOpenDisplay(nullptr); + _display = XOpenDisplay(nullptr); /* Get visual ID */ - VisualID visualId = contextHandler->getVisualId(display); + VisualID visualId = _contextHandler->getVisualId(_display); /* Get visual info */ XVisualInfo *visInfo, visTemplate; int visualCount; visTemplate.visualid = visualId; - visInfo = XGetVisualInfo(display, VisualIDMask, &visTemplate, &visualCount); + visInfo = XGetVisualInfo(_display, VisualIDMask, &visTemplate, &visualCount); if(!visInfo) { Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot get X visual"; return false; } /* Create X Window */ - Window root = RootWindow(display, DefaultScreen(display)); + Window root = RootWindow(_display, DefaultScreen(_display)); XSetWindowAttributes attr; attr.background_pixel = 0; attr.border_pixel = 0; - attr.colormap = XCreateColormap(display, root, visInfo->visual, AllocNone); + attr.colormap = XCreateColormap(_display, root, visInfo->visual, AllocNone); attr.event_mask = 0; unsigned long mask = CWBackPixel|CWBorderPixel|CWColormap|CWEventMask; - window = XCreateWindow(display, root, 20, 20, configuration.size().x(), configuration.size().y(), 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr); - XSetStandardProperties(display, window, configuration.title().data(), nullptr, 0, nullptr, 0, nullptr); + _window = XCreateWindow(_display, root, 20, 20, configuration.size().x(), configuration.size().y(), 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr); + XSetStandardProperties(_display, _window, configuration.title().data(), nullptr, 0, nullptr, 0, nullptr); XFree(visInfo); /* Be notified about closing the window */ - deleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", True); - XSetWMProtocols(display, window, &deleteWindow, 1); + _deleteWindow = XInternAtom(_display, "WM_DELETE_WINDOW", True); + XSetWMProtocols(_display, _window, &_deleteWindow, 1); /* Create context */ - contextHandler->createContext(configuration, window); + _contextHandler->createContext(configuration, _window); /* Capture exposure, keyboard and mouse button events */ - XSelectInput(display, window, INPUT_MASK); + XSelectInput(_display, _window, INPUT_MASK); /* Set OpenGL context as current */ - contextHandler->makeCurrent(); + _contextHandler->makeCurrent(); - c = new Platform::Context; + _context.reset(new Platform::Context); return true; } AbstractXApplication::~AbstractXApplication() { - delete c; + _context.reset(); /* Shut down context handler */ - delete contextHandler; + _contextHandler.reset(); /* Shut down X */ - XDestroyWindow(display, window); - XCloseDisplay(display); + XDestroyWindow(_display, _window); + XCloseDisplay(_display); } void AbstractXApplication::swapBuffers() { - contextHandler->swapBuffers(); + _contextHandler->swapBuffers(); } int AbstractXApplication::exec() { /* Show window */ - XMapWindow(display, window); + XMapWindow(_display, _window); - while(!(flags & Flag::Exit)) { + while(!(_flags & Flag::Exit)) { XEvent event; /* Closed window */ - if(XCheckTypedWindowEvent(display, window, ClientMessage, &event) && - Atom(event.xclient.data.l[0]) == deleteWindow) { + if(XCheckTypedWindowEvent(_display, _window, ClientMessage, &event) && + Atom(event.xclient.data.l[0]) == _deleteWindow) { return 0; } - while(XCheckWindowEvent(display, window, INPUT_MASK, &event)) { + while(XCheckWindowEvent(_display, _window, INPUT_MASK, &event)) { switch(event.type) { /* Window resizing */ case ConfigureNotify: { Vector2i size(event.xconfigure.width, event.xconfigure.height); - if(size != viewportSize) { - viewportSize = size; + if(size != _viewportSize) { + _viewportSize = size; viewportEvent(size); - flags |= Flag::Redraw; + _flags |= Flag::Redraw; } } break; @@ -159,8 +159,8 @@ int AbstractXApplication::exec() { } } - if(flags & Flag::Redraw) { - flags &= ~Flag::Redraw; + if(_flags & Flag::Redraw) { + _flags &= ~Flag::Redraw; drawEvent(); } else Utility::sleep(5); } diff --git a/src/Magnum/Platform/AbstractXApplication.h b/src/Magnum/Platform/AbstractXApplication.h index 4899fdfc8..b92dfeff3 100644 --- a/src/Magnum/Platform/AbstractXApplication.h +++ b/src/Magnum/Platform/AbstractXApplication.h @@ -29,6 +29,7 @@ * @brief Class @ref Magnum::Platform::AbstractXApplication */ +#include #include #include @@ -93,7 +94,7 @@ class AbstractXApplication { int exec(); /** @brief Exit application main loop */ - void exit() { flags |= Flag::Exit; } + void exit() { _flags |= Flag::Exit; } protected: /* Nobody will need to have (and delete) AbstractXApplication*, thus @@ -118,7 +119,7 @@ class AbstractXApplication { void swapBuffers(); /** @copydoc Sdl2Application::redraw() */ - void redraw() { flags |= Flag::Redraw; } + void redraw() { _flags |= Flag::Redraw; } #ifdef DOXYGEN_GENERATING_OUTPUT protected: @@ -174,18 +175,17 @@ class AbstractXApplication { typedef Containers::EnumSet Flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) - Display* display; - Window window; - Atom deleteWindow; + Display* _display; + Window _window; + Atom _deleteWindow; - Implementation::AbstractContextHandler* contextHandler; - - Platform::Context* c; + std::unique_ptr> _contextHandler; + std::unique_ptr _context; /** @todo Get this from the created window */ - Vector2i viewportSize; + Vector2i _viewportSize; - Flags flags; + Flags _flags; }; CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Flags)