class Demo::CairoCurveRectangle

Constants

RADIUS
RECT_HEIGHT
RECT_WIDTH
X0

a custom shape, that could be wrapped in a function

X1
Y0
Y1

Public Class Methods

new() click to toggle source
Calls superclass method
# File gtk2/sample/gtk-demo/cairo-curve-rectangle.rb, line 25
def initialize
  super('cairo curve rectangle')
end

Public Instance Methods

draw(cr) click to toggle source
# File gtk2/sample/gtk-demo/cairo-curve-rectangle.rb, line 29
def draw(cr)
  return if (RECT_WIDTH <= 0 || RECT_HEIGHT <= 0)
    
  if (RECT_WIDTH / 2 < RADIUS)
    if (RECT_HEIGHT / 2 < RADIUS)
      cr.move_to(X0, (Y0 + Y1) / 2)
      cr.curve_to(X0 ,Y0, X0, Y0, (X0 + X1) / 2, Y0)
      cr.curve_to(X1, Y0, X1, Y0, X1, (Y0 + Y1) / 2)
      cr.curve_to(X1, Y1, X1, Y1, (X1 + X0) / 2, Y1)
      cr.curve_to(X0, Y1, X0, Y1, X0, (Y0 + Y1) / 2)
    else
      cr.move_to(X0, Y0 + RADIUS)
      cr.curve_to(X0 ,Y0, X0, Y0, (X0 + X1) / 2, Y0)
      cr.curve_to(X1, Y0, X1, Y0, X1, Y0 + RADIUS)
      cr.line_to(X1 , Y1 - RADIUS)
      cr.curve_to(X1, Y1, X1, Y1, (X1 + X0) / 2, Y1)
      cr.curve_to(X0, Y1, X0, Y1, X0, Y1- RADIUS)
    end
  else
    if (RECT_HEIGHT / 2 < RADIUS)
      cr.move_to(X0, (Y0 + Y1) / 2)
      cr.curve_to(X0, Y0, X0 , Y0, X0 + RADIUS, Y0)
      cr.line_to(X1 - RADIUS, Y0)
      cr.curve_to(X1, Y0, X1, Y0, X1, (Y0 + Y1) / 2)
      cr.curve_to(X1, Y1, X1, Y1, X1 - RADIUS, Y1)
      cr.line_to(X0 + RADIUS, Y1)
      cr.curve_to(X0, Y1, X0, Y1, X0, (Y0 + Y1) / 2)
    else
      cr.move_to(X0, Y0 + RADIUS)
      cr.curve_to(X0 , Y0, X0 , Y0, X0 + RADIUS, Y0)
      cr.line_to(X1 - RADIUS, Y0)
      cr.curve_to(X1, Y0, X1, Y0, X1, Y0 + RADIUS)
      cr.line_to(X1 , Y1 - RADIUS)
      cr.curve_to(X1, Y1, X1, Y1, X1 - RADIUS, Y1)
      cr.line_to(X0 + RADIUS, Y1)
      cr.curve_to(X0, Y1, X0, Y1, X0, Y1- RADIUS)
    end
  end
  
  cr.close_path

  cr.set_source_rgba(0.5,0.5,1)
  cr.fill_preserve
  cr.set_source_rgba(0.5, 0, 0, 0.5)
  cr.stroke
end