Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary Martin <gary@garycmartin.com>2009-08-27 01:54:52 (GMT)
committer Gary Martin <gary@garycmartin.com>2009-08-27 01:54:52 (GMT)
commit2595c0520fdb4a93c7537c96824ae3eaaa546c78 (patch)
tree6230bd85a79b71c2cd1a0a5766438d809ef16820
parentc62859f5c9ac7c17650d781c547f1cfb32f21517 (diff)
Added better fake Sugar cursor to the PyGame canvas.
Ouch, this took a while. Using a real png with alpha, an invisible PyGame cursor, and some gtk events so that the fake cursor is hidden as it enters the Sugar toolbar area.
-rw-r--r--MANIFEST5
-rw-r--r--physics.py28
-rw-r--r--standardcursor.pngbin0 -> 640 bytes
-rw-r--r--standardcursor.xbm20
-rw-r--r--standardcursor_mask.xbm20
5 files changed, 25 insertions, 48 deletions
diff --git a/MANIFEST b/MANIFEST
index e23f49c..c59bdb1 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -294,5 +294,6 @@ lib/Elements-0.13-py2.5.egg
lib/pkg_resources.py
activity/application-x-physics-project.svg
activity/mimetypes.xml
-standardcursor.xbm
-standardcursor_mask.xbm
+
+
+standardcursor.png
diff --git a/physics.py b/physics.py
index 21d3beb..5788ff9 100644
--- a/physics.py
+++ b/physics.py
@@ -28,7 +28,7 @@ import Box2D as box2d
import elements
import tools
from helpers import *
-
+import gtk
class PhysicsGame:
def __init__(self,screen):
@@ -48,10 +48,23 @@ class PhysicsGame:
self.world.renderer.set_surface(self.screen)
# set up static environment
- self.world.add.ground()
+ self.world.add.ground()
+
+ # Fake a Sugar cursor for the pyGame canvas area
+ self.show_fake_cursor = False
+ pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
+ self.cursor_picture = pygame.image.load('standardcursor.png')
+ self.cursor_picture.convert_alpha()
+ self.canvas.connect("enter_notify_event", self.switch_on_fake_pygame_cursor_cb)
+ self.canvas.connect("leave_notify_event", self.switch_off_fake_pygame_cursor_cb)
+ self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK
+ | gtk.gdk.LEAVE_NOTIFY_MASK)
+
+ def switch_off_fake_pygame_cursor_cb(self, panel, event):
+ self.show_fake_cursor = False
- a, b, c, d = pygame.cursors.load_xbm("standardcursor.xbm", "standardcursor_mask.xbm")
- pygame.mouse.set_cursor(a, b, c, d)
+ def switch_on_fake_pygame_cursor_cb(self, panel, event):
+ self.show_fake_cursor = True
def run(self):
self.running = True
@@ -60,7 +73,6 @@ class PhysicsGame:
self.currentTool.handleEvents(event)
# Clear Display
self.screen.fill((255,255,255)) #255 for white
-
if self.world.run_physics:
for body in self.world.world.GetBodyList():
if type(body.userData) == type({}):
@@ -74,7 +86,11 @@ class PhysicsGame:
# draw output from tools
self.currentTool.draw()
-
+
+ # Show Sugar like cursor for UI consistancy
+ if self.show_fake_cursor:
+ self.screen.blit(self.cursor_picture, pygame.mouse.get_pos())
+
# Flip Display
pygame.display.flip()
diff --git a/standardcursor.png b/standardcursor.png
new file mode 100644
index 0000000..20e4154
--- /dev/null
+++ b/standardcursor.png
Binary files differ
diff --git a/standardcursor.xbm b/standardcursor.xbm
deleted file mode 100644
index ad9e6fd..0000000
--- a/standardcursor.xbm
+++ /dev/null
@@ -1,20 +0,0 @@
-#define _width 40
-#define _height 40
-static char _bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF,
- 0xFF, 0x3F, 0x00, 0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0xFC, 0xFF, 0xFF, 0xFF,
- 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0x00, 0xFC,
- 0xFF, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0xFC, 0xFF, 0xFF,
- 0x3F, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x01, 0x00, 0x00,
- 0xFC, 0xFF, 0x03, 0x00, 0x00, 0xFC, 0xFF, 0x07, 0x00, 0x00, 0xFC, 0xFF,
- 0x0F, 0x00, 0x00, 0xFC, 0xFF, 0x1F, 0x00, 0x00, 0xFC, 0xFB, 0x3F, 0x00,
- 0x00, 0xFC, 0xF3, 0x7F, 0x00, 0x00, 0xFC, 0xE3, 0xFF, 0x00, 0x00, 0xFC,
- 0xC3, 0xFF, 0x01, 0x00, 0xFC, 0x83, 0xFF, 0x03, 0x00, 0xFC, 0x03, 0xFF,
- 0x07, 0x00, 0xFC, 0x03, 0xFE, 0x0F, 0x00, 0xFC, 0x03, 0xFC, 0x1F, 0x00,
- 0xFC, 0x03, 0xF8, 0x3F, 0x00, 0xFC, 0x03, 0xF0, 0x7F, 0x00, 0xFC, 0x03,
- 0xE0, 0xFF, 0x00, 0xFC, 0x03, 0xC0, 0xFF, 0x01, 0xFC, 0x03, 0x80, 0xFF,
- 0x01, 0xFC, 0x03, 0x00, 0xFF, 0x03, 0xF8, 0x01, 0x00, 0xFE, 0x01, 0xF0,
- 0x00, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
- 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
diff --git a/standardcursor_mask.xbm b/standardcursor_mask.xbm
deleted file mode 100644
index 9384f80..0000000
--- a/standardcursor_mask.xbm
+++ /dev/null
@@ -1,20 +0,0 @@
-#define _width 40
-#define _height 40
-static char _bits[] = {
- 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0xFF, 0xFF,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