API for seesaw.graphics - Seesaw

by Dave Ray

Full namespace name: seesaw.graphics

Overview

Basic graphics functions to simplify use of Graphics2D.

Public Variables and Functions



anti-alias

function
Usage: (anti-alias g2d)
Enable anti-aliasing on the given Graphics2D object.

Returns g2d.


circle

function
Usage: (circle x y radius)
Create a circle with the given center and radius


draw

function
Usage: (draw g2d)
       (draw g2d shape style)
       (draw g2d shape style & more)
Draw a one or more shape/style pairs to the given graphics context.

shape should be an object that implements Draw protocol (see (rect),
(ellipse), etc.

style is a style object created with (style). If the style's :foreground
is non-nil, the border of the shape is drawn with the given stroke. If
the style's :background is non-nil, the shape is filled with that color.

Returns g2d.


ellipse

function
Usage: (ellipse x y w h)
       (ellipse x y w)
Create an ellipse that occupies the given rectangular region


linear-gradient

function
Usage: (linear-gradient & {:keys [start end fractions colors cycle], :or {start default-start, end default-end, fractions default-fractions, colors default-colors, cycle :none}, :as opts})
Creates a linear gradient suitable for use on the :foreground and
:background properties of a (seesaw.graphics/style), or anywhere
a java.awt.Paint is required. Has the following options:

  :start The start [x y] point, defaults to [0 0]
  :end   The end [x y] point, defaults to [1 0]
  :fractions Sequence of fractional values indicating color transition points
             in the gradient. Defaults to [0.0 1.0]. Must have same number
             of entries as :colors.
  :colors Sequence of color values correspoding to :fractions. Value is passed
          through (seesaw.color/to-color). e.g. :blue, "#fff", etc.
  :cycle The cycle behavior of the gradient, :none, :repeat, or :reflect.
         Defaults to :none.

Examples:

  ; create a horizontal red, white and blue gradiant with three equal parts
  (linear-gradient :fractions [0 0.5 1.0] :colors [:red :white :blue])

See:
  http://docs.oracle.com/javase/6/docs/api/java/awt/LinearGradientPaint.html


polygon

function
Usage: (polygon & points)
Create a polygonal shape with the given set of vertices.
points is a list of x/y pairs, e.g.:

  (polygon [1 2] [3 4] [5 6])


push

macro
Usage: (push g2d & forms)
Push a Graphics2D context (Graphics2d/create) and automatically dispose it.

For example, in a paint handler:

  (fn [c g2d]
    (.setColor g2d java.awt.Color/RED)
    (.drawString g2d "This string is RED" 0 20)
    (push g2d
      (.setColor g2d java.awt.Color/BLUE)
      (.drawString g2d "This string is BLUE" 0 40))
    (.drawString g2d "This string is RED again" 0 60))


radial-gradient

function
Usage: (radial-gradient & {:keys [center focus radius fractions colors cycle], :or {center default-center, radius default-radius, fractions default-fractions, colors default-colors, cycle :none}, :as opts})
Creates a radial gradient suitable for use on the :foreground and
:background properties of a (seesaw.graphics/style), or anywhere
a java.awt.Paint is required. Has the following options:

  :center The center [x y] point, defaults to [0 0]
  :focus The focus [x y] point, defaults to :center
  :radius   The radius. Defaults to 1.0
  :fractions Sequence of fractional values indicating color transition points
             in the gradient. Defaults to [0.0 1.0]. Must have same number
             of entries as :colors.
  :colors Sequence of color values correspoding to :fractions. Value is passed
          through (seesaw.color/to-color). e.g. :blue, "#fff", etc.
  :cycle The cycle behavior of the gradient, :none, :repeat, or :reflect.
         Defaults to :none.

Examples:

  ; create a red, white and blue gradiant with three equal parts
  (radial-gradient :radius 100.0 :fractions [0 0.5 1.0] :colors [:red :white :blue])

See:
  http://docs.oracle.com/javase/6/docs/api/java/awt/RadialGradientPaint.html


rect

function
Usage: (rect x y w h)
       (rect x y w)
Create a rectangular shape with the given upper-left corner, width and
height.


rotate

function
Usage: (rotate g2d degrees)
Apply a rotation to the graphics context by degrees

Returns g2d


rounded-rect

function
Usage: (rounded-rect x y w h rx ry)
       (rounded-rect x y w h rx)
       (rounded-rect x y w h)
Create a rectangular shape with the given upper-left corner, width,
height and corner radii.


scale

function
Usage: (scale g2d sx sy)
       (scale g2d s)
Apply a scale factor to the graphics context

Returns g2d


stroke

function
Usage: (stroke & {:keys [width cap join miter-limit dashes dash-phase], :or {width 1, cap :square, join :miter, miter-limit 10.0, dashes nil, dash-phase 0.0}})
Create a new stroke with the given properties:

  :width Width of the stroke


style

function
Usage: (style & {:keys [foreground background stroke font]})
Create a new style object for use with (seesaw.graphics/draw). Takes a list
of key/value pairs:

  :foreground A color value (see seesaw.color) for the foreground (stroke)
  :background A color value (see seesaw.color) for the background (fill)
  :stroke     A stroke value used to draw outlines (see seesaw.graphics/stroke)
  :font       Font value used for drawing text shapes

  The default value for all properties is nil. See (seesaw.graphics/draw) for
  interpretation of nil values.

Notes:

  Style objects are immutable so they can be efficiently "pre-compiled" and
  used for drawing multiple shapes.

Examples:

  ; Red on black
  (style :foreground :red :background :black :font :monospace)

  ; Red, 8-pixel line with no fill.
  (style :foreground :red :stroke 8)

See:
  (seesaw.graphics/update-style)
  (seesaw.graphics/draw)


translate

function
Usage: (translate g2d dx dy)
Apply a translation to the graphics context

Returns g2d


update-style

function
Usage: (update-style s & {:keys [foreground background stroke font], :or {foreground (:foreground s), background (:background s), stroke (:stroke s), font (:font s)}})
Update a style with new properties and return a new style. This is basically
exactly the same as (clojure.core/assoc) with the exception that color, stroke,
and font values are interpreted by Seesaw.

Examples:

  (def start (style :foreground blue :background :white))
  (def no-fill (update-style start :background nil))
  (def red-line (update-style no-fill :foreground :red))

See:
  (seesaw.graphics/style)
  (seesaw.graphics/draw)
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.