Support mouse wheel on Linux.

This commit is contained in:
leo 2013-01-28 19:57:33 +00:00
parent 0876ec0306
commit 03794eb0ec
6 changed files with 84 additions and 41 deletions

View file

@ -52,14 +52,15 @@ public:
virtual void OnSize(int cx, int cy)
{ m_nWidth = cx; m_nHeight = cy; };
virtual void OnInitialUpdate();
virtual void OnLeftButtonDown(int x, int y, bool bControl, bool bShift) { };
virtual void OnLeftButtonUp(int x, int y, bool bControl, bool bShift) { };
virtual void OnLeftButtonDoubleClick(int x, int y, bool bControl, bool bShift) { };
virtual void OnMiddleButtonDown(int x, int y, bool bControl, bool bShift) { };
virtual void OnMiddleButtonUp(int x, int y, bool bControl, bool bShift) { };
virtual void OnRightButtonDown(int x, int y, bool bControl, bool bShift) { };
virtual void OnRightButtonUp(int x, int y, bool bControl, bool bShift) { };
virtual void OnMouseMove(int x, int y, bool bControl, bool bShift) { };
virtual void OnLeftButtonDown(int x, int y, bool Control, bool Shift) { };
virtual void OnLeftButtonUp(int x, int y, bool Control, bool Shift) { };
virtual void OnLeftButtonDoubleClick(int x, int y, bool Control, bool Shift) { };
virtual void OnMiddleButtonDown(int x, int y, bool Control, bool Shift) { };
virtual void OnMiddleButtonUp(int x, int y, bool Control, bool Shift) { };
virtual void OnRightButtonDown(int x, int y, bool Control, bool Shift) { };
virtual void OnRightButtonUp(int x, int y, bool Control, bool Shift) { };
virtual void OnMouseMove(int x, int y, bool Control, bool Shift) { };
virtual void OnMouseWheel(int x, int y, float Direction, bool Control, bool Shift) { };
protected:
int m_nWidth;

View file

@ -8935,6 +8935,14 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
}
}
void Project::OnMouseWheel(View* view, int x, int y, float Direction, bool Control, bool Shift)
{
if (Direction > 0.0f)
HandleCommand(LC_VIEW_ZOOM, 10);
else
HandleCommand(LC_VIEW_ZOOM, -10);
}
// Check if the mouse is over a different area of the overlay and redraw it.
void Project::MouseUpdateOverlays(View* view, int x, int y)
{

View file

@ -246,15 +246,16 @@ protected:
public:
// Call these functions from each OS
void OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bShift);
void OnLeftButtonUp(View* view, int x, int y, bool bControl, bool bShift);
void OnLeftButtonDoubleClick(View* view, int x, int y, bool bControl, bool bShift);
void OnMiddleButtonDown(View* view, int x, int y, bool bControl, bool bShift);
void OnMiddleButtonUp(View* view, int x, int y, bool bControl, bool bShift);
void OnRightButtonDown(View* view, int x, int y, bool bControl, bool bShift);
void OnRightButtonUp(View* view, int x, int y, bool bControl, bool bShift);
void OnMouseMove(View* view, int x, int y, bool bControl, bool bShift);
bool OnKeyDown(char nKey, bool bControl, bool bShift);
void OnLeftButtonDown(View* view, int x, int y, bool Control, bool Shift);
void OnLeftButtonUp(View* view, int x, int y, bool Control, bool Shift);
void OnLeftButtonDoubleClick(View* view, int x, int y, bool Control, bool Shift);
void OnMiddleButtonDown(View* view, int x, int y, bool Control, bool Shift);
void OnMiddleButtonUp(View* view, int x, int y, bool Control, bool Shift);
void OnRightButtonDown(View* view, int x, int y, bool Control, bool Shift);
void OnRightButtonUp(View* view, int x, int y, bool Control, bool Shift);
void OnMouseMove(View* view, int x, int y, bool Control, bool Shift);
void OnMouseWheel(View* view, int x, int y, float Direction, bool Control, bool Shift);
bool OnKeyDown(char nKey, bool Control, bool Shift);
void SetAction(int Action);
int GetCurAction() const

View file

@ -132,42 +132,47 @@ void View::OnInitialUpdate()
m_Project->AddView(this);
}
void View::OnLeftButtonDown(int x, int y, bool bControl, bool bShift)
void View::OnLeftButtonDown(int x, int y, bool Control, bool Shift)
{
m_Project->OnLeftButtonDown(this, x, y, bControl, bShift);
m_Project->OnLeftButtonDown(this, x, y, Control, Shift);
}
void View::OnLeftButtonUp(int x, int y, bool bControl, bool bShift)
void View::OnLeftButtonUp(int x, int y, bool Control, bool Shift)
{
m_Project->OnLeftButtonUp(this, x, y, bControl, bShift);
m_Project->OnLeftButtonUp(this, x, y, Control, Shift);
}
void View::OnLeftButtonDoubleClick(int x, int y, bool bControl, bool bShift)
void View::OnLeftButtonDoubleClick(int x, int y, bool Control, bool Shift)
{
m_Project->OnLeftButtonDoubleClick(this, x, y, bControl, bShift);
m_Project->OnLeftButtonDoubleClick(this, x, y, Control, Shift);
}
void View::OnMiddleButtonDown(int x, int y, bool bControl, bool bShift)
void View::OnMiddleButtonDown(int x, int y, bool Control, bool Shift)
{
m_Project->OnMiddleButtonDown(this, x, y, bControl, bShift);
m_Project->OnMiddleButtonDown(this, x, y, Control, Shift);
}
void View::OnMiddleButtonUp(int x, int y, bool bControl, bool bShift)
void View::OnMiddleButtonUp(int x, int y, bool Control, bool Shift)
{
m_Project->OnMiddleButtonUp(this, x, y, bControl, bShift);
m_Project->OnMiddleButtonUp(this, x, y, Control, Shift);
}
void View::OnRightButtonDown(int x, int y, bool bControl, bool bShift)
void View::OnRightButtonDown(int x, int y, bool Control, bool Shift)
{
m_Project->OnRightButtonDown(this, x, y, bControl, bShift);
m_Project->OnRightButtonDown(this, x, y, Control, Shift);
}
void View::OnRightButtonUp(int x, int y, bool bControl, bool bShift)
void View::OnRightButtonUp(int x, int y, bool Control, bool Shift)
{
m_Project->OnRightButtonUp(this, x, y, bControl, bShift);
m_Project->OnRightButtonUp(this, x, y, Control, Shift);
}
void View::OnMouseMove(int x, int y, bool bControl, bool bShift)
void View::OnMouseMove(int x, int y, bool Control, bool Shift)
{
m_Project->OnMouseMove(this, x, y, bControl, bShift);
m_Project->OnMouseMove(this, x, y, Control, Shift);
}
void View::OnMouseWheel(int x, int y, float Direction, bool Control, bool Shift)
{
m_Project->OnMouseWheel(this, x, y, Direction, Control, Shift);
}

View file

@ -14,14 +14,15 @@ public:
void OnDraw();
void OnInitialUpdate();
void OnLeftButtonDown(int x, int y, bool bControl, bool bShift);
void OnLeftButtonUp(int x, int y, bool bControl, bool bShift);
void OnLeftButtonDoubleClick(int x, int y, bool bControl, bool bShift);
void OnMiddleButtonDown(int x, int y, bool bControl, bool bShift);
void OnMiddleButtonUp(int x, int y, bool bControl, bool bShift);
void OnRightButtonDown(int x, int y, bool bControl, bool bShift);
void OnRightButtonUp(int x, int y, bool bControl, bool bShift);
void OnMouseMove(int x, int y, bool bControl, bool bShift);
void OnLeftButtonDown(int x, int y, bool Control, bool Shift);
void OnLeftButtonUp(int x, int y, bool Control, bool Shift);
void OnLeftButtonDoubleClick(int x, int y, bool Control, bool Shift);
void OnMiddleButtonDown(int x, int y, bool Control, bool Shift);
void OnMiddleButtonUp(int x, int y, bool Control, bool Shift);
void OnRightButtonDown(int x, int y, bool Control, bool Shift);
void OnRightButtonUp(int x, int y, bool Control, bool Shift);
void OnMouseMove(int x, int y, bool Control, bool Shift);
void OnMouseWheel(int x, int y, float Direction, bool Control, bool Shift);
void SetCamera(Camera* camera, bool ForceCopy);
void SetDefaultCamera();

View file

@ -119,6 +119,32 @@ static gint pointer_motion_event(GtkWidget *widget, GdkEventMotion *event, gpoin
return TRUE;
}
static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data)
{
GLWindow *wnd = (GLWindow*)data;
float Direction;
int x, y;
switch (event->direction)
{
case GDK_SCROLL_UP:
Direction = 1.0f;
break;
case GDK_SCROLL_DOWN:
Direction = -1.0f;
break;
default:
return FALSE;
}
x = (int)event->x;
y = widget->allocation.height - (int)event->y - 1;
wnd->OnMouseWheel(x, y, Direction, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
return TRUE;
}
static gint size_allocate_event(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
{
GLWindow *wnd = (GLWindow*)data;
@ -239,6 +265,7 @@ bool GLWindow::CreateFromWindow(void *data)
gtk_signal_connect(GTK_OBJECT(prv->widget), "motion_notify_event", GTK_SIGNAL_FUNC(pointer_motion_event), this);
gtk_signal_connect(GTK_OBJECT(prv->widget), "button_press_event", GTK_SIGNAL_FUNC(button_press_event), this);
gtk_signal_connect(GTK_OBJECT(prv->widget), "button_release_event", GTK_SIGNAL_FUNC(button_release_event), this);
gtk_signal_connect(GTK_OBJECT(prv->widget), "scroll_event", GTK_SIGNAL_FUNC(scroll_event), this);
gtk_signal_connect(GTK_OBJECT(prv->widget), "realize", GTK_SIGNAL_FUNC(realize_event), this);
*((GtkWidget**)data) = prv->widget;