rubymotion needs...

136 views
Skip to first unread message

Colin Thomas-Arnold

unread,
Jul 26, 2012, 1:03:58 AM7/26/12
to rubym...@googlegroups.com
...a simpler way to do CoreGraphics.

These drawing primitives are amazing, you can do really neat stuff... but UG

    context = UIGraphicsGetCurrentContext

    CGContextSaveGState(context)  # Save Context State Before Drawing "linePath" Shadow

    linePath = CGPathCreateMutable()
    linePathY = 10.0
    CGPathMoveToPoint(linePath, nil, 1.0, linePathY)
    CGPathAddLineToPoint(linePath, nil, self.bounds.size.width, linePathY)
    CGContextAddPath(context, linePath)
    CGPathRelease(linePath)

    CGContextSetLineWidth(context, 1.0)
    CGContextSetStrokeColorWithColor(context, :black.uicolor(0.6).CGColor)
    CGContextSetShadowWithColor(context, CGSizeMake(0.0, 1.0), 0.0, :white.uicolor(0.2).CGColor)
    CGContextDrawPath(context, KCGPathStroke)
    CGContextRestoreGState(context) # Restore Context State After Drawing "linePath" Shadow

That draws a friggin' HORIZONTAL LINE PEOPLE.

:-|

Mateus

unread,
Jul 26, 2012, 3:14:44 AM7/26/12
to rubym...@googlegroups.com
2 years ago, I wrote some helpers for MacRuby CoreGraphics, you have to be careful when you're dealing with them,
they're very expressive, wrapping them you lose the expressiveness and could be really difficult to debug when you have an issue. specially since we can not use instrument directly.

But you can reduce the Context state save and restore:

def CGContextSaveRestoreGState(&blk)
  context = UIGraphicsGetCurrentContext
  CGContextSaveGState(context)
  blk[context]
  CGContextRestoreGState(context)

end

CGContextSaveRestoreGState do |context|
  line_path = CGPathCreateMutable()
  line_pathY = 10.0
  CGPathMoveToPoint(linePath, nil, 1.0, line_pathY)
  CGPathAddLineToPoint(line_path, nil, self.bounds.size.width, line_pathY)
  CGContextAddPath(context, line_path)
  CGPathRelease(line_path)
  CGContextSetLineWidth(context, 1.0)
  CGContextSetStrokeColorWithColor(context, :black.uicolor(0.6).CGColor)
  CGContextSetShadowWithColor(context, CGSizeMake(0.0, 1.0), 0.0, :white.u
  CGContextDrawPath(context, KCGPathStroke)

end 

It feels more naturally for me :-), I think people writing Cocoa-/Touch Wrappers should really understand what they're doing, I've seen some really big Problems with Rubymotion Libs that are using to much memory because people don't reuse cell and overusing the Main queue/thread.


BR,

Mateus


Amit Kumar

unread,
Jul 26, 2012, 3:47:58 AM7/26/12
to rubym...@googlegroups.com
I have a little complex requirement..
I have to create curves and have data points which can be dragged along the path of the curve

haven't played with coreplot yet; has anyone tried to do something similar ?

--
 
 
 

Reply all
Reply to author
Forward
0 new messages