| | 15 | |
|---|
| | 16 | |
|---|
| | 17 | def _makeGlyphCellDragIcon(glyphs): |
|---|
| | 18 | font = None |
|---|
| | 19 | glyphRepresentation = None |
|---|
| | 20 | glyphWidth = None |
|---|
| | 21 | for glyph in glyphs: |
|---|
| | 22 | rep = glyph.getRepresentation("NSBezierPath") |
|---|
| | 23 | if not rep.isEmpty(): |
|---|
| | 24 | font = glyph.getParent() |
|---|
| | 25 | glyphRepresentation = rep |
|---|
| | 26 | glyphWidth = glyph.width |
|---|
| | 27 | break |
|---|
| | 28 | # set up the image |
|---|
| | 29 | iconImage = NSImage.alloc().initWithSize_((40, 40)) |
|---|
| | 30 | iconImage.lockFocus() |
|---|
| | 31 | context = NSGraphicsContext.currentContext() |
|---|
| | 32 | # draw the page base |
|---|
| | 33 | pageSize = 35 |
|---|
| | 34 | pagePath = NSBezierPath.bezierPath() |
|---|
| | 35 | pagePath.moveToPoint_((.5, 5.5)) |
|---|
| | 36 | pagePath.lineToPoint_((.5, 39.5)) |
|---|
| | 37 | pagePath.lineToPoint_((34.5, 39.5)) |
|---|
| | 38 | pagePath.lineToPoint_((34.5, 5.5)) |
|---|
| | 39 | pagePath.lineToPoint_((.5, 5.5)) |
|---|
| | 40 | # set the shadow |
|---|
| | 41 | context.saveGraphicsState() |
|---|
| | 42 | shadow = NSShadow.alloc().init() |
|---|
| | 43 | shadow.setShadowOffset_((1, -1)) |
|---|
| | 44 | shadow.setShadowColor_(NSColor.blackColor()) |
|---|
| | 45 | shadow.setShadowBlurRadius_(2.0) |
|---|
| | 46 | shadow.set() |
|---|
| | 47 | # fill the page |
|---|
| | 48 | NSColor.whiteColor().set() |
|---|
| | 49 | pagePath.fill() |
|---|
| | 50 | try: |
|---|
| | 51 | color1 = NSColor.colorWithCalibratedWhite_alpha_(.95, 1) |
|---|
| | 52 | color2 = NSColor.colorWithCalibratedWhite_alpha_(.85, 1) |
|---|
| | 53 | gradient = NSGradient.alloc().initWithColors_([color1, color2]) |
|---|
| | 54 | gradient.drawInBezierPath_angle_(pagePath, -90) |
|---|
| | 55 | except NameError: |
|---|
| | 56 | pass |
|---|
| | 57 | # remove the shadow |
|---|
| | 58 | context.restoreGraphicsState() |
|---|
| | 59 | # draw the glyph |
|---|
| | 60 | if glyphRepresentation is not None: |
|---|
| | 61 | context.saveGraphicsState() |
|---|
| | 62 | buffer = pageSize * .125 |
|---|
| | 63 | upm = font.info.unitsPerEm |
|---|
| | 64 | scale = (pageSize - buffer - buffer) / float(upm) |
|---|
| | 65 | xOffset = ((pageSize * (1.0 / scale)) - glyphWidth) / 2 |
|---|
| | 66 | transform = NSAffineTransform.transform() |
|---|
| | 67 | transform.translateXBy_yBy_(0, 5 + buffer) |
|---|
| | 68 | transform.scaleBy_(scale) |
|---|
| | 69 | transform.translateXBy_yBy_(xOffset, -font.info.descender) |
|---|
| | 70 | transform.concat() |
|---|
| | 71 | NSColor.colorWithCalibratedWhite_alpha_(0, .8).set() |
|---|
| | 72 | # XXX should clip the glyph path here to prevent overflow |
|---|
| | 73 | glyphRepresentation.fill() |
|---|
| | 74 | context.restoreGraphicsState() |
|---|
| | 75 | # draw the page border |
|---|
| | 76 | NSColor.grayColor().set() |
|---|
| | 77 | pagePath.stroke() |
|---|
| | 78 | # done |
|---|
| | 79 | iconImage.unlockFocus() |
|---|
| | 80 | # add the count badge |
|---|
| | 81 | return addCountBadgeToIcon(len(glyphs), iconImage) |
|---|