Support middle mouse button on Linux.

This commit is contained in:
leo 2013-01-26 20:06:27 +00:00
parent f602408f6a
commit 3a2b6551b9
2 changed files with 131 additions and 132 deletions

View file

@ -335,7 +335,7 @@ int lcGetBrickLinkColor(int ColorIndex)
const char* Name = gColorList[ColorIndex].Name;
for (int Color = 0; Color < sizeof(BrickLinkColors) / sizeof(BrickLinkColors[0]); Color++)
for (unsigned int Color = 0; Color < sizeof(BrickLinkColors) / sizeof(BrickLinkColors[0]); Color++)
if (!strcmp(Name, BrickLinkColors[Color].Name))
return BrickLinkColors[Color].Code;

View file

@ -18,7 +18,7 @@ static GdkVisual* WindowGdkVisual = NULL;
static XVisualInfo* WindowXVisualInfo = NULL;
static bool WindowMultisample = false;
static GLXContext WindowContext;
int WindowContextCount;
static int WindowContextCount;
// =============================================================================
// static functions
@ -56,27 +56,25 @@ static gint button_press_event(GtkWidget *widget, GdkEventButton *event, gpointe
if (event->type == GDK_BUTTON_PRESS)
{
if (event->button == 1)
wnd->OnLeftButtonDown (x, y, (event->state & GDK_CONTROL_MASK) != 0,
(event->state & GDK_SHIFT_MASK) != 0);
wnd->OnLeftButtonDown(x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
else if (event->button == 2)
wnd->OnMiddleButtonDown(x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
else if (event->button == 3)
wnd->OnRightButtonDown (x, y, (event->state & GDK_CONTROL_MASK) != 0,
(event->state & GDK_SHIFT_MASK) != 0);
wnd->OnRightButtonDown(x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
}
else if (event->type == GDK_2BUTTON_PRESS)
{
wnd->OnLeftButtonDoubleClick (x, y, (event->state & GDK_CONTROL_MASK) != 0,
(event->state & GDK_SHIFT_MASK) != 0);
wnd->OnLeftButtonDoubleClick(x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
}
gtk_window_set_focus (GTK_WINDOW (gtk_widget_get_toplevel (widget)), widget);
gdk_pointer_grab (widget->window, FALSE, (GdkEventMask)(GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|
GDK_POINTER_MOTION_MASK|GDK_POINTER_MOTION_HINT_MASK),
gtk_window_set_focus(GTK_WINDOW(gtk_widget_get_toplevel(widget)), widget);
gdk_pointer_grab(widget->window, FALSE, (GdkEventMask)(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK),
NULL, NULL, GDK_CURRENT_TIME);
return TRUE;
}
static gint button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer data)
static gint button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
GLWindow *wnd = (GLWindow*)data;
int x, y;
@ -84,19 +82,19 @@ static gint button_release_event (GtkWidget *widget, GdkEventButton *event, gpoi
x = (int)event->x;
y = widget->allocation.height - (int)event->y - 1;
gdk_pointer_ungrab (GDK_CURRENT_TIME);
gdk_pointer_ungrab(GDK_CURRENT_TIME);
if (event->button == 1)
wnd->OnLeftButtonUp (x, y, (event->state & GDK_CONTROL_MASK) != 0,
(event->state & GDK_SHIFT_MASK) != 0);
wnd->OnLeftButtonUp(x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
else if (event->button == 2)
wnd->OnMiddleButtonUp(x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
else if (event->button == 3)
wnd->OnRightButtonUp (x, y, (event->state & GDK_CONTROL_MASK) != 0,
(event->state & GDK_SHIFT_MASK) != 0);
wnd->OnRightButtonUp(x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
return TRUE;
}
static gint pointer_motion_event (GtkWidget *widget, GdkEventMotion *event, gpointer data)
static gint pointer_motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
GLWindow *wnd = (GLWindow*)data;
GdkModifierType state;
@ -104,7 +102,7 @@ static gint pointer_motion_event (GtkWidget *widget, GdkEventMotion *event, gpoi
if (event->is_hint)
{
gdk_window_get_pointer (event->window, &x, &y, &state);
gdk_window_get_pointer(event->window, &x, &y, &state);
state = (GdkModifierType)0;
}
else
@ -116,25 +114,25 @@ static gint pointer_motion_event (GtkWidget *widget, GdkEventMotion *event, gpoi
y = widget->allocation.height - y - 1;
wnd->OnMouseMove (x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
wnd->OnMouseMove(x, y, (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)
static gint size_allocate_event(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
{
GLWindow *wnd = (GLWindow*)data;
wnd->OnSize (allocation->width, allocation->height);
wnd->OnSize(allocation->width, allocation->height);
return TRUE;
}
/*
static void destroy_event (GtkWidget *widget, gpointer data)
static void destroy_event(GtkWidget *widget, gpointer data)
{
GLWindow *wnd = (GLWindow*)data;
wnd->DestroyContext ();
wnd->DestroyContext();
}
*/
@ -232,8 +230,7 @@ bool GLWindow::CreateFromWindow(void *data)
GTK_WIDGET_SET_FLAGS(prv->widget, GTK_CAN_FOCUS);
gtk_widget_set_events(GTK_WIDGET(prv->widget), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
gtk_widget_set_events(GTK_WIDGET(prv->widget), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
// Connect signal handlers
gtk_signal_connect(GTK_OBJECT(prv->widget), "expose_event", GTK_SIGNAL_FUNC(expose_event), this);
@ -313,7 +310,7 @@ void GLWindow::ReleaseMouse()
{
}
static void create_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, const char **xpm)
static void create_bitmap_and_mask_from_xpm(GdkBitmap **bitmap, GdkBitmap **mask, const char **xpm)
{
int height, width, colors;
char pixmap_buffer [(32 * 32)/8];
@ -321,16 +318,17 @@ static void create_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mas
int x, y, pix;
int transparent_color, black_color;
sscanf (xpm [0], "%d %d %d %d", &height, &width, &colors, &pix);
sscanf(xpm [0], "%d %d %d %d", &height, &width, &colors, &pix);
g_assert (height == 32);
g_assert (width == 32);
g_assert (colors == 3);
g_assert(height == 32);
g_assert(width == 32);
g_assert(colors == 3);
transparent_color = ' ';
black_color = '.';
for (y = 0; y < 32; y++)
{
for (x = 0; x < 32;)
{
char value = 0, maskv = 0;
@ -347,9 +345,10 @@ static void create_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mas
pixmap_buffer [(y * 4 + x/8)-1] = value;
mask_buffer [(y * 4 + x/8)-1] = maskv;
}
}
*bitmap = gdk_bitmap_create_from_data (NULL, pixmap_buffer, 32, 32);
*mask = gdk_bitmap_create_from_data (NULL, mask_buffer, 32, 32);
*bitmap = gdk_bitmap_create_from_data(NULL, pixmap_buffer, 32, 32);
*mask = gdk_bitmap_create_from_data(NULL, mask_buffer, 32, 32);
}
void GLWindow::SetCursor(LC_CURSOR_TYPE Type)