ThanksĀ Ogla,
I just finished the example showing how to use Cairo to do it.
Now... how do i add all of this to a Custom Rectangle of my own? :D..and create 
it like this:ClutterActor *MyDashedBorderRectangle = 
my_dashedborder_rectangle_new( line_thickness, line_type );
i know it has something to do with creating a ClutterContainer object, but all 
attempts have failed at addingrectangles internally, hiding them from the users 
knowledge, making it seem like the Custom Control is drawingeverything from 
scratch, but it isnt. and is really just changing the clipping and size of the 
rectangles. :D
Any help in figuring out the right way to add all these rectangles to a Custom 
Container control, doesnt have to be aContainer.. just assumed it was the right 
way, would be Super! ;-D
I'll see if i can get a working example soon.
Thanks,Izzy.
________________________________
> Date: Sat, 4 Jun 2011 12:50:13 +0300
> Subject: Re: Using COGL to Draw a line with different Dashes?
> From: [email protected]
> To: [email protected]
> CC: [email protected]
>
> Hi Izzy,
>
> It is very possible to draw shapes with cairo and display on stage with
> ClutterCairoTexture.
> I've been using librsvg to render complex SVG files( or sub nodes) to
> ClutterCairoTextures.
>
> On Fri, Jun 3, 2011 at 8:15 AM, Izzy Soft
> > wrote:
>
> Hi All,
> Just curious if COGL (or with Cairo) can be used to draw a line with
> dashes? Ex: (scroll down a bit in the page)
> http://zetcode.com/tutorials/cairographicstutorial/basicdrawing/
> Thanks,Izzy> Thanks,Izzy>.
> _______________________________________________
> clutter-app-devel-list mailing list
> [email protected]
> http://lists.clutter-project.org/listinfo/clutter-app-devel-list
>
>
>
> --
> Ogla Sungutay
> http://www.lyciasoft.com
                                          
#include <clutter/clutter.h>

ClutterActor *
make_gradient_actor( guint width, guint height )
{
	cairo_t *cr;

	ClutterActor* texture = clutter_cairo_texture_new( width, height );

	// cast to CLUTTER_CAIRO_TEXTURE, as the functions used below require that type
	ClutterCairoTexture *cc_texture = CLUTTER_CAIRO_TEXTURE (texture);

	clutter_cairo_texture_clear (cc_texture);

	cr = clutter_cairo_texture_create (cc_texture);

	cairo_pattern_t *pat;

	pat = cairo_pattern_create_linear (0.0 +100, 0.0 +100,  width -100, height -100);

	cairo_pattern_add_color_stop_rgba (pat, 1, 0.4, 0.8, 0.4, 1);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0.5, 0.8, 1, 1);
	cairo_rectangle (cr, 0, 0, width, height);
	cairo_set_source (cr, pat);
	cairo_fill (cr);
	cairo_pattern_destroy (pat);

	/* does the actual drawing onto the texture */
	cairo_destroy (cr);

	return texture;
}

ClutterActor *
make_DashedLine_actor( guint length, double thickness, uint dashtype )
{
	cairo_t *cr;

	ClutterActor* texture = clutter_cairo_texture_new( length, thickness );

	// cast to CLUTTER_CAIRO_TEXTURE, as the functions used below require that type
	ClutterCairoTexture *cc_texture = CLUTTER_CAIRO_TEXTURE (texture);

	clutter_cairo_texture_clear (cc_texture);

	cr = clutter_cairo_texture_create (cc_texture);

	cairo_set_source_rgba(cr, 0, 0, 0, 1);
	cairo_set_line_width(cr, thickness);

	static double dashed[3];
	static int len1;

	switch(dashtype)
	{
	case 1:
		dashed[0] = 4.0;
		dashed[1] = 1.0;
		len1 = 2;
		break;

	case 2:
		dashed[0] = 4.0;
		dashed[1] = 1.0;
		dashed[2] = 4.0;
		len1 = 3;
		break;

	case 3:
		dashed[0] = 1.0;
		len1 = 1;
		break;
	}

	cairo_set_dash(cr, dashed, len1, 0);

	cairo_move_to(cr, 0, 0);
	cairo_line_to(cr, length, 0);
	cairo_stroke(cr);

	/* does the actual drawing onto the texture */
	cairo_destroy (cr);

	return texture;
}

void
init_texture (ClutterActor *stage )
{
  ClutterActor *ctex = clutter_cairo_texture_new(300, 200);
  cairo_t *cr = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE (ctex));

  cairo_set_tolerance (cr, 0.1);
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba(cr, 1, 1, 1, 1);

  cairo_move_to (cr, 0, 0);
  cairo_line_to (cr, 300, 600);
  cairo_stroke (cr);

  cairo_destroy(cr);
  clutter_container_add_actor(CLUTTER_CONTAINER(stage), ctex );
  clutter_actor_set_position(ctex, 0, 0);
}


int
main (int argc, char **argv)
{
	ClutterActor *stage;

	clutter_init (&argc, &argv);

	stage = clutter_stage_get_default ();
	g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
	clutter_stage_set_color (CLUTTER_STAGE (stage), &(ClutterColor) { 255, 255, 255, 255 });
	clutter_stage_set_user_resizable( CLUTTER_STAGE( stage ), TRUE );
	clutter_actor_set_size( stage, 460, 260 );

	// Change These Values
	uint x=30, y=30, w=400, h=200;

	ClutterActor *GradTexture = make_gradient_actor( w, h );
	clutter_container_add_actor( CLUTTER_CONTAINER( stage ), GradTexture );
	clutter_actor_set_position( GradTexture, x, y );

	// Change These Values
	uint line_thickness = 2;		// 1 and up
	uint line_type = 1;				// 1,2,3

	gfloat line_thickness_half = (line_thickness / 2.f);
	ClutterActor *DashedLineBig = make_DashedLine_actor( 1440, line_thickness, line_type );
	clutter_container_add_actor( CLUTTER_CONTAINER( stage ), DashedLineBig );
	clutter_actor_hide( DashedLineBig );

	ClutterActor *DashedLine1 = clutter_clone_new( DashedLineBig );
	ClutterActor *DashedLine2 = clutter_clone_new( DashedLineBig );
	ClutterActor *DashedLine3 = clutter_clone_new( DashedLineBig );
	ClutterActor *DashedLine4 = clutter_clone_new( DashedLineBig );

	clutter_container_add_actor( CLUTTER_CONTAINER( stage ), DashedLine1 );
	clutter_actor_set_clip( DashedLine1, 0, 0, w, line_thickness);
	clutter_actor_set_position( DashedLine1, x, y );

	clutter_container_add_actor( CLUTTER_CONTAINER( stage ), DashedLine2 );
	clutter_actor_set_clip( DashedLine2, 0, 0, h, line_thickness);
	clutter_actor_set_rotation( DashedLine2, CLUTTER_Z_AXIS, 90.f, 0,line_thickness,0 );
	clutter_actor_set_position( DashedLine2, x - line_thickness_half, y - line_thickness );

	clutter_container_add_actor( CLUTTER_CONTAINER( stage ), DashedLine3 );
	clutter_actor_set_clip( DashedLine3, 0, 0, w, line_thickness);
	clutter_actor_set_position( DashedLine3, x, y+h - line_thickness_half );

	clutter_container_add_actor( CLUTTER_CONTAINER( stage ), DashedLine4 );
	clutter_actor_set_clip( DashedLine4, 0, 0, 200, line_thickness);
	clutter_actor_set_rotation( DashedLine4, CLUTTER_Z_AXIS, 90.f, 0,line_thickness,0 );
	clutter_actor_set_position( DashedLine4, x+w - line_thickness, y - line_thickness );

	clutter_actor_show( stage );

	clutter_main ();

	return 0;
}
_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list

Reply via email to