X11 support for resize events
parent
a90a8606bd
commit
1e3b877fd3
|
@ -147,7 +147,8 @@ public:
|
||||||
EMouseEndDragEvent = 0x0400,
|
EMouseEndDragEvent = 0x0400,
|
||||||
EMouseDoubleClickEvent = 0x0800,
|
EMouseDoubleClickEvent = 0x0800,
|
||||||
EGainFocusEvent = 0x1000,
|
EGainFocusEvent = 0x1000,
|
||||||
ELoseFocusEvent = 0x2000
|
ELoseFocusEvent = 0x2000,
|
||||||
|
EResizeEvent = 0x4000
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Device keyboard event modifiers
|
/// Device keyboard event modifiers
|
||||||
|
@ -315,6 +316,12 @@ public:
|
||||||
/// Return whether full screen drawing is enabled
|
/// Return whether full screen drawing is enabled
|
||||||
inline bool getFullscreen() const { return m_fullscreen; }
|
inline bool getFullscreen() const { return m_fullscreen; }
|
||||||
|
|
||||||
|
// Specify whether resizing the window is allowed
|
||||||
|
void setResizeAllowed(bool resizeAllowed);
|
||||||
|
|
||||||
|
/// Return whether it is possible to resize the window
|
||||||
|
inline bool isResizeAllowed() const { return m_resizeAllowed; }
|
||||||
|
|
||||||
/// Define whether to enable window centering
|
/// Define whether to enable window centering
|
||||||
void setCenter(bool center);
|
void setCenter(bool center);
|
||||||
|
|
||||||
|
@ -386,20 +393,11 @@ protected:
|
||||||
Vector2i m_size;
|
Vector2i m_size;
|
||||||
Point2i m_position;
|
Point2i m_position;
|
||||||
int m_fsaa;
|
int m_fsaa;
|
||||||
int m_redBits;
|
int m_redBits, m_greenBits, m_blueBits;
|
||||||
int m_greenBits;
|
int m_alphaBits, m_depthBits, m_stencilBits;
|
||||||
int m_blueBits;
|
bool m_doubleBuffer, m_initialized, m_fullscreen;
|
||||||
int m_alphaBits;
|
bool m_center, m_showFPS, m_resizeAllowed;
|
||||||
int m_depthBits;
|
int m_fpsCounter, m_fps, m_lastTime;
|
||||||
int m_stencilBits;
|
|
||||||
bool m_doubleBuffer;
|
|
||||||
bool m_initialized;
|
|
||||||
bool m_fullscreen;
|
|
||||||
bool m_center;
|
|
||||||
bool m_showFPS;
|
|
||||||
int m_fpsCounter;
|
|
||||||
int m_fps;
|
|
||||||
int m_lastTime;
|
|
||||||
std::string m_title;
|
std::string m_title;
|
||||||
std::list<DeviceEventListener *> m_callbacks;
|
std::list<DeviceEventListener *> m_callbacks;
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,6 +55,12 @@ public:
|
||||||
/// Initialize the renderer
|
/// Initialize the renderer
|
||||||
virtual void init(Device *device, Renderer *other = NULL);
|
virtual void init(Device *device, Renderer *other = NULL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Reconfigure the renderer for a certain device
|
||||||
|
* (e.g. after a resize event)
|
||||||
|
*/
|
||||||
|
void reconfigure(const Device *device);
|
||||||
|
|
||||||
/// Shut the renderer down
|
/// Shut the renderer down
|
||||||
virtual void shutdown();
|
virtual void shutdown();
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void init(Device *device, Renderer *other = NULL);
|
virtual void init(Device *device, Renderer *other = NULL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Reconfigure the renderer for a certain device
|
||||||
|
* (e.g. after a resize event)
|
||||||
|
*/
|
||||||
|
virtual void reconfigure(const Device *device) = 0;
|
||||||
|
|
||||||
/// Shut the renderer down
|
/// Shut the renderer down
|
||||||
virtual void shutdown();
|
virtual void shutdown();
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,9 @@ protected:
|
||||||
|
|
||||||
/// To be overwritten (optionally): handle a mouse end drag event
|
/// To be overwritten (optionally): handle a mouse end drag event
|
||||||
virtual void mouseEndDrag(const DeviceEvent &event);
|
virtual void mouseEndDrag(const DeviceEvent &event);
|
||||||
|
|
||||||
|
/// To be overwritten (optionally): handle a window resize event
|
||||||
|
virtual void windowResized(const DeviceEvent &event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool deviceEventOccurred(const DeviceEvent &event);
|
bool deviceEventOccurred(const DeviceEvent &event);
|
||||||
|
|
|
@ -46,6 +46,7 @@ Device::Device(Session *name) {
|
||||||
m_fpsCounter = 0;
|
m_fpsCounter = 0;
|
||||||
m_lastTime = 0;
|
m_lastTime = 0;
|
||||||
m_timer = new Timer();
|
m_timer = new Timer();
|
||||||
|
m_resizeAllowed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device() {
|
Device::~Device() {
|
||||||
|
@ -124,6 +125,11 @@ void Device::setFullscreen(bool fullscreen) {
|
||||||
m_fullscreen = fullscreen;
|
m_fullscreen = fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setResizeAllowed(bool resizeAllowed) {
|
||||||
|
Assert(!m_initialized);
|
||||||
|
m_resizeAllowed = resizeAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
void Device::setCenter(bool center) {
|
void Device::setCenter(bool center) {
|
||||||
Assert(!m_initialized);
|
Assert(!m_initialized);
|
||||||
m_center = center;
|
m_center = center;
|
||||||
|
|
|
@ -209,6 +209,10 @@ GPUSync *GLRenderer::createGPUSync() {
|
||||||
return new GLSync();
|
return new GLSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLRenderer::reconfigure(const Device *device) {
|
||||||
|
glViewport(0, 0, device->getSize().x, device->getSize().y);
|
||||||
|
}
|
||||||
|
|
||||||
void GLRenderer::clear() {
|
void GLRenderer::clear() {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
checkError();
|
checkError();
|
||||||
|
|
|
@ -37,6 +37,8 @@ int Viewer::run(int argc, char **argv) {
|
||||||
m_font->init(m_renderer);
|
m_font->init(m_renderer);
|
||||||
m_quit = false;
|
m_quit = false;
|
||||||
m_leaveEventLoop = true;
|
m_leaveEventLoop = true;
|
||||||
|
DeviceEvent event(Device::EResizeEvent);
|
||||||
|
windowResized(event);
|
||||||
|
|
||||||
if (init(argc, argv)) {
|
if (init(argc, argv)) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -76,6 +78,7 @@ void Viewer::mouseMoved(const DeviceEvent &event) { }
|
||||||
void Viewer::mouseBeginDrag(const DeviceEvent &event) { }
|
void Viewer::mouseBeginDrag(const DeviceEvent &event) { }
|
||||||
void Viewer::mouseDragged(const DeviceEvent &event) { }
|
void Viewer::mouseDragged(const DeviceEvent &event) { }
|
||||||
void Viewer::mouseEndDrag(const DeviceEvent &event) { }
|
void Viewer::mouseEndDrag(const DeviceEvent &event) { }
|
||||||
|
void Viewer::windowResized(const DeviceEvent &event) { }
|
||||||
|
|
||||||
bool Viewer::deviceEventOccurred(const DeviceEvent &event) {
|
bool Viewer::deviceEventOccurred(const DeviceEvent &event) {
|
||||||
switch (event.getType()) {
|
switch (event.getType()) {
|
||||||
|
@ -99,6 +102,11 @@ bool Viewer::deviceEventOccurred(const DeviceEvent &event) {
|
||||||
m_quit = true;
|
m_quit = true;
|
||||||
m_leaveEventLoop = true;
|
m_leaveEventLoop = true;
|
||||||
break;
|
break;
|
||||||
|
case Device::EResizeEvent:
|
||||||
|
m_renderer->reconfigure(m_device);
|
||||||
|
windowResized(event);
|
||||||
|
m_leaveEventLoop = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -236,8 +236,17 @@ void X11Device::init(Device *other) {
|
||||||
|
|
||||||
/* Make the window non-resizable */
|
/* Make the window non-resizable */
|
||||||
XSizeHints *hints = XAllocSizeHints();
|
XSizeHints *hints = XAllocSizeHints();
|
||||||
hints->min_width = hints->max_width = hints->width = m_size.x;
|
hints->width = m_size.x;
|
||||||
hints->min_height = hints->max_height = hints->height = m_size.y;
|
hints->height = m_size.y;
|
||||||
|
|
||||||
|
if (m_resizeAllowed) {
|
||||||
|
hints->min_width = hints->min_height = 10;
|
||||||
|
hints->max_width = hints->max_height = INT_MAX;
|
||||||
|
} else {
|
||||||
|
hints->min_width = hints->max_width = m_size.x;
|
||||||
|
hints->min_height = hints->max_height = m_size.y;
|
||||||
|
}
|
||||||
|
|
||||||
hints->x = m_position.x; hints->y = m_position.y;
|
hints->x = m_position.x; hints->y = m_position.y;
|
||||||
hints->flags = PMaxSize | PMinSize | USSize | USPosition;
|
hints->flags = PMaxSize | PMinSize | USSize | USPosition;
|
||||||
XSetNormalHints(session->m_display, m_window, hints);
|
XSetNormalHints(session->m_display, m_window, hints);
|
||||||
|
@ -473,7 +482,14 @@ void X11Device::processEvent(const XEvent &event) {
|
||||||
case UnmapNotify:
|
case UnmapNotify:
|
||||||
m_modifierState = 0;
|
m_modifierState = 0;
|
||||||
break;
|
break;
|
||||||
case ConfigureNotify:
|
case ConfigureNotify: {
|
||||||
|
Vector2i size(event.xconfigure.width, event.xconfigure.height);
|
||||||
|
if (m_size != size) {
|
||||||
|
m_size = size;
|
||||||
|
deviceEvent.setType(EResizeEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ReparentNotify:
|
case ReparentNotify:
|
||||||
case Expose:
|
case Expose:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -23,7 +23,6 @@ MTS_NAMESPACE_BEGIN
|
||||||
class CylClip : public Viewer {
|
class CylClip : public Viewer {
|
||||||
public:
|
public:
|
||||||
CylClip() : m_red(0.0f), m_blue(0.0f), m_gray(.5f), m_angle(0) {
|
CylClip() : m_red(0.0f), m_blue(0.0f), m_gray(.5f), m_angle(0) {
|
||||||
m_projTransform = Transform::glPerspective(45, 1e-4, 1e4);
|
|
||||||
m_viewTransform = Transform::lookAt(Point(10*std::sin(m_angle), 0, std::cos(m_angle)*10),
|
m_viewTransform = Transform::lookAt(Point(10*std::sin(m_angle), 0, std::cos(m_angle)*10),
|
||||||
Point(0, 0, 0), Vector(0, 1, 0));
|
Point(0, 0, 0), Vector(0, 1, 0));
|
||||||
m_lineParams = Point2(M_PI/2, 0.28f);
|
m_lineParams = Point2(M_PI/2, 0.28f);
|
||||||
|
@ -37,6 +36,12 @@ public:
|
||||||
m_radius = .2f;
|
m_radius = .2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void windowResized(const DeviceEvent &event) {
|
||||||
|
Float aspect = m_device->getAspect();
|
||||||
|
m_projTransform = Transform::glPerspective(45, 1e-4, 1e4)
|
||||||
|
* Transform::scale(Vector(1.0f, aspect, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
void mouseDragged(const DeviceEvent &event) {
|
void mouseDragged(const DeviceEvent &event) {
|
||||||
if (event.getMouseButton() == Device::ELeftButton) {
|
if (event.getMouseButton() == Device::ELeftButton) {
|
||||||
m_angle += event.getMouseRelative().x / 100.0f;
|
m_angle += event.getMouseRelative().x / 100.0f;
|
||||||
|
|
Loading…
Reference in New Issue