Ejemplo n.º 1
0
void draw_surface_part_ext(int id, gs_scalar left, gs_scalar top, gs_scalar w, gs_scalar h, gs_scalar x, gs_scalar y, gs_scalar xscale, gs_scalar yscale,int color, gs_scalar alpha)
{
	const gs_scalar tbw = surface_get_width(id), tbh = surface_get_height(id);
	draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(id));
	draw_vertex_texture_color(x,y,left/tbw,top/tbh,color,alpha);
	draw_vertex_texture_color(x+w*xscale,y,(left+w)/tbw,top/tbh,color,alpha);
	draw_vertex_texture_color(x,y+h*yscale,left/tbw,(top+h)/tbh,color,alpha);
	draw_vertex_texture_color(x+w*xscale,y+h*yscale,(left+w)/tbw,(top+h)/tbh,color,alpha);
	draw_primitive_end();
}
Ejemplo n.º 2
0
void draw_surface(int id, gs_scalar x, gs_scalar y, int color, gs_scalar alpha)
{
	int w=surface_get_width(id);
	int h=surface_get_height(id);
  
	draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(id));
	draw_vertex_texture_color(x,y,0,0,color,alpha);
	draw_vertex_texture_color(x+w,y,1,0,color,alpha);
	draw_vertex_texture_color(x,y+h,0,1,color,alpha);
	draw_vertex_texture_color(x+w,y+h,1,1,color,alpha);
	draw_primitive_end();
}
Ejemplo n.º 3
0
void draw_surface_tiled_ext(int id, gs_scalar x, gs_scalar y, gs_scalar xscale, gs_scalar yscale, int color, gs_scalar alpha)
{
    const gs_scalar w=surface_get_width(id)*xscale, h=surface_get_height(id)*yscale;
    const int hortil= int (ceil(room_width/(surface_get_width(id)))),
        vertil= int (ceil(room_height/(surface_get_height(id))));
    x=w-fmod(x,w);
    y=h-fmod(y,h);
 
    for (int i=0; i<hortil; i++)
    {
      for (int c=0; c<vertil; c++)
      {		  
		draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(id));
		draw_vertex_texture_color(i*w-x,c*h-y,0,0,color,alpha);
		draw_vertex_texture_color((i+1)*w-x,c*h-y,1,0,color,alpha);
		draw_vertex_texture_color(i*w-x,(c+1)*h-y,0,1,color,alpha);
		draw_vertex_texture_color((i+1)*w-x,(c+1)*h-y,1,1,color,alpha);
		draw_primitive_end();
      }
    }
}
Ejemplo n.º 4
0
void draw_surface_tiled(int id, gs_scalar x, gs_scalar y, int color, gs_scalar alpha)
{
	const gs_scalar tbw = surface_get_width(id), tbh = surface_get_height(id);
	x=surface_get_width(id)-fmod(x,surface_get_width(id));
	y=surface_get_height(id)-fmod(y,surface_get_height(id));
	const int hortil= int (ceil(room_width/(surface_get_width(id)))),
			  vertil= int (ceil(room_height/(surface_get_height(id))));

    
	for (int i=0; i<hortil; i++)
	{
		for (int c=0; c<vertil; c++)
		{
			draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(id));
			draw_vertex_texture_color(i*tbw-x,c*tbh-y,0,0,color,alpha);
			draw_vertex_texture_color((i+1)*tbw-x,c*tbh-y,1,0,color,alpha);
			draw_vertex_texture_color(i*tbw-x,(c+1)*tbh-y,0,1,color,alpha);
			draw_vertex_texture_color((i+1)*tbw-x,(c+1)*tbh-y,1,1,color,alpha);
			draw_primitive_end();
		}
	}
}
Ejemplo n.º 5
0
void draw_surface_ext(int id,gs_scalar x, gs_scalar y,gs_scalar xscale, gs_scalar yscale,double rot,int color,gs_scalar alpha)
{
    const gs_scalar w=surface_get_width(id)*xscale, h=surface_get_height(id)*yscale;
    rot *= M_PI/180;

    gs_scalar ulcx = x + xscale * cos(M_PI+rot) + yscale * cos(M_PI/2+rot),
          ulcy = y - yscale * sin(M_PI+rot) - yscale * sin(M_PI/2+rot);

	draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(id));
	draw_vertex_texture_color(ulcx,ulcy,0,0,color,alpha);
	draw_vertex_texture_color(ulcx + w*cos(rot), ulcy - w*sin(rot),1,0,color,alpha);
	ulcx += h * cos(3*M_PI/2 + rot);
	ulcy -= h * sin(3*M_PI/2 + rot);
	draw_vertex_texture_color(ulcx,ulcy,0,1,color,alpha);
	draw_vertex_texture_color(ulcx + w*cos(rot), ulcy - w*sin(rot),1,1,color,alpha);
	draw_primitive_end();
}
Ejemplo n.º 6
0
void draw_surface_general(int id, gs_scalar left, gs_scalar top, gs_scalar width, gs_scalar height, gs_scalar x, gs_scalar y, gs_scalar xscale, gs_scalar yscale, double rot, int c1, int c2, int c3, int c4, gs_scalar alpha)
{
	const gs_scalar tbw = surface_get_width(id), tbh = surface_get_height(id),
	  w = width*xscale, h = height*yscale;

    rot *= M_PI/180;

    gs_scalar ulcx = x + xscale * cos(M_PI+rot) + yscale * cos(M_PI/2+rot),
          ulcy = y - yscale * sin(M_PI+rot) - yscale * sin(M_PI/2+rot);

    draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(id));
	draw_vertex_texture_color(ulcx,ulcy,left/tbw,top/tbh,c1,alpha);
	draw_vertex_texture_color((ulcx + w*cos(rot)), (ulcy - w*sin(rot)), (left+width)/tbw,top/tbh, c2, alpha);
		
      ulcx += h * cos(3*M_PI/2 + rot);
      ulcy -= h * sin(3*M_PI/2 + rot);
	  
	draw_vertex_texture_color((ulcx + w*cos(rot)), (ulcy - w*sin(rot)), (left+width)/tbw,(top+height)/tbh, c4, alpha);
	draw_vertex_texture_color(ulcx, ulcy, left/tbw, (top+height)/tbh, c3, alpha);
    draw_primitive_end();
}
Ejemplo n.º 7
0
void draw_surface_tiled_area_ext(int id, gs_scalar x, gs_scalar y, gs_scalar x1, gs_scalar y1, gs_scalar x2, gs_scalar y2, gs_scalar xscale, gs_scalar yscale, int color, gs_scalar alpha)
{
    gs_scalar sw,sh,i,j,jj,left,top,width,height,X,Y;
    sw = surface_get_width(id)*xscale;
    sh = surface_get_height(id)*yscale;

    i = x1-(fmod(x1,sw) - fmod(x,sw)) - sw*(fmod(x1,sw)<fmod(x,sw));
    j = y1-(fmod(y1,sh) - fmod(y,sh)) - sh*(fmod(y1,sh)<fmod(y,sh));
    jj = j;

    for(; i<=x2; i+=sw)
    {
      for(; j<=y2; j+=sh)
      {
        if(i <= x1) left = x1-i;
        else left = 0;
        X = i+left;

        if(j <= y1) top = y1-j;
        else top = 0;
        Y = j+top;

        if(x2 <= i+sw) width = ((sw)-(i+sw-x2)+1)-left;
        else width = sw-left;

        if(y2 <= j+sh) height = ((sh)-(j+sh-y2)+1)-top;
        else height = sh-top;
		  
		draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(id));
		draw_vertex_texture_color(X,Y,left/sw,top/sh,color,alpha);
		draw_vertex_texture_color(X+width,Y,(left+width)/sw,top/sh,color,alpha);
		draw_vertex_texture_color(X,Y+height,left/sw,(top+height)/sh,color,alpha);
		draw_vertex_texture_color(X+width,Y+height,(left+width)/sw,(top+height)/sh,color,alpha);
		draw_primitive_end();
      }
      j = jj;
    }
}
Ejemplo n.º 8
0
int main(int argc, char *argv[]) {     
    int fd;                      /* fd to Erlang node */
    unsigned char buf[BUFSIZE];  /* Buffer for incoming message */
    ErlMessage emsg;             /* Incoming message */
    int c_node;                   /* C-Node number */
    char cookie[EI_MAX_COOKIE_SIZE+1];  /* Shared cookie */
    short creation;              /* ?? */
    char *erlang_node;           /* Erlang node to connect to */
	 char *cookie_opt;				/* Where to source our cookie */
	 char *cookie_data;				/* Either the filename or literal cookie */
    ETERM *fromp, *msgp, *fnp, *argp, *resp;
    int received, loop = 1;
    
    if (argc < 5) {
        quit_with_error("invalid_args");
    }
    
    c_node = atoi(argv[1]);
    cookie_opt = argv[2];
	 cookie_data = argv[3];
    creation = 0;
    erlang_node = argv[4];
    
    erl_init(NULL, 0);

	 get_cookie(cookie_opt, cookie_data, cookie);
    
    if (!erl_connect_init(c_node, cookie, creation)) {
        quit_with_error("erl_connect_init");
    }
    
    if ((fd = erl_connect(erlang_node)) < 0) {
        quit_with_error("erl_connect"); 
    }
       
    while (loop) {
        received = erl_receive_msg(fd, buf, BUFSIZE, &emsg);

    if (received == ERL_TICK) {
        /* ignore */    
    } else if (received == ERL_ERROR) {
        loop = 0;
    } else {
        if (emsg.type == ERL_REG_SEND) {          
            fromp = erl_element(2, emsg.msg);
            msgp = erl_element(3, emsg.msg);
            fnp = erl_element(1, msgp);
            argp = erl_element(2, msgp);  
            
            if (is_function(fnp, "stop")) {
                loop = 0;
                resp = erl_format("{c_node, ~i, ok}", c_node);
            } else if (is_function(fnp, "new_image_blank")) { 
                resp = new_image_blank(argp, c_node); 
            } else if (is_function(fnp, "write_to_png")) {
                resp = write_to_png(argp, c_node);
            } else if (is_function(fnp, "close_image")) {
                resp = close_image(argp, c_node);
            } else if (is_function(fnp, "save")) {
                resp = save(argp, c_node);
            } else if (is_function(fnp, "restore")) {
                resp = restore(argp, c_node);
            } else if (is_function(fnp, "set_line_width")) {
                resp = set_line_width(argp, c_node);
            } else if (is_function(fnp, "set_source_rgba")) {
                resp = set_source_rgba(argp, c_node);	
	        } else if (is_function(fnp, "set_operator")) {
                resp = set_operator(argp, c_node);
            } else if (is_function(fnp, "move_to")) {
                resp = move_to(argp, c_node);
            } else if (is_function(fnp, "line_to")) {
                resp = line_to(argp, c_node);
            } else if (is_function(fnp, "curve_to")) {
                resp = curve_to(argp, c_node);
            } else if (is_function(fnp, "rel_move_to")) {
                resp = rel_move_to(argp, c_node);
            } else if (is_function(fnp, "rel_line_to")) {
                resp = rel_line_to(argp, c_node);
            } else if (is_function(fnp, "rel_curve_to")) {
                resp = rel_curve_to(argp, c_node);
            } else if (is_function(fnp, "rectangle")) {
                resp = rectangle(argp, c_node);
            } else if (is_function(fnp, "arc")) {
                resp = arc(argp, c_node);
            } else if (is_function(fnp, "arc_negative")) {
                resp = arc_negative(argp, c_node);
            } else if (is_function(fnp, "close_path")) {
                resp = close_path(argp, c_node);
            } else if (is_function(fnp, "paint")) {
                resp = paint(argp, c_node);
            } else if (is_function(fnp, "fill")) {
                resp = fill(argp, c_node);
            } else if (is_function(fnp, "fill_preserve")) {
                resp = fill_preserve(argp, c_node);
            } else if (is_function(fnp, "stroke")) {
                resp = stroke(argp, c_node);
            } else if (is_function(fnp, "stroke_preserve")) {
                resp = stroke_preserve(argp, c_node);
            } else if (is_function(fnp, "translate")) {
                resp = translate(argp, c_node);
            } else if (is_function(fnp, "scale")) {
                resp = scale(argp, c_node);
            } else if (is_function(fnp, "rotate")) {
                resp = rotate(argp, c_node);
            } else if (is_function(fnp, "select_font")) {
                resp = select_font_face(argp, c_node);
            } else if (is_function(fnp, "set_font_size")) {
                resp = set_font_size(argp, c_node);
            } else if (is_function(fnp, "show_text")) {
                resp = show_text(argp, c_node);
            } else if (is_function(fnp, "text_extents")) {
                resp = text_extents(argp, c_node);          
            } else if (is_function(fnp, "surface_create_from_png")) {
                resp = surface_create_from_png(argp, c_node);
            } else if (is_function(fnp, "surface_create_from_png_stream")) {
                resp = surface_create_from_png_stream(argp, c_node);
            } else if (is_function(fnp, "surface_get_width")) {
                resp = surface_get_width(argp, c_node);          
            } else if (is_function(fnp, "surface_get_height")) {
                resp = surface_get_height(argp, c_node);          
            } else if (is_function(fnp, "surface_destroy")) {
                resp = surface_destroy(argp, c_node);          
            } else if (is_function(fnp, "set_source_surface")) {
                resp = set_source_surface(argp, c_node);          
            } else if (is_function(fnp, "write_to_png_stream")) {
                resp = write_to_png_stream(argp, c_node);          
            } else {
                resp = erl_format("{c_node, ~i, {error, '~s'}}", c_node, "unknown command");
            }         
            erl_send(fd, fromp, resp);           
            erl_free_term(emsg.from); 
            erl_free_term(emsg.msg);
            erl_free_term(fromp); 
            erl_free_term(msgp);
            erl_free_term(fnp); 
            erl_free_term(argp);
            erl_free_term(resp);
      }
    }
  }
  exit(EXIT_SUCCESS);
}