Browse Source

Add dbg messages to Window.cpp; Fix first setVisible on Windows

gh-pages
falkTX 11 years ago
parent
commit
a054116f67
1 changed files with 91 additions and 18 deletions
  1. +91
    -18
      dgl/src/Window.cpp

+ 91
- 18
dgl/src/Window.cpp View File

@@ -19,6 +19,7 @@
#include "../Window.hpp" #include "../Window.hpp"


#include <cassert> #include <cassert>
#include <cstdio>
#include <list> #include <list>


#include "pugl/pugl.h" #include "pugl/pugl.h"
@@ -43,6 +44,16 @@ extern "C" {
#define FOR_EACH_WIDGET_INV(rit) \ #define FOR_EACH_WIDGET_INV(rit) \
for (std::list<Widget*>::reverse_iterator rit = fWidgets.rbegin(); rit != fWidgets.rend(); ++rit) for (std::list<Widget*>::reverse_iterator rit = fWidgets.rbegin(); rit != fWidgets.rend(); ++rit)


#ifdef DEBUG
# define DBG(msg) std::fprintf(stderr, "%s", msg);
# define DBGp(...) std::fprintf(stderr, __VA_ARGS__);
# define DBGF std::fflush(stderr);
#else
# define DBG(msg)
# define DBGp(...)
# define DBGF
#endif

START_NAMESPACE_DGL START_NAMESPACE_DGL


Window* dgl_lastUiParent = nullptr; Window* dgl_lastUiParent = nullptr;
@@ -69,6 +80,7 @@ public:
_dummy('\0') _dummy('\0')
#endif #endif
{ {
DBG("Creating simple window without parent..."); DBGF;
init(); init();
} }


@@ -89,12 +101,14 @@ public:
_dummy('\0') _dummy('\0')
#endif #endif
{ {
DBG("Creating window with parent..."); DBGF;
init(); init();


#if DGL_OS_LINUX #if DGL_OS_LINUX
PuglInternals* const parentImpl = parent.pData->fView->impl; PuglInternals* const parentImpl = parent.pData->fView->impl;


XSetTransientForHint(xDisplay, xWindow, parentImpl->win); XSetTransientForHint(xDisplay, xWindow, parentImpl->win);
XFlush(xDisplay);
#endif #endif
} }


@@ -114,17 +128,22 @@ public:
_dummy('\0') _dummy('\0')
#endif #endif
{ {
DBG("Creating window embedded with parent Id..."); DBGF;
init(); init();


// starts visible
DBG("Embed window always visible\n");
fApp.oneShown(); fApp.oneShown();
fFirstInit = false; fFirstInit = false;
} }


void init() void init()
{ {
if (fView == nullptr)
if (fSelf == nullptr || fView == nullptr)
{
DBG("Failed!\n");
dgl_lastUiParent = nullptr;
return; return;
}


dgl_lastUiParent = fSelf; dgl_lastUiParent = fSelf;


@@ -141,31 +160,43 @@ public:
#if DGL_OS_WINDOWS #if DGL_OS_WINDOWS
PuglInternals* impl = fView->impl; PuglInternals* impl = fView->impl;
hwnd = impl->hwnd; hwnd = impl->hwnd;
assert(hwnd != 0);
#elif DGL_OS_LINUX #elif DGL_OS_LINUX
PuglInternals* impl = fView->impl; PuglInternals* impl = fView->impl;
xDisplay = impl->display; xDisplay = impl->display;
xWindow = impl->win; xWindow = impl->win;
assert(xWindow != 0);
#endif #endif


DBG("Success!\n");

// process any initial events
puglProcessEvents(fView);

fApp.addWindow(fSelf); fApp.addWindow(fSelf);
} }


~PrivateData() ~PrivateData()
{ {
DBG("Destroying window..."); DBGF;

//fOnModal = false; //fOnModal = false;
fWidgets.clear(); fWidgets.clear();


if (fView != nullptr)
if (fSelf != nullptr && fView != nullptr)
{ {
fApp.removeWindow(fSelf); fApp.removeWindow(fSelf);
puglDestroy(fView); puglDestroy(fView);
} }

DBG("Success!\n");
} }


// ------------------------------------------------------------------- // -------------------------------------------------------------------


void close() void close()
{ {
DBG("Window close\n");
setVisible(false); setVisible(false);


if (! fFirstInit) if (! fFirstInit)
@@ -177,6 +208,7 @@ public:


void exec(const bool lockWait) void exec(const bool lockWait)
{ {
DBG("Window exec\n");
exec_init(); exec_init();


if (lockWait) if (lockWait)
@@ -204,6 +236,7 @@ public:


void focus() void focus()
{ {
DBG("Window focus\n");
#if DGL_OS_WINDOWS #if DGL_OS_WINDOWS
SetForegroundWindow(hwnd); SetForegroundWindow(hwnd);
SetActiveWindow(hwnd); SetActiveWindow(hwnd);
@@ -213,6 +246,7 @@ public:
#elif DGL_OS_LINUX #elif DGL_OS_LINUX
XRaiseWindow(xDisplay, xWindow); XRaiseWindow(xDisplay, xWindow);
XSetInputFocus(xDisplay, xWindow, RevertToPointerRoot, CurrentTime); XSetInputFocus(xDisplay, xWindow, RevertToPointerRoot, CurrentTime);
XFlush(xDisplay);
#endif #endif
} }


@@ -226,19 +260,10 @@ public:


void repaint() void repaint()
{ {
DBG("Window repaint\n");
puglPostRedisplay(fView); puglPostRedisplay(fView);
} }


void flush()
{
#if DGL_OS_WINDOWS
UpdateWindow(hwnd);
#elif DGL_OS_MAC
#elif DGL_OS_LINUX
XFlush(xDisplay);
#endif
}

// ------------------------------------------------------------------- // -------------------------------------------------------------------


bool isVisible() const noexcept bool isVisible() const noexcept
@@ -249,7 +274,12 @@ public:
void setVisible(const bool yesNo) void setVisible(const bool yesNo)
{ {
if (fVisible == yesNo) if (fVisible == yesNo)
{
DBG("Window setVisible ignored!\n");
return; return;
}

DBG("Window setVisible called\n");


fVisible = yesNo; fVisible = yesNo;


@@ -261,15 +291,17 @@ public:
#if DGL_OS_WINDOWS #if DGL_OS_WINDOWS
if (yesNo) if (yesNo)
{ {
ShowWindow(hwnd, WS_VISIBLE);
if (! fFirstInit)
if (fFirstInit)
ShowWindow(hwnd, SW_SHOWNORMAL);
else
ShowWindow(hwnd, SW_RESTORE); ShowWindow(hwnd, SW_RESTORE);
} }
else else
{ {
ShowWindow(hwnd, SW_HIDE); ShowWindow(hwnd, SW_HIDE);
} }

UpdateWindow(hwnd);
#elif DGL_OS_MAC #elif DGL_OS_MAC
puglImplSetVisible(fView, yesNo); puglImplSetVisible(fView, yesNo);
#elif DGL_OS_LINUX #elif DGL_OS_LINUX
@@ -277,6 +309,8 @@ public:
XMapRaised(xDisplay, xWindow); XMapRaised(xDisplay, xWindow);
else else
XUnmapWindow(xDisplay, xWindow); XUnmapWindow(xDisplay, xWindow);

XFlush(xDisplay);
#endif #endif


if (yesNo) if (yesNo)
@@ -301,7 +335,12 @@ public:
void setResizable(const bool yesNo) void setResizable(const bool yesNo)
{ {
if (fResizable == yesNo) if (fResizable == yesNo)
{
DBG("Window setResizable ignored!\n");
return; return;
}

DBG("Window setResizable called\n");


fResizable = yesNo; fResizable = yesNo;


@@ -338,12 +377,17 @@ public:


#ifndef DGL_OS_MAC #ifndef DGL_OS_MAC
if (fView->width == (int)width && fView->height == (int)height && ! forced) if (fView->width == (int)width && fView->height == (int)height && ! forced)
return;
{
DBG("Window setSize ignored!\n");
return;
}


fView->width = width; fView->width = width;
fView->height = height; fView->height = height;
#endif #endif


DBG("Window setSize called\n");

#if DGL_OS_WINDOWS #if DGL_OS_WINDOWS
int winFlags = WS_POPUPWINDOW | WS_CAPTION; int winFlags = WS_POPUPWINDOW | WS_CAPTION;


@@ -354,6 +398,7 @@ public:
AdjustWindowRectEx(&wr, winFlags, FALSE, WS_EX_TOPMOST); AdjustWindowRectEx(&wr, winFlags, FALSE, WS_EX_TOPMOST);


SetWindowPos(hwnd, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); SetWindowPos(hwnd, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
UpdateWindow(hwnd);
#elif DGL_OS_MAC #elif DGL_OS_MAC
puglImplSetSize(fView, width, height); puglImplSetSize(fView, width, height);
#elif DGL_OS_LINUX #elif DGL_OS_LINUX
@@ -372,6 +417,8 @@ public:


XSetNormalHints(xDisplay, xWindow, &sizeHints); XSetNormalHints(xDisplay, xWindow, &sizeHints);
} }

XFlush(xDisplay);
#endif #endif


repaint(); repaint();
@@ -381,12 +428,14 @@ public:


void setTitle(const char* const title) void setTitle(const char* const title)
{ {
DBG("Window setTitle\n");
#if DGL_OS_WINDOWS #if DGL_OS_WINDOWS
SetWindowTextA(hwnd, title); SetWindowTextA(hwnd, title);
#elif DGL_OS_MAC #elif DGL_OS_MAC
puglImplSetTitle(fView, title); puglImplSetTitle(fView, title);
#elif DGL_OS_LINUX #elif DGL_OS_LINUX
XStoreName(xDisplay, xWindow, title); XStoreName(xDisplay, xWindow, title);
XFlush(xDisplay);
#endif #endif
} }


@@ -426,6 +475,7 @@ public:


void exec_init() void exec_init()
{ {
DBG("Window modal loop starting..."); DBGF;
fModal.enabled = true; fModal.enabled = true;
assert(fModal.parent != nullptr); assert(fModal.parent != nullptr);


@@ -452,14 +502,19 @@ public:


fModal.parent->setVisible(true); fModal.parent->setVisible(true);
setVisible(true); setVisible(true);

DBG("Ok\n");
} }


void exec_fini() void exec_fini()
{ {
DBG("Window modal loop stopping..."); DBGF;
fModal.enabled = false; fModal.enabled = false;


if (fModal.parent != nullptr) if (fModal.parent != nullptr)
fModal.parent->fModal.childFocus = nullptr; fModal.parent->fModal.childFocus = nullptr;

DBG("Ok\n");
} }


// ------------------------------------------------------------------- // -------------------------------------------------------------------
@@ -467,6 +522,8 @@ public:
protected: protected:
void onDisplay() void onDisplay()
{ {
DBG("PUGL: onDisplay\n");

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


FOR_EACH_WIDGET(it) FOR_EACH_WIDGET(it)
@@ -480,6 +537,8 @@ protected:


void onKeyboard(const bool press, const uint32_t key) void onKeyboard(const bool press, const uint32_t key)
{ {
DBGp("PUGL: onKeyboard : %i %i\n", press, key);

if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
return fModal.childFocus->focus(); return fModal.childFocus->focus();


@@ -494,6 +553,8 @@ protected:


void onMouse(const int button, const bool press, const int x, const int y) void onMouse(const int button, const bool press, const int x, const int y)
{ {
DBGp("PUGL: onMouse : %i %i %i %i\n", button, press, x, y);

if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
return fModal.childFocus->focus(); return fModal.childFocus->focus();


@@ -508,6 +569,8 @@ protected:


void onMotion(const int x, const int y) void onMotion(const int x, const int y)
{ {
DBGp("PUGL: onMotion : %i %i\n", x, y);

if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
return; return;


@@ -522,6 +585,8 @@ protected:


void onScroll(const float dx, const float dy) void onScroll(const float dx, const float dy)
{ {
DBGp("PUGL: onScroll : %f %f\n", dx, dy);

if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
return; return;


@@ -536,6 +601,8 @@ protected:


void onSpecial(const bool press, const Key key) void onSpecial(const bool press, const Key key)
{ {
DBGp("PUGL: onSpecial : %i %i\n", press, key);

if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
return; return;


@@ -550,7 +617,8 @@ protected:


void onReshape(const int width, const int height) void onReshape(const int width, const int height)
{ {
printf("resized: %i:%i\n", width, height);
DBGp("PUGL: onReshape : %i %i\n", width, height);

FOR_EACH_WIDGET(it) FOR_EACH_WIDGET(it)
{ {
Widget* const widget(*it); Widget* const widget(*it);
@@ -560,6 +628,8 @@ protected:


void onClose() void onClose()
{ {
DBG("PUGL: onClose\n");

fModal.enabled = false; fModal.enabled = false;


if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
@@ -803,3 +873,6 @@ void Window::removeWidget(Widget* const widget)
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


END_NAMESPACE_DGL END_NAMESPACE_DGL

#undef DBG
#undef DBGF

Loading…
Cancel
Save