1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
RADIUS <- 150
N.WORDS <- 10
FONT <- "Sans Bold 27"
draw.text <- function(widget, event, data)
{
width <- widget[["allocation"]][["width"]]
height <- widget[["allocation"]][["height"]]
device.radius <- min(width, height) / 2.
cr <- gdkCairoCreate(widget[["window"]])
# Center coordinates on the middle of the region we are drawing
cr$translate(device.radius + (width - 2 * device.radius) / 2,
device.radius + (height - 2 * device.radius) / 2)
cr$scale(device.radius / RADIUS, device.radius / RADIUS)
# Create a PangoLayout, set the font and text
layout <- pangoCairoCreateLayout(cr)
layout$setText("Text")
desc <- pangoFontDescriptionFromString(FONT)
layout$setFontDescription(desc)
# Draw the layout N.WORDS times in a circle
for (i in 1:N.WORDS)
{
angle <- (360 * i) / N.WORDS
cr$save()
# Gradient from red at angle 60 to blue at angle 300
red <- (1 + cos((angle - 60) * pi / 180)) / 2
cr$setSourceRgb(red, 0, 1.0 - red)
cr$rotate(angle * pi / 180)
# Inform Pango to re-layout the text with the new transformation
pangoCairoUpdateLayout(cr, layout)
size <- layout$getSize()
cr$moveTo(- (size$width / PANGO_SCALE) / 2, - RADIUS)
pangoCairoShowLayout(cr, layout)
cr$restore()
}
return(FALSE)
}
white <- c( 0, "0xffff", "0xffff", "0xffff" )
window <- gtkWindowNew("toplevel", show = F)
window$setTitle("Rotated Text")
drawing.area <- gtkDrawingAreaNew()
window$add(drawing.area)
# This overrides the background color from the theme
drawing.area$modifyBg("normal", white)
gSignalConnect(drawing.area, "expose-event", draw.text)
window$showAll()
|