Html5 canvas 卡布奇诺网络框架中是否有类似HTML5画布的控件?

Html5 canvas 卡布奇诺网络框架中是否有类似HTML5画布的控件?,html5-canvas,cappuccino,Html5 Canvas,Cappuccino,我正在用卡布奇诺(Cappuccino)创建一个webapp,我需要一种在CPWindow上绘制形状(矩形、图像等)的方法。是否有任何小部件/控件可用于执行此操作?在Sproutcore等其他框架中是否有类似的控件?还是我必须实施我自己的 我还想知道是否有办法使形状可拖动?在卡布奇诺中,您可以在任何视图中执行自定义绘图。为此,重写drawRect:方法(从CPView继承的任何方法,它几乎是每个控件的继承方法)。您可以使用CPGraphics工具(如),也可以使用CoreGraphics和命令(

我正在用卡布奇诺(Cappuccino)创建一个webapp,我需要一种在
CPWindow
上绘制形状(矩形、图像等)的方法。是否有任何小部件/控件可用于执行此操作?在Sproutcore等其他框架中是否有类似的控件?还是我必须实施我自己的


我还想知道是否有办法使形状可拖动?

在卡布奇诺中,您可以在任何视图中执行自定义绘图。为此,重写
drawRect:
方法(从
CPView
继承的任何方法,它几乎是每个控件的继承方法)。您可以使用CPGraphics工具(如),也可以使用CoreGraphics和命令(如)进行绘制,以了解有关绘制Apple文档的后一种样式的更多信息。记住卡布奇诺是基于Objective-C和可可粉的

下面是一个示例视图,该视图在圆角矩形中绘制了一个带点边框的黄色星形,大小适合当前视图:

@implementation CustomDrawView : CPView
{
}

- (void)drawRect:(CGRect)aRect
{
    [super drawRect:aRect];

    [[CPColor whiteColor] set];
    [[CPBezierPath bezierPathWithRect:bounds] fill];

    var frame =[self bounds],
        shadow = [[CPShadow alloc] init];

    [shadow setShadowColor:[CPColor blackColor]];
    [shadow setShadowOffset:CGSizeMake(0, 3)];
    [shadow setShadowBlurRadius:5];

    //// Rounded Rectangle Drawing
    var roundedRectanglePath = [CPBezierPath bezierPathWithRoundedRect:CGRectMake(CGRectGetMinX(frame) + 3.5, CGRectGetMinY(frame) + 3.5, CGRectGetWidth(frame) - 7, CGRectGetHeight(frame) - 7) xRadius:7 yRadius:7];
    [[CPColor blackColor] setStroke];
    [roundedRectanglePath setLineWidth:1];
    var roundedRectanglePattern = [5, 1, 1, 1];
    [roundedRectanglePath setLineDash:roundedRectanglePattern phase:0];
    [roundedRectanglePath stroke];

    var starPath = [CPBezierPath bezierPath];
    [starPath moveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.50000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.20513 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.43029 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.35357 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.31200 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.40445 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.38720 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.54707 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.38381 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.72696 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.50000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.66667 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.61619 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.72696 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.61280 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.54707 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.68800 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.40445 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.56971 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.35357 * CGRectGetHeight(frame))];
    [starPath closePath];
    [[CPColor yellowColor] setFill];
    [starPath fill];
    [CPGraphicsContext saveGraphicsState];
    [shadow set];
    [[CPColor whiteColor] setStroke];
    [starPath setLineWidth:3];
    var starPattern = [5, 1, 5, 1];
    [starPath setLineDash:starPattern phase:2];
    [starPath stroke];
    [CPGraphicsContext restoreGraphicsState];
}

@end

我从一个更大的集合中提取了这个


在引擎盖下,卡布奇诺将使用画布(如果可用),或在必要时使用VML(对于某些版本的IE)。

在卡布奇诺中,您可以在任何视图中执行自定义绘图。为此,重写
drawRect:
方法(从
CPView
继承的任何方法,它几乎是每个控件的继承方法)。您可以使用CPGraphics工具(如),也可以使用CoreGraphics和命令(如)进行绘制,以了解有关绘制Apple文档的后一种样式的更多信息。记住卡布奇诺是基于Objective-C和可可粉的

下面是一个示例视图,该视图在圆角矩形中绘制了一个带点边框的黄色星形,大小适合当前视图:

@implementation CustomDrawView : CPView
{
}

- (void)drawRect:(CGRect)aRect
{
    [super drawRect:aRect];

    [[CPColor whiteColor] set];
    [[CPBezierPath bezierPathWithRect:bounds] fill];

    var frame =[self bounds],
        shadow = [[CPShadow alloc] init];

    [shadow setShadowColor:[CPColor blackColor]];
    [shadow setShadowOffset:CGSizeMake(0, 3)];
    [shadow setShadowBlurRadius:5];

    //// Rounded Rectangle Drawing
    var roundedRectanglePath = [CPBezierPath bezierPathWithRoundedRect:CGRectMake(CGRectGetMinX(frame) + 3.5, CGRectGetMinY(frame) + 3.5, CGRectGetWidth(frame) - 7, CGRectGetHeight(frame) - 7) xRadius:7 yRadius:7];
    [[CPColor blackColor] setStroke];
    [roundedRectanglePath setLineWidth:1];
    var roundedRectanglePattern = [5, 1, 1, 1];
    [roundedRectanglePath setLineDash:roundedRectanglePattern phase:0];
    [roundedRectanglePath stroke];

    var starPath = [CPBezierPath bezierPath];
    [starPath moveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.50000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.20513 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.43029 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.35357 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.31200 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.40445 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.38720 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.54707 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.38381 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.72696 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.50000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.66667 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.61619 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.72696 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.61280 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.54707 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.68800 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.40445 * CGRectGetHeight(frame))];
    [starPath lineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.56971 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.35357 * CGRectGetHeight(frame))];
    [starPath closePath];
    [[CPColor yellowColor] setFill];
    [starPath fill];
    [CPGraphicsContext saveGraphicsState];
    [shadow set];
    [[CPColor whiteColor] setStroke];
    [starPath setLineWidth:3];
    var starPattern = [5, 1, 5, 1];
    [starPath setLineDash:starPattern phase:2];
    [starPath stroke];
    [CPGraphicsContext restoreGraphicsState];
}

@end

我从一个更大的集合中提取了这个


在引擎盖下,卡布奇诺将使用画布(如果可用),或者在必要时使用VML(对于某些版本的IE)。

这很好,但是有没有办法用鼠标移动形状?(很抱歉没有在原始问题中概述这一点)是的,但如何做到这一点取决于您想要多少形状。如果您只有几个形状,我建议您将每个形状设置为自己的CPView。这使得它很容易对点击和拖动做出反应。另一方面,如果你想要有很多,你应该使用一个单一的CPView来绘制所有的矩形,并通过
mouseDown:
mouseUp:
mouseDragged:
来解释鼠标的交互。下面是一个如何检测鼠标光标何时位于形状(路径)内部的示例:。这很好,但是有没有办法用鼠标移动形状?(很抱歉没有在原始问题中概述这一点)是的,但如何做到这一点取决于您想要多少形状。如果您只有几个形状,我建议您将每个形状设置为自己的CPView。这使得它很容易对点击和拖动做出反应。另一方面,如果你想要有很多,你应该使用一个单一的CPView来绘制所有的矩形,并通过
mouseDown:
mouseUp:
mouseDragged:
来解释鼠标的交互。下面是一个如何检测鼠标光标何时位于形状(路径)内部的示例:。