#
hs.drawing
DEPRECATED. Primitives for drawing on the screen in various ways.
hs.drawing is now deprecated and will be removed in a future release. Its functionality is now implemented by hs.canvas and you should migrate your code to using that directly. The API docs for hs.drawing remain here as a convenience.
#
Submodules
#
API Overview
Constants - Useful values which cannot be changed
windowBehaviors windowLevels
Functions - API calls offered directly by the extension
defaultTextStyle disableScreenUpdates enableScreenUpdates getTextDrawingSize
Constructors - API calls which return an object, typically one that offers API methods
appImage arc circle ellipticalArc image line rectangle text
Methods - API calls which can only be made on an object returned by a constructor
alpha behavior behaviorAsLabels bringToFront clickCallbackActivating clippingRectangle delete frame getStyledText hide imageAlignment imageAnimates imageFrame imageScaling orderAbove orderBelow rotateImage sendToBack setAlpha setArcAngles setBehavior setBehaviorByLabels setClickCallback setFill setFillColor setFillGradient setFrame setImage setImageASCII setImageFromPath setLevel setRoundedRectRadii setSize setStroke setStrokeColor setStrokeWidth setStyledText setText setTextColor setTextFont setTextSize setTextStyle setTopLeft show
#
API Documentation
#
Constants
#
windowBehaviors
#
windowLevels
#
Functions
#
defaultTextStyle
#
disableScreenUpdates
#
enableScreenUpdates
#
getTextDrawingSize
#
Constructors
#
appImage
#
arc
#
circle
#
ellipticalArc
#
image
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.drawing.image(sizeRect, imageData) -> drawingObject or nil
|
| Type | Constructor |
| Description | Creates a new image object |
| Parameters |
- sizeRect - A rect-table containing the location/size of the image
- imageData - This can be either:
An
hs.image
object A string containing a path to an image file A string beginning withASCII:
which signifies that the rest of the string is interpreted as a special form of ASCII diagram, which will be rendered to an image. See the notes below for information about the special format of ASCII diagram.
- An
hs.drawing
object, or nil if an error occurs - Paths relative to the PWD of Hammerspoon (typically ~/.hammerspoon/) will work, but paths relative to the UNIX homedir character,
~
will not - Animated GIFs are supported. They're not super friendly on your CPU, but they work
- To use the ASCII diagram image support, see http://cocoamine.net/blog/2015/03/20/replacing-photoshop-with-nsstring/ and be sure to preface your ASCII diagram with the special string
ASCII:
#
line
#
rectangle
#
text
#
Methods
#
alpha
#
behavior
#
behaviorAsLabels
#
bringToFront
#
clickCallbackActivating
#
clippingRectangle
#
delete
#
frame
#
getStyledText
#
hide
#
imageAlignment
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.drawing:imageAlignment([type]) -> drawingObject or current value
|
| Type | Method |
| Description | Get or set the alignment of an image that doesn't fully fill the drawing objects frame. |
| Parameters |
- type - an optional string value which should match one of the following (default is center): topLeft - the image's top left corner will match the drawing frame's top left corner top - the image's top match the drawing frame's top and will be centered horizontally topRight - the image's top right corner will match the drawing frame's top right corner left - the image's left side will match the drawing frame's left side and will be centered vertically center - the image will be centered vertically and horizontally within the drawing frame right - the image's right side will match the drawing frame's right side and will be centered vertically bottomLeft - the image's bottom left corner will match the drawing frame's bottom left corner bottom - the image's bottom match the drawing frame's bottom and will be centered horizontally bottomRight - the image's bottom right corner will match the drawing frame's bottom right corner
- If a setting value is provided, the drawing object is returned; if no argument is provided, the current setting is returned.
#
imageAnimates
#
imageFrame
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.drawing:imageFrame([type]) -> drawingObject or current value
|
| Type | Method |
| Description | Get or set what type of frame should be around the drawing frame of the image. |
| Parameters |
- type - an optional string value which should match one of the following (default is none): none - no frame is drawing around the drawingObject's frameRect photo - a thin black outline with a white background and a dropped shadow. bezel - a gray, concave bezel with no background that makes the image look sunken. groove - a thin groove with a gray background that looks etched around the image. button - a convex bezel with a gray background that makes the image stand out in relief, like a button.
- If a setting value is provided, the drawing object is returned; if no argument is provided, the current setting is returned.
- Apple considers the photo, groove, and button style frames "stylistically obsolete" and if a frame is required, recommend that you use the bezel style or draw your own to more closely match the OS look and feel.
#
imageScaling
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.drawing:imageScaling([type]) -> drawingObject or current value
|
| Type | Method |
| Description | Get or set how an image is scaled within the frame of a drawing object containing an image. |
| Parameters |
- type - an optional string value which should match one of the following (default is scaleProportionally): shrinkToFit - shrink the image, preserving the aspect ratio, to fit the drawing frame only if the image is larger than the drawing frame. scaleToFit - shrink or expand the image to fully fill the drawing frame. This does not preserve the aspect ratio. none - perform no scaling or resizing of the image. scaleProportionally - shrink or expand the image to fully fill the drawing frame, preserving the aspect ration.
- If a setting value is provided, the drawing object is returned; if no argument is provided, the current setting is returned.
#
orderAbove
#
orderBelow
#
rotateImage
#
sendToBack
#
setAlpha
#
setArcAngles
#
setBehavior
#
setBehaviorByLabels
#
setClickCallback
#
setFill
#
setFillColor
#
setFillGradient
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.drawing:setFillGradient(startColor, endColor, angle) -> drawingObject
|
| Type | Method |
| Description | Sets the fill gradient of a drawing object |
| Parameters |
- startColor - A table containing color component values between 0.0 and 1.0 for each of the keys: red (default 0.0) green (default 0.0) blue (default 0.0) alpha (default 1.0)
- endColor - A table containing color component values between 0.0 and 1.0 for each of the keys: red (default 0.0) green (default 0.0) blue (default 0.0) alpha (default 1.0)
- angle - A number representing the angle of the gradient, measured in degrees, counter-clockwise, from the left of the drawing object
- The drawing object
- This method should only be used on rectangle, circle, or arc drawing objects
- Calling this method will remove any fill color previously set with
hs.drawing:setFillColor()
#
setFrame
#
setImage
#
setImageASCII
#
setImageFromPath
#
setLevel
#
setRoundedRectRadii
#
setSize
#
setStroke
#
setStrokeColor
#
setStrokeWidth
#
setStyledText
#
setText
#
setTextColor
#
setTextFont
#
setTextSize
#
setTextStyle
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.drawing:setTextStyle([textStyle]) -> drawingObject
|
| Type | Method |
| Description | Sets some simple style parameters for the entire text of a drawing object. For more control over style including having multiple styles within a single text object, use hs.styledtext
and hs.drawing:setStyledText
instead. |
| Parameters |
- textStyle - an optional table containing one or more of the following keys to set for the text of the drawing object (if the table is nil or left out, the style is reset to the
hs.drawing
defaults): font - the name of the font to use (default: the system font) size - the font point size to use (default: 27.0) color - a color table as described inhs.drawing.color
alignment - a string of one of the following indicating the texts alignment within the drawing objects frame:"left" - the text is visually left aligned."right" - the text is visually right aligned."center" - the text is visually center aligned."justified" - the text is justified"natural" - (default) the natural alignment of the text’s script lineBreak - a string of one of the following indicating how to wrap text which exceeds the drawing object's frame:"wordWrap" - (default) wrap at word boundaries, unless the word itself doesn’t fit on a single line"charWrap" - wrap before the first character that doesn’t fit"clip" - do not draw past the edge of the drawing object frame"truncateHead" - the line is displayed so that the end fits in the frame and the missing text at the beginning of the line is indicated by an ellipsis"truncateTail" - the line is displayed so that the beginning fits in the frame and the missing text at the end of the line is indicated by an ellipsis"truncateMiddle" - the line is displayed so that the beginning and end fit in the frame and the missing text in the middle is indicated by an ellipsis
- The drawing object
- This method should only be used on text drawing objects
- If the text of the drawing object is currently empty (i.e. "") then style changes may be lost. Use a placeholder such as a space (" ") or hide the object if style changes need to be saved but the text should disappear for a while.
- Only the keys specified are changed. To reset an object to all of its defaults, call this method with an explicit nil as its only parameter (e.g.
hs.drawing:setTextStyle(nil)
- The font, font size, and font color can also be set by their individual specific methods as well; this method is provided so that style components can be stored and applied collectively, as well as used by
hs.drawing.getTextDrawingSize()
to determine the proper rectangle size for a textual drawing object.