Skip to content
Browse files

Add new events to IWindowListener: OnMouseScroll, OnResize

Adopt textool plugin to make use of those events in patch texture alignment window.
  • Loading branch information...
1 parent 1c3b826 commit 7f763ad2fd0334c8b26d9ab8c5d5a4ec816da485 @mfn committed Jan 2, 2010
View
2 contrib/bobtoolz/DListener.h
@@ -43,6 +43,8 @@ class DListener : public IWindowListener
bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y);
bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y);
bool OnKeyPressed(char *s) { return false; }
+ bool OnMouseScroll(GdkScrollDirection direction, gdouble x, gdouble y) { return false; }
+ bool OnResize(int width, int height) { return false; }
bool Paint() { return true; }
void Close() { }
View
2 contrib/bobtoolz/DTreePlanter.h
@@ -43,6 +43,8 @@ class DTreePlanter : public IWindowListener {
virtual bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y);
virtual bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y);
virtual bool OnKeyPressed(char *s) { return false; }
+ virtual bool OnMouseScroll(GdkScrollDirection direction, gdouble x, gdouble y) { return false; }
+ virtual bool OnResize(int width, int height) { return false; }
virtual bool Paint() { return true; }
virtual void Close() { }
View
2 contrib/camera/listener.h
@@ -35,6 +35,8 @@ class CListener : public IWindowListener
bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y);
bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y);
bool OnKeyPressed(char *s) { return false; }
+ bool OnMouseScroll(GdkScrollDirection direction, gdouble x, gdouble y) { return false; }
+ bool OnResize(int width, int height) { return false; }
bool Paint() { return true; }
void Close() { }
View
2 include/iui.h
@@ -51,6 +51,8 @@ class IWindowListener
virtual bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y) = 0;
virtual bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y) = 0;
virtual bool OnMouseMove(guint32 nFlags, gdouble x, gdouble y) = 0;
+ virtual bool OnMouseScroll(GdkScrollDirection direction, gdouble x, gdouble y) = 0;
+ virtual bool OnResize(int width, int height) = 0;
virtual bool OnKeyPressed(char *s) = 0;
// paint message, the caller makes the GL context current, calls Paint, then swaps GL buffers
View
18 plugins/textool/2DView.cpp
@@ -182,6 +182,24 @@ bool C2DView::OnMouseMove (int xPos, int yPos)
return false;
}
+bool C2DView::OnMouseScroll (GdkScrollDirection direction, int x, int y)
+{
+ if (ViewState == View_Idle)
+ {
+ if (direction == GDK_SCROLL_DOWN)
+ {
+ ZoomOut();
+ return true;
+ }
+ if (direction == GDK_SCROLL_UP)
+ {
+ ZoomIn();
+ return true;
+ }
+ }
+ return false;
+}
+
bool C2DView::OnKeyDown (char *s)
{
if (ViewState == View_Idle)
View
1 plugins/textool/2DView.h
@@ -62,6 +62,7 @@ class C2DView
bool OnMouseMove (int x, int y);
bool OnRButtonUp (int x, int y);
bool OnKeyDown (char *s);
+ bool OnMouseScroll (GdkScrollDirection direction, int x, int y);
void ZoomIn();
void ZoomOut();
View
2 plugins/textool/StdAfx.h
@@ -113,6 +113,8 @@ class CWindowListener : public IWindowListener
bool OnMButtonUp(guint32 nFlags, double x, double y) { return false; }
bool OnRButtonUp(guint32 nFlags, double x, double y);
bool OnMouseMove(guint32 nFlags, double x, double y);
+ bool OnMouseScroll(GdkScrollDirection direction, gdouble x, gdouble y);
+ bool OnResize(int width, int height);
bool OnKeyPressed(char *s);
bool Paint();
void Close();
View
20 plugins/textool/TexTool.cpp
@@ -775,6 +775,26 @@ bool CWindowListener::OnMouseMove(guint32 nFlags, double x, double y)
return false;
}
+bool CWindowListener::OnMouseScroll(GdkScrollDirection direction, gdouble x, gdouble y)
+{
+ if (CanProcess ()) {
+ if (g_2DView.OnMouseScroll (direction, (int)x, (int)y)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool CWindowListener::OnResize(int width, int height)
+{
+ // we'll need to update after that as well:
+ g_bTexViewReady = false;
+ // send a repaint message
+ g_pToolWnd->Redraw ();
+
+ return true;
+}
+
// the widget is closing
void CWindowListener::Close()
{
View
21 radiant/ui.cpp
@@ -57,6 +57,21 @@ static void button_release (GtkWidget *widget, GdkEventButton *event, gpointer d
}
}
+
+// React to mouse wheel scrolling events
+static void scroll (GtkWidget *widget, GdkEventScroll *event, gpointer data)
+{
+ IWindowListener *pListen = static_cast<IWindowListener *>(data);
+ pListen->OnMouseScroll(event->direction, event->x, event->y);
+}
+
+// React to window resize request events
+static void resize (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
+{
+ IWindowListener *pListen = static_cast<IWindowListener *>(data);
+ pListen->OnResize(allocation->width, allocation->height);
+}
+
static void motion (GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
IWindowListener *pListen = static_cast<IWindowListener *>(data);
@@ -141,7 +156,7 @@ bool CGtkWindow::Show()
m_pGLWidget = gtk_glwidget_new(FALSE, g_qeglobals_gui.d_glBase);
gtk_widget_set_events (m_pGLWidget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK |
- GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK);
+ GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK);
// Connect signal handlers
gtk_signal_connect (GTK_OBJECT (m_pGLWidget), "expose_event", GTK_SIGNAL_FUNC (expose), this);
@@ -151,6 +166,10 @@ bool CGtkWindow::Show()
GTK_SIGNAL_FUNC (button_press), m_pListen);
gtk_signal_connect (GTK_OBJECT (m_pGLWidget), "button_release_event",
GTK_SIGNAL_FUNC (button_release), m_pListen);
+ gtk_signal_connect (GTK_OBJECT (m_pGLWidget), "scroll_event",
+ GTK_SIGNAL_FUNC (scroll), m_pListen);
+ gtk_signal_connect (GTK_OBJECT (m_pGLWidget), "size_allocate",
+ GTK_SIGNAL_FUNC (resize), m_pListen);
gtk_signal_connect (GTK_OBJECT (m_pWnd), "delete_event", GTK_SIGNAL_FUNC (close_widget), this);
gtk_signal_connect (GTK_OBJECT (m_pWnd), "key_press_event",

0 comments on commit 7f763ad

Please sign in to comment.
Something went wrong with that request. Please try again.