def makeCursor(self): try: Scale = Glyphs.font.currentTab.scale if abs(Scale - self.lastScale) < 0.001: return # x, y = 100, 100 x, y, circleCursorColor = self.getCursorSize() # print("__getCursorSize", x, y, circleCursorColor) if x > 0 and y > 0: ImageSize = NSMakeSize(math.ceil(x * Scale), math.ceil(y * Scale)) # print(math.ceil(x * Scale), math.ceil(y * Scale)) circleCursorImage = NSImage.alloc().initWithSize_(ImageSize) circleCursorImage.lockFocus() rect = NSMakeRect(0, 0, x * Scale, y * Scale) # circleCursorColor = 0.5, 0.5, 0.5, 0.9 NSColor.colorWithCalibratedRed_green_blue_alpha_( *circleCursorColor).set() NSBezierPath.bezierPathWithOvalInRect_(rect).fill() try: fontSize = 18 fontAttributes = { #NSFontAttributeName: NSFont.labelFontOfSize_(10.0), NSFontAttributeName: NSFont.systemFontOfSize_weight_(fontSize, 0.0), NSForegroundColorAttributeName: NSColor.blackColor() } displayText = NSAttributedString.alloc( ).initWithString_attributes_( self.getCursorType(circleCursorColor), fontAttributes) textAlignment = 4 # top left: 6, top center: 7, top right: 8, center left: 3, center center: 4, center right: 5, bottom left: 0, bottom center: 1, bottom right: 2 #font = layer.parent.parent displayText.drawAtPoint_alignment_( NSMakePoint(0 + x * Scale / 2, 0 + y * Scale / 2), textAlignment) except: print(traceback.format_exc()) circleCursorImage.unlockFocus() self.circleCursor = NSCursor.alloc().initWithImage_hotSpot_( circleCursorImage, NSMakePoint(x / 2 * Scale, y / 2 * Scale)) try: if self.editViewController().graphicView().cursor( ) != self.circleCursor: self.editViewController().graphicView().setCursor_( self.circleCursor) except: pass except Exception as e: print(traceback.format_exc())
def makeCursor(self): try: Scale = Glyphs.font.currentTab.scale if abs(Scale - self.lastScale) < 0.001: return # x, y = 100, 100 x, y, circleCursorColor = self.getCursorSize() # print "__getCursorSize", x, y, circleCursorColor if x > 0 and y > 0: ImageSize = NSMakeSize(math.ceil(x * Scale), math.ceil(y * Scale)) # print math.ceil(x * Scale), math.ceil(y * Scale) circleCursorImage = NSImage.alloc().initWithSize_(ImageSize) circleCursorImage.lockFocus() rect = NSMakeRect(0, 0, x * Scale, y * Scale) # circleCursorColor = 0.5, 0.5, 0.5, 0.9 NSColor.colorWithCalibratedRed_green_blue_alpha_( *circleCursorColor ).set() NSBezierPath.bezierPathWithOvalInRect_(rect).fill() try: fontSize = 18 fontAttributes = { #NSFontAttributeName: NSFont.labelFontOfSize_(10.0), NSFontAttributeName: NSFont.systemFontOfSize_weight_(fontSize,0.0), NSForegroundColorAttributeName: NSColor.blackColor() } displayText = NSAttributedString.alloc().initWithString_attributes_( self.getCursorType(circleCursorColor), fontAttributes) textAlignment = 4 # top left: 6, top center: 7, top right: 8, center left: 3, center center: 4, center right: 5, bottom left: 0, bottom center: 1, bottom right: 2 #font = layer.parent.parent displayText.drawAtPoint_alignment_(NSMakePoint(0 + x * Scale / 2, 0 + y * Scale / 2 ), textAlignment) except: print traceback.format_exc() circleCursorImage.unlockFocus() self.circleCursor = NSCursor.alloc().initWithImage_hotSpot_(circleCursorImage, NSMakePoint(x / 2 * Scale, y / 2 * Scale)) try: if self.editViewController().graphicView().cursor() != self.circleCursor: self.editViewController().graphicView().setCursor_(self.circleCursor) except: pass except Exception as e: print traceback.format_exc()
def _make_empty_cursor(): global _empty_cursor if not _empty_cursor: from AppKit import NSCursor, NSImage, NSBitmapImageRep, NSDeviceRGBColorSpace from GUI import Cursor import sys if sys.version_info >= (3, 0): b = bytes([0]) else: b = "\x00" d = b * 1024 ns_bitmap = NSBitmapImageRep.alloc().\ initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_\ ((d, d, d, d, d), 16, 16, 8, 4, True, False, NSDeviceRGBColorSpace, 64, 32) ns_image = NSImage.alloc().initWithSize_((16, 16)) ns_image.addRepresentation_(ns_bitmap) ns_cursor = NSCursor.alloc().initWithImage_hotSpot_(ns_image, (0, 0)) _empty_cursor = Cursor._from_ns_cursor(ns_cursor) _empty_cursor._data = d return _empty_cursor
def _init_from_image_and_hotspot(self, image, hotspot): #print "Cursor._init_from_image_and_hotspot:", image, hotspot ### ns_image = image._ns_image.copy() ns_image.setFlipped_(False) self._ns_cursor = NSCursor.alloc().initWithImage_hotSpot_( ns_image, hotspot)