Author: Tim Felgentreff <[email protected]>
Branch: 
Changeset: r271:cb4ecb195c6e
Date: 2013-04-15 15:12 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/cb4ecb195c6e/

Log:    Apply cursor shape

diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -22,6 +22,7 @@
         assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
         RSDL.WM_SetCaption(title, "RSqueakVM")
         RSDL.EnableUNICODE(1)
+        SDLCursor.has_display = True
         self.has_surface = False
         self.mouse_position = [0, 0]
         self.button = 0
@@ -79,6 +80,8 @@
                                     self.key = ord(chars[0])
                                 else:
                                     pass # XXX: Todo?
+                    elif c_type == RSDL.QUIT:
+                        exit(0)
         finally:
             lltype.free(event, flavor='raw')
 
@@ -110,3 +113,46 @@
     def peek_keycode(self):
         self.get_next_event()
         return self.key
+
+
+class SDLCursorClass(object):
+    _attrs_ = ["cursor", "has_cursor", "has_display"]
+
+    instance = None
+
+    def __init__(self):
+        self.has_cursor = False
+        self.has_display = False
+
+    def set(self, data_words, w, h, x, y, mask_words=None):
+        if not self.has_display:
+            return
+        if self.has_cursor:
+            RSDL.FreeCursor(self.cursor)
+        try:
+            data = self.words_to_bytes(len(data_words) * 4, data_words)
+            try:
+                mask = self.words_to_bytes(len(data_words) * 4, mask_words)
+                self.cursor = RSDL.CreateCursor(data, mask, w, h, x, y)
+                self.has_cursor = True
+                RSDL.SetCursor(self.cursor)
+            finally:
+                lltype.free(mask, flavor="raw")
+        finally:
+            lltype.free(data, flavor="raw")
+
+    def words_to_bytes(self, bytenum, words):
+        bytes = lltype.malloc(RSDL.Uint8P.TO, bytenum, flavor="raw")
+        if words:
+            for pos in range(bytenum / 4):
+                word = words[pos]
+                bytes[pos * 4] = rffi.r_uchar((word >> 24) & 0xff)
+                bytes[pos * 4 + 1] = rffi.r_uchar((word >> 16) & 0xff)
+                bytes[pos * 4 + 2] = rffi.r_uchar((word >> 8) & 0xff)
+                bytes[pos * 4 + 3] = rffi.r_uchar(word & 0xff)
+        else:
+            for idx in range(bytenum):
+                bytes[idx] = rffi.r_uchar(0)
+        return bytes
+
+SDLCursor = SDLCursorClass()
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -585,7 +585,26 @@
     if argcount == 1:
         # TODO: use mask
         w_mask = s_frame.peek(0)
-    # TODO: Use info from cursor object.
+        if not isinstance(w_mask, model.W_WordsObject):
+            raise PrimitiveFailedError()
+    else:
+        w_mask = None
+    w_bitmap = w_rcvr.fetch(interp.space, 0)
+    if not isinstance(w_bitmap, model.W_WordsObject):
+        raise PrimitiveFailedError()
+    width = interp.space.unwrap_int(w_rcvr.fetch(interp.space, 1))
+    height = interp.space.unwrap_int(w_rcvr.fetch(interp.space, 2))
+    depth = interp.space.unwrap_int(w_rcvr.fetch(interp.space, 3))
+    hotpt = wrapper.PointWrapper(interp.space, w_rcvr.fetch(interp.space, 4))
+    display.SDLCursor.set(
+        w_bitmap.words,
+        width,
+        height,
+        hotpt.x(),
+        hotpt.y(),
+        w_mask.words if w_mask else None
+    )
+
     interp.space.objtable['w_cursor'] = w_rcvr
     return w_rcvr
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to