예제 #1
0
  void repaint(){
    if(!display){
      cout << "Repaint: You must first call initCanvas before "<<
	"using any graphics features.\n";
      exit(1);
    }

    if(globalRepaintFlag){
      int tl_x=0,tl_y=0,width=canvas_width(),height=canvas_height();
      XCopyArea(display, screenBG, screenTmp, gc, 
		tl_x, tl_y, width, height, tl_x, tl_y);

      curr_d = screenTmp;

      for(auto iter = spriteSet.begin(); iter != spriteSet.end(); iter ++){
	(*iter)->paint();
      } 

      XCopyArea(display, screenTmp, canvas_window, gc, 
		tl_x, tl_y, width, height, tl_x, tl_y);
    
      XSync(display, false);
      curr_d = canvas_window;
    }
  }
Turtle::Turtle(Composite* owner){
  double pts_body[4][2] = {{0, 15}, {20, 0}, {0, -15}, {0,15}};
  setColor(COLOR("red"), false);
  setFill();
  penDown();
  reset(canvas_width()/2, canvas_height()/2,pts_body, 4, owner);
}
예제 #3
0
  int initCanvas(const char window_title[], int width, int height){

    display = XOpenDisplay(NULL);    // Connect X server by opening a display
    //display = XOpenDisplay("localhost:11.0");    // Connect X server by opening a display

    if(!display){
      cerr<<"Unable to connect X server\n";
      return 1;
    }

    screen_number = DefaultScreen(display);

    if(width == -1){
      screen_width = (DisplayWidth(display, screen_number) -100);
      screen_height = (DisplayHeight(display, screen_number) -100);
    }
    else{
      screen_width = width;
      screen_height= height;
    }

    canvas_window = XCreateSimpleWindow(display,
					RootWindow(display, screen_number),
					0,0, // left top corner.  doesnt work.
					screen_width, screen_height,
					1,
					BlackPixel(display, screen_number),
					WhitePixel(display, screen_number));

    XSetStandardProperties(display, canvas_window, window_title,
			   window_title, None, NULL, 0, NULL);

    XSelectInput(display, canvas_window, 
		 ExposureMask|ButtonPressMask|ButtonReleaseMask|KeyPressMask|
		 ButtonMotionMask);

    XMapWindow(display, canvas_window);    // Map canvas window to display
    XSync(display, True);  // flush all output requests and discards events

    gc_vals.function = GXcopy;
    //  gc_vals.foreground = Color(COLOR("black"));
    gc_vals.line_width = 2;
    gc_vals.line_style = LineSolid;
    gc_vals.cap_style = CapButt;
    gc_vals.join_style = JoinMiter;

    gc = XCreateGC(display, canvas_window, 0 ,0);    // Create GC

    if((long int) gc < 0){
      //if(gc < 0){
      cerr<<"Unable to create graphic context.\n";
      return 2;                            // ERROR CODE 2: gc error
    }


    xfs = XLoadQueryFont(display, "-*-helvetica-bold-r-normal-*-24-*");
    if (!xfs) {
      xfs = XLoadQueryFont(display, "fixed");
    }
    if(!xfs){
      cout << "Cannot load font.  You will not be able to use Text.\n";
    }

    //XClearWindow(display, canvas_window);
    //XMapRaised(display, canvas_window);

    cmap = DefaultColormap(display, screen_number);
  
    // Flush all events to X server and wait
    XSync(display, False);

    screenBG =XCreatePixmap(display, canvas_window, 
			    screen_width, screen_height, 
			    XDefaultDepth(display, screen_number));
    //    XCopyArea(display, canvas_window, screenBG, gc, 0,0,screen_width, screen_height, 0,0);

    //  {int p; cin >> p;}
    wait(0.1);
    XSync(display, False);

    screenTmp=XCreatePixmap(display, canvas_window, screen_width, screen_height, 
			    XDefaultDepth(display, screen_number));

    curr_d = canvas_window;

    Rectangle r(canvas_width()/2.0, canvas_height()/2.0, 
		canvas_width(), canvas_height());
    r.setColor(COLOR("white"));
    r.setFill();
    r.imprint();


    return 0;
  }
예제 #4
0
int init_nip_stop_codons_plot(Tcl_Interp *interp,
			      int seq_id,
			      int result_id,
			      char *e_win,
			      char *c_win, 
			      Tcl_Obj *results,
			      int container_id,
			      int element_id,
			      char *element_type,
			      int line_width,
			      char *colour,
			      float tick_ht,
			      int orientation)
{
    seq_result *s_result;
    Graph *graph;
    configs *configure;
    plot_data *result;
    int i;
    int height;
    int seq_id_h, seq_id_v;

    s_result = seq_id_to_result(result_id);
    
    if (NULL == (result = (plot_data *)xmalloc(sizeof(plot_data))))
	return -1;
    
    if (NULL == (result->configure = (configs **)xmalloc(sizeof(configs*))))
	return -1;
    
    if (NULL == (configure = (configs *)xmalloc(sizeof(configs))))
	return -1;

    configure->position = 0.5;
    configure->x_direction = '+';
    configure->y_direction = '+';
    configure->height = tick_ht;
    configure->zoom = 0;
    configure->scroll = 0;

    result->configure[0] = configure;
    result->n_configure = 1;
    result->sf_m = 1.0;
    result->sf_c = 0.0;
    result->result_id = result_id;
    result->hidden = 0;
    result->line_width = line_width;
    result->colour = strdup(colour);
    result->len_ruler = 1;
    result->amp_ruler = 0;
    sprintf(result->tags, "id%d", result_id);

    graph = Tcl_GetGraphFromObj(results);
   
    if (orientation == HORIZONTAL) {
	seq_id_h = seq_id;
	seq_id_v = -1;
	height = canvas_height(interp, e_win);
	result->scale = SCALE_X;
    } else {
	seq_id_h = -1;
	seq_id_v = seq_id;
	height = canvas_width(interp, e_win);
	result->scale = SCALE_Y;
    }

    graph->dim.y0 = 1;
    graph->dim.y1 = height;

    /* graph->dim.y1 = tick_ht; */

    for (i = 0; i < graph->d_arrays[0].n_dlines; i++) {
	graph->d_arrays[0].d_array[i].y0 = 1;
	graph->d_arrays[0].d_array[i].y1 = tick_ht;

    }
    
    init_seq_element(interp, s_result, seq_id_h, seq_id_v, result, 
		     container_id, 
		     element_id, e_win, c_win, orientation, orientation,
		     graph, element_type);
    
    return 0;
}
예제 #5
0
void nip_stop_codons_callback(int seq_num, void *obj, seq_reg_data *jdata)
{
    seq_result *s_result = (seq_result *) obj;
    in_s_codon *input = s_result->input;
    int result_id = s_result->id;
    char cmd[1024];
    element *e = s_result->e;
    plot_data *result;
    Tcl_Interp *interp;

    if (e) {
	result = find_plot_data(e, result_id);
	interp = e->c->interp;
    }

    switch(jdata->job) {
    case SEQ_QUERY_NAME:
	if (s_result->type == SEQ_TYPE_STOPCODON) {
	    sprintf(jdata->name.line, "Plot stop codons");
	} else {
	    sprintf(jdata->name.line, "Plot start codons");
	}
	break;    

    case SEQ_KEY_NAME:
	if (s_result->type == SEQ_TYPE_STOPCODON) {
	    sprintf(jdata->name.line, "stop f%d #%d", s_result->frame,
		    result_id);
	} else {
	    sprintf(jdata->name.line, "start f%d #%d", s_result->frame,
		    result_id);
	}
	break;
	
    case SEQ_GET_BRIEF:
	if (s_result->type == SEQ_TYPE_STOPCODON) {
	    sprintf(jdata->name.line, "stop codons: seq=%s frame=%d", 
		    GetSeqName(GetSeqNum(s_result->seq_id[HORIZONTAL])), 
		    s_result->frame);
	} else {
	    sprintf(jdata->name.line, "start codons: seq=%s frame=%d", 
		    GetSeqName(GetSeqNum(s_result->seq_id[HORIZONTAL])), 
		    s_result->frame);
	}
	break;

    case SEQ_GET_OPS:
	if (result->hidden) {
	    jdata->get_ops.ops = "Information\0List results\0"
		"PLACEHOLDER\0PLACEHOLDER\0Reveal\0SEPARATOR\0Remove\0";
	} else {
	    jdata->get_ops.ops = "Information\0List results\0Configure\0"
	       "Hide\0PLACEHOLDER\0SEPARATOR\0Remove\0";
	}
	break;
    case SEQ_INVOKE_OP:
	switch (jdata->invoke_op.op) {
	case 0: /* information */
	    vfuncheader("input parameters");
	    vmessage("%s\n", input->params); 
	    break;
	case 1: /* results */
	    Tcl_Eval(interp, "SetBusy");
	    vfuncheader("results");
	    s_result->txt_func(s_result);
	    Tcl_Eval(interp, "ClearBusy");
	    break;
	case 2: /* configure */
	    sprintf(cmd, "result_config %d %d %s %d %s", 
		    result_id, result->line_width, result->colour, e->id, 
		    e->win);
	    if (TCL_OK != Tcl_Eval(interp, cmd)){
		puts(interp->result);
	    }
	    break;
	case 3: /* hide all */
	    result->hidden = 1;
	    Tcl_VarEval(e->c->interp, "result_list_update ", e->c->win, NULL);
	    e->replot_func(e);
	    break;
	case 4: /* reveal all */
	    result->hidden = 0;
	    Tcl_VarEval(e->c->interp, "result_list_update ", e->c->win, NULL);
	    e->replot_func(e);
	    break;
	case 5: /* remove */ 
	    {
		nip_stop_codons_shutdown(interp, s_result, e, seq_num);
		remove_result_from_element(e, result_id);
		break;
	    }
	}
	break;
    case SEQ_PLOT:
	{
	    Tcl_Obj *graph_obj = (Tcl_Obj *) s_result->data;
	    Graph *graph;
	    
	    /* HACK - but the only way I have discovered to making stop 
	       codons work. Need to set the dim.y1 to be the height of the
	       current canvas (for instance moving codons from gene pref plot
	       to own plot
	    */
	    graph = Tcl_GetGraphFromObj(graph_obj);
	    graph->dim.y1 = canvas_height(interp, e->win);
	    s_result->pr_func(s_result, (seq_reg_plot *)jdata);
	    break;
	}
    case SEQ_RESULT_INFO:
	switch (jdata->info.op) {
	case RESULT:
	    jdata->info.result = (void *)s_result;
	    break;
	case WIN_NAME:
	    {
		char *r_win = e->win;
		jdata->info.result = (void *)r_win;
		break;
	    }
	case WIN_SIZE:
	    {
		static d_point pt;
		pt.x = get_default_int(interp, tk_utils_defs,
					w("ELEMENT.PLOT_WIDTH"));
		pt.y = get_default_double(interp, tk_utils_defs,
					   w("ELEMENT.SINGLE.PLOT_HEIGHT"));

		jdata->info.result = (void *)&pt;
		break;
	    }
	}
	break;
    case SEQ_QUIT:
    case SEQ_DELETE: 
	{
	    nip_stop_codons_shutdown(interp, s_result, e, seq_num);
	    break;
	}
    }
}
예제 #6
0
 void resetTurtle(){
   _PsystemTurtle_->Sprite::reset(canvas_width()/2,canvas_height()/2);
 }