Exemple #1
0
int launch_multi(MPI_Comm comm, int count, int* procs,
                 char** cmd,
                 int* argc, char*** argv,
                 int* envc, char*** envs,
                 char* color_setting) {
  int rank;
  MPI_Comm_rank(comm, &rank);
  int color = get_color(rank, comm, count, procs, color_setting);
  // printf("launch: rank=%i color=%i %s\n", rank, color, cmd[color]);
  // fflush(stdout);
  if (color < 0)
    return 1; // Return error

  MPI_Comm subcomm;
  MPI_Comm_split(comm, color, 0, &subcomm);
  int status = 0;
  int result = launch_envs(subcomm, cmd[color],
                           argc[color], argv[color],
                           envc[color], envs[color]);
  MPI_Reduce(&status, &result, 1, MPI_INT, MPI_MAX, 0, comm);
  return status;
}
void Draw_Grain::Draw(wxWindowDC *dc)
{
    //wxPen pen = wxPen("BLACK",1,wxSOLID);
    wxPen pen = wxPen(get_color(),1,wxSOLID);
    dc->SetPen(pen);


    double r_u = sqrt ( get_ux() * get_ux()
                        + get_uy() * get_uy()
                        + get_uz() * get_uz() );

    if ( r_u != 0 ) // Not null direction vector
    {
        dc->DrawLine(
            (int) ( get_x() - get_len()/2 * get_ux() / r_u ),
            (int) ( get_y() - get_len()/2 * get_uy() / r_u ),
            (int) ( get_x() + get_len()/2 * get_ux() / r_u ),
            (int) ( get_y() + get_len()/2 * get_uy() / r_u )
        );
    }

}
Exemple #3
0
/* adds string to the msg treeview */
void msgwin_msg_add_string(gint msg_color, gint line, GeanyDocument *doc, const gchar *string)
{
	GtkTreeIter iter;
	const GdkColor *color = get_color(msg_color);
	gchar *tmp;
	gsize len;
	gchar *utf8_msg;

	if (! ui_prefs.msgwindow_visible)
		msgwin_show_hide(TRUE);

	/* work around a strange problem when adding very long lines(greater than 4000 bytes)
	 * cut the string to a maximum of 1024 bytes and discard the rest */
	/* TODO: find the real cause for the display problem / if it is GtkTreeView file a bug report */
	len = strlen(string);
	if (len > 1024)
		tmp = g_strndup(string, 1024);
	else
		tmp = g_strdup(string);

	if (! g_utf8_validate(tmp, -1, NULL))
		utf8_msg = utils_get_utf8_from_locale(tmp);
	else
		utf8_msg = tmp;

	gtk_list_store_append(msgwindow.store_msg, &iter);
	gtk_list_store_set(msgwindow.store_msg, &iter,
		MSG_COL_LINE, line, MSG_COL_DOC_ID, doc ? doc->id : 0, MSG_COL_COLOR,
		color, MSG_COL_STRING, utf8_msg, -1);

	/* Lazily initialize the line shifts hash table once we get a non-status message */
	if (msg_color != COLOR_BLUE && msgwindow.line_shifts_msg == NULL)
		msgwindow.line_shifts_msg = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, free_line_shifts_seq);

	g_free(tmp);
	if (utf8_msg != tmp)
		g_free(utf8_msg);
}
bool video::init_window(int sizex, int sizey)
{
    assert(win_hInstance != 0);
    g_sizex = sizex; g_sizey = sizey;
    if( !WinInit(win_hInstance, win_iCmdShow, gWndClass, title, false) )
        return DisplayError("Unable to initialize the program's window.");
    running = true;
    if( !DDInit() ) {
        DestroyDDraw();
        goto fail;
    }
    if( !DDOverlayInit() || !DrawOverlay() ) {
        DestroyOverlay();
        DestroyDDraw();
        goto fail;
    }
    DDPIXELFORMAT PixelFormat; memset(&PixelFormat, 0, sizeof(PixelFormat)); PixelFormat.dwSize = sizeof(PixelFormat);
    g_pDDSOverlay->GetPixelFormat(&PixelFormat);
    mask2bits(PixelFormat.dwRBitMask, red_mask, red_shift);
    mask2bits(PixelFormat.dwGBitMask, green_mask, green_shift);
    mask2bits(PixelFormat.dwBBitMask, blue_mask, blue_shift);
    if(PixelFormat.dwFlags == DDPF_RGB)
         depth = depth_t(PixelFormat.dwRGBBitCount);
    else depth = -depth_t(PixelFormat.dwFourCC);
    for(int i = 0, e = sizex * sizey * PixelFormat.dwRGBBitCount / 32, c = get_color(0, 0, 0); i < e; i++)
        g_pImg[i] = c; // clear surface
    ShowWindow(g_hAppWnd, SW_SHOW);
    g_hVSync = CreateThread (
        NULL,          // LPSECURITY_ATTRIBUTES security_attrs
        0,             // SIZE_T stacksize
        (LPTHREAD_START_ROUTINE) thread_vsync,
        this,               // argument
        0, 0);
    SetPriorityClass(g_hVSync, IDLE_PRIORITY_CLASS); // questionable
    return true;
fail:
    g_pImg = new unsigned int[g_sizex * g_sizey];
    return false;
}
Exemple #5
0
void EditorLog::_notification(int p_what) {

	if (p_what==NOTIFICATION_ENTER_TREE) {

		log->add_color_override("default_color",get_color("font_color","Tree"));
		tb->set_normal_texture( get_icon("Collapse","EditorIcons"));
		tb->set_hover_texture( get_icon("CollapseHl","EditorIcons"));
		//button->set_icon(get_icon("Console","EditorIcons"));

	}

	/*if (p_what==NOTIFICATION_DRAW) {

		RID ci = get_canvas_item();
		get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
		int top_ofs = 20;
		int border_ofs=4;
		Ref<StyleBox> style = get_stylebox("normal","TextEdit");

		style->draw(ci,Rect2( Point2(border_ofs,top_ofs),get_size()-Size2(border_ofs*2,top_ofs+border_ofs)));
	}*/
}
Exemple #6
0
void	refresh(t_args_events *args)
{
  int	i;
  int	n;
  t_col	color;
  t_pos	pos;
  int	taille;

  i = n = 0;
  taille = LARG / sqrt(MEM_SIZE);
  while (i < MEM_SIZE)
    {
      pos.x = (n * taille) % (LARG - taille);
      pos.y = ((i * taille) / (LARG - taille)) * taille;
      get_color(&color, i, args->arena);
      do_carre(args, taille, &pos, &color);
      i++;
      n++;
      if (LARG / taille <= n)
	n = 0;
    }
}
Exemple #7
0
static int l_textbox_gethg(lua_State *L)
{
	l_textbox	*tb;
	SDL_Color	c;

	tb = l_checkTextbox(L, 1);
	get_color(tb, HG_INDEX, &c);

	lua_newtable(L);

	lua_pushnumber(L, 1);
	lua_pushnumber(L, c.r);
	lua_rawset(L, -3);
	lua_pushnumber(L, 2);
	lua_pushnumber(L, c.g);
	lua_rawset(L, -3);
	lua_pushnumber(L, 3);
	lua_pushnumber(L, c.b);
	lua_rawset(L, -3);

	return 1;
}
Exemple #8
0
void EditorLog::add_message(const String& p_msg,bool p_error) {


	if (p_error) {
		Ref<Texture> icon = get_icon("Error","EditorIcons");
		log->add_image( icon );
		button->set_icon(icon);
		log->push_color(get_color("fg_error","Editor"));
	} else {
		button->set_icon(Ref<Texture>());
	}


	log->add_newline();
	log->add_text(p_msg);
	button->set_text(p_msg);

	if (p_error)
		log->pop();


}
/**
 * Display an entry on the gain specialty menu
 */
void view_spec_display(menu_type *menu, int oid, bool cursor, int row, int col,
		       int width)
{
    char buf[80];
    byte color;
    ability *choices = menu->menu_data;

    switch (choices[oid].type)
    {
    case PLAYER_FLAG_SPECIAL:
    {
	sprintf(buf, "Specialty Ability: %s", choices[oid].name);
	color = TERM_GREEN;
	break;
    } 
    case PLAYER_FLAG_CLASS: 
    {
	sprintf(buf, "Class: %s", choices[oid].name);
	color = TERM_UMBER;
	break;
    } 
    case PLAYER_FLAG_RACE: 
    {
	sprintf(buf, "Racial: %s", choices[oid].name);
	color = TERM_ORANGE;
	break;
    } 
    default:
    {
	sprintf(buf, "Racial: Other");
	color = TERM_ORANGE;
    }
    }

    /* Print it */
    c_put_str(cursor ? get_color(color, ATTR_HIGH, 1) : color, buf, row, col);

}
Exemple #10
0
// recursively reverse the color of a componenet, which contains `node'
void ConstraintGraph::recur_reverse_color(const GNode &node,
		BoolVector & mark){
	int idx = get_node_idx(node);
	// check if this node has been visited
	if( mark[idx] == true ) return;
	else mark[idx] = true;

	COLOR origin_color = get_color(node);
	COLOR new_color = next_color(origin_color);
	set_color(node,new_color);

	// reverse color all its adjacent nodes
	vector<GEdge> & adj_nodes = edge[idx];
	for (int v_idx=0; v_idx<row+col;v_idx++) {
		// 1.no need to check itself
		// 2.only check if edge exist
		GEdge & e = adj_nodes[v_idx];
		if( v_idx != idx && e.type != NOEDGE ){
			assert( e.v != node );
			recur_reverse_color(e.v,mark);
		}
	}
}
Exemple #11
0
static int l_textbox_putc(lua_State *L)
{
	l_textbox *tb;
	uint32_t c;
	SDL_Color fg;
	uint32_t width;
	SDL_Rect srect, prect;

	tb = l_checkTextbox(L, 1);
	c = luaL_checkint(L, 2);

	get_color(tb, FG_INDEX, &fg);

	width = font_putc(tb->font, c, tb->s, tb->x, tb->y, &fg);

	_update_screen(tb);

	tb->x += width;

	lua_pushnumber(L, width);

	return 1;
}
std::string GameState::to_std_string(const char empty) const
{
  const std::string &oneline = std::string(to_oneline_string(empty), 1, 64);
  std::string s(get_color() == W ? "w\n" : "b\n");
  s += " +-----------------+\n";
  int rev_row = 0;
  char buf[10];
  for(int row=0; row < 8; row++) {
    rev_row = 7 - row;
    sprintf(buf, "%d", rev_row + 1);
    s += buf;
    s += '|';
    s += ' ';
    for(int col=0; col < 8; col++) {
      s += oneline[rev_row * 8 + col];
      s += ' ';
    }
    s += "|\n";
  }
  s += " +-----------------+\n";
  s += "   a b c d e f g h\n";
  return s;
}
void raster_colorizer::colorize(image_data_rgba8 & out, T const& in,
                                boost::optional<double> const& nodata,
                                feature_impl const& f) const
{
    using image_data_type = T;
    using pixel_type = typename image_data_type::pixel_type;
    // TODO: assuming in/out have the same width/height for now
    std::uint32_t * out_data = out.getData();
    pixel_type const* in_data = in.getData();
    int len = out.width() * out.height();
    for (int i=0; i<len; ++i)
    {
        pixel_type value = in_data[i];
        if (nodata && (std::fabs(value - *nodata) < epsilon_))
        {
            out_data[i] = 0; // rgba(0,0,0,0)
        }
        else
        {
            out_data[i] = get_color(value);
        }
    }
}
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect window_bounds = layer_get_bounds(window_layer);

  // status layer
  status_layer = text_layer_create(GRect(0, window_bounds.size.h / 2 - (42 / 2) - 28 - 5, window_bounds.size.w, 42));
  text_layer_set_font(status_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_background_color(status_layer, GColorClear);
  text_layer_set_text_alignment(status_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(status_layer));
  
  // output layer
  output_layer = text_layer_create(GRect(0, window_bounds.size.h / 2 - (42 / 2) - 5, window_bounds.size.w, 42));
  text_layer_set_font(output_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  text_layer_set_background_color(output_layer, GColorClear);
  text_layer_set_text_color(output_layer, GColorWhite);
  text_layer_set_text_alignment(output_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(output_layer));
  
  // bpm layer
  bpm_layer = text_layer_create(GRect(0, window_bounds.size.h / 2 + (42 / 2) - 5, window_bounds.size.w, 42));
  text_layer_set_font(bpm_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_background_color(bpm_layer, GColorClear);
  text_layer_set_text_color(bpm_layer, GColorWhite);
  text_layer_set_text_alignment(bpm_layer, GTextAlignmentCenter);
  text_layer_set_text(bpm_layer, "BPM");
  layer_add_child(window_layer, text_layer_get_layer(bpm_layer));

  // read stuff
  vibe_duration = (persist_exists(KEY_VIBE_DURATION) ? persist_read_int(KEY_VIBE_DURATION) : INITIAL_VIBE_DURATION);
  set_vibe(vibe_duration);
  set_tempo(persist_exists(KEY_TEMPO) ? persist_read_int(KEY_TEMPO) : INITIAL_TEMPO);
  
  color = get_color();
  set_state(true);
  metronome_loop();
}
Exemple #15
0
t_cylinder	*get_cylinder(int fd)
{
	int			r;
	char		*line;
	t_vect		*center;
	double		radius;
	t_color		*color;

	while ((r = get_next_line(fd, &line)) > 0 && ft_strcmp(line, "----------"))
	{
		if (!ft_strcmp("pos:", line))
			center = get_vector(fd);
		if (!ft_strcmp("radius:", line))
		{
			r = get_next_line(fd, &line);
			radius = ft_atodouble(&line);
		}
		if (!ft_strcmp("color:", line))
			color = get_color(fd);
	}
	if (r == -1)
		exit(-1);
	return (new_cylinder(center, radius, color));
}
Exemple #16
0
void ProgressBar::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		Ref<StyleBox> bg = get_stylebox("bg");
		Ref<StyleBox> fg = get_stylebox("fg");
		Ref<Font> font = get_font("font");
		Color font_color = get_color("font_color");

		draw_style_box(bg, Rect2(Point2(), get_size()));
		float r = get_as_ratio();
		int mp = fg->get_minimum_size().width;
		int p = r * get_size().width - mp;
		if (p > 0) {

			draw_style_box(fg, Rect2(Point2(), Size2(p + fg->get_minimum_size().width, get_size().height)));
		}

		if (percent_visible) {
			String txt = itos(int(get_as_ratio() * 100)) + "%";
			font->draw_halign(get_canvas_item(), Point2(0, font->get_ascent() + (get_size().height - font->get_height()) / 2), HALIGN_CENTER, get_size().width, txt, font_color);
		}
	}
}
static bool_t draw_vis_cb (GtkWidget * widget, cairo_t * cr)
{
    clear (widget, cr);

    for (int i = 0; i < VIS_BANDS; i++)
    {
        int x = SPACING + 8 * i;
        int t = VIS_CENTER - vis.bars[i];
        int m = MIN (VIS_CENTER + vis.bars[i], HEIGHT);

        float r, g, b;
        get_color (i, & r, & g, & b);

        cairo_set_source_rgb (cr, r, g, b);
        cairo_rectangle (cr, x, t, 6, VIS_CENTER - t);
        cairo_fill (cr);

        cairo_set_source_rgb (cr, r * 0.3, g * 0.3, b * 0.3);
        cairo_rectangle (cr, x, VIS_CENTER, 6, m - VIS_CENTER);
        cairo_fill (cr);
    }

    return TRUE;
}
Exemple #18
0
/**************************************************************************
  Draws a rectangle with top left corner at (canvas_x, canvas_y), and
  width 'w' and height 'h'. It is drawn using the 'selection_gc' context,
  so the pixel combining function is XOR. This means that drawing twice
  in the same place will restore the image to its original state.

  NB: A side effect of this function is to set the 'selection_gc' color
  to COLOR_MAPVIEW_SELECTION.
**************************************************************************/
void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
{
  double dashes[2] = {4.0, 4.0};
  struct color *pcolor;
  cairo_t *cr;

  if (w == 0 || h == 0) {
    return;
  }

  pcolor = get_color(tileset, COLOR_MAPVIEW_SELECTION);
  if (!pcolor) {
    return;
  }

  cr = gdk_cairo_create(gtk_widget_get_window(map_canvas));
  gdk_cairo_set_source_rgba(cr, &pcolor->color);
  cairo_set_line_width(cr, 2.0);
  cairo_set_dash(cr, dashes, 2, 0);
  cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE);
  cairo_rectangle(cr, canvas_x, canvas_y, w, h);
  cairo_stroke(cr);
  cairo_destroy(cr);
}
Exemple #19
0
void R_s_k_2::draw_one_pedge(const Edge& edge,
    const FT value,
    const FT min_value,
    const FT max_value,
    const float line_width)
{
  if (value == min_value)
  {
    viewer->glLineWidth(2*line_width);
    viewer->glColor3f(0.0f, 0.0f, 0.0f);
  }
  else
  {
    viewer->glLineWidth(line_width);
    FT color = (value - min_value) / (max_value - min_value);
    QColor qcolor = get_color(color);
    viewer->glColor3f(qcolor.redF(), qcolor.greenF(), qcolor.blueF());
  }

  Point s = m_dt.source_vertex(edge)->point();
  Point t = m_dt.target_vertex(edge)->point();
  Point c = CGAL::midpoint(s, t);
  draw_edge_with_arrow(c, t);
}
Exemple #20
0
static int
get_border_properties(void)
{
    char *bwidth;
    /*char *bc = NULL;*/
    int bw;
    /*XColor color_def, color_db;*/
    Colormap cmap;
    /*int ret_val;*/


    bwidth = "2";  /* XGetDefault(gXDisplay, "FriCAS.hyperdoc", "BorderWidth") */

    if (bwidth == NULL)
        bw = 1;
    else {
        bw = atoi(bwidth);
        if (bw < 1) {
            fprintf(stderr,
                    "%s: The line width value must be greater than zero\n",
                    "FriCAS.hyperdoc");
            bw = 1;
        }
    }

    /* Now try to find the user preferred border color */

    if (DisplayPlanes(gXDisplay, gXScreenNumber) == 1)
        gBorderColor = BlackPixel(gXDisplay, gXScreenNumber);
    else {
        cmap = DefaultColormap(gXDisplay, gXScreenNumber);
        gBorderColor = get_color("BorderColor", "Foreground",
            BlackPixel(gXDisplay, gXScreenNumber), &cmap);
    }
    return bw;
}
Exemple #21
0
void msgwin_compiler_add_string(gint msg_color, const gchar *msg)
{
	GtkTreeIter iter;
	const GdkColor *color = get_color(msg_color);
	gchar *utf8_msg;

	if (! g_utf8_validate(msg, -1, NULL))
		utf8_msg = utils_get_utf8_from_locale(msg);
	else
		utf8_msg = (gchar *) msg;

	gtk_list_store_append(msgwindow.store_compiler, &iter);
	gtk_list_store_set(msgwindow.store_compiler, &iter,
		COMPILER_COL_COLOR, color, COMPILER_COL_STRING, utf8_msg, -1);

	/* Lazily initialize the line shifts hash table once we get a non-status compiler message */
	if (msg_color != COLOR_BLUE && msgwindow.line_shifts_compiler == NULL)
		msgwindow.line_shifts_compiler = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, free_line_shifts_seq);

	if (ui_prefs.msgwindow_visible && interface_prefs.compiler_tab_autoscroll)
	{
		GtkTreePath *path = gtk_tree_model_get_path(
			gtk_tree_view_get_model(GTK_TREE_VIEW(msgwindow.tree_compiler)), &iter);

		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(msgwindow.tree_compiler), path, NULL, TRUE, 0.5, 0.5);
		gtk_tree_path_free(path);
	}

	/* calling build_menu_update for every build message would be overkill, TODO really should call it once when all done */
	gtk_widget_set_sensitive(build_get_menu_items(-1)->menu_item[GBG_FIXED][GBF_NEXT_ERROR], TRUE);
	gtk_widget_set_sensitive(build_get_menu_items(-1)->menu_item[GBG_FIXED][GBF_PREV_ERROR], TRUE);

	if (utf8_msg != msg)
		g_free(utf8_msg);
}
Exemple #22
0
void	create_line(t_pts a, t_pts b, t_lbx e)
{
	t_pts	len;
	t_pts	coef;
	t_pts	bkpt;
	int		i;

	len.x = ABS((b.isox - a.isox));
	len.y = ABS((b.isoy - a.isoy));
	coef.x = ((len.x && len.y && ((len.x / len.y) < 1)) ? len.x / len.y : 1);
	coef.y = ((len.x && len.y && ((len.y / len.x) < 1)) ? len.y / len.x : 1);
	i = 0;
	while (a.isox != b.isox || a.isoy != b.isoy)
	{
		mlx_pixel_put(e.mlx, e.winx, a.isox, a.isoy, get_color(a, i, coef, e));
		a.isox = ((b.isox > a.isox) ? a.isox + coef.x : a.isox - coef.x);
		a.isoy = ((b.isoy > a.isoy) ? a.isoy + coef.y : a.isoy - coef.y);
		bkpt.x = ABS((a.isox - b.isox));
		bkpt.y = ABS((a.isoy - b.isoy));
		i++;
		if ((bkpt.x <= 1) && (bkpt.y <= 1))
			break ;
	}
}
void AnimationNodeBlendSpace1DEditor::_notification(int p_what) {
	if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
		error_panel->add_style_override("panel", get_stylebox("bg", "Tree"));
		error_label->add_color_override("font_color", get_color("error_color", "Editor"));
		panel->add_style_override("panel", get_stylebox("bg", "Tree"));
		tool_blend->set_icon(get_icon("EditPivot", "EditorIcons"));
		tool_select->set_icon(get_icon("ToolSelect", "EditorIcons"));
		tool_create->set_icon(get_icon("EditKey", "EditorIcons"));
		tool_erase->set_icon(get_icon("Remove", "EditorIcons"));
		snap->set_icon(get_icon("SnapGrid", "EditorIcons"));
		open_editor->set_icon(get_icon("Edit", "EditorIcons"));
	}

	if (p_what == NOTIFICATION_PROCESS) {
		String error;

		if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) {
			error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
		} else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
			error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason();
		}

		if (error != error_label->get_text()) {
			error_label->set_text(error);
			if (error != String()) {
				error_panel->show();
			} else {
				error_panel->hide();
			}
		}
	}

	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
		set_process(is_visible_in_tree());
	}
}
	void MaterialDescription::save_xml(
		const XmlWriterSharedPtr &writer) const
	{
		Uint32 i;
		SamplerParameterType sampler;

		writer->start_element(String(UTF8("material")));
		writer->write_element(String(UTF8("name")), get_name());
		writer->write_element(String(UTF8("effect")), get_effect());
		writer->write_element(String(UTF8("script")), get_script());

		for (i = 0; i < m_textures.size(); ++i)
		{
			sampler = static_cast<SamplerParameterType>(i);

			writer->start_element(SamplerParameterUtil::get_str(
				sampler));
			writer->write_bool_property(String(UTF8("sRGB")),
				get_sRGB(sampler));
			writer->write_string(get_texture(sampler));
			writer->end_element();
		}

		writer->write_mat2x3_element(String(UTF8("texture_matrix_0")),
			get_texture_matrix(0));
		writer->write_mat2x3_element(String(UTF8("texture_matrix_1")),
			get_texture_matrix(1));
		writer->write_vec4_element(String(UTF8("color")), get_color());
		writer->write_vec4_element(String(UTF8("dudv_scale_offset")),
			get_dudv_scale_offset());
		writer->write_bool_element(String(UTF8("cast_shadows")),
			get_cast_shadows());
		writer->write_bool_element(String(UTF8("culling")),
			get_culling());
		writer->end_element();
	}
Exemple #25
0
void delete_case5(struct rbtree *t, rbtree_node *n)
{
    if (n == n->parent->left &&
            get_color(sibling(n)) ==RB_BLACK &&
            get_color(sibling(n)->left) == RB_RED &&
            get_color(sibling(n)->right) == RB_BLACK)
    {
        sibling(n)->color = RB_RED;
        sibling(n)->left->color =RB_BLACK;
        rotate_right(sibling(n),t);
    }
    else if (n == n->parent->right &&
            get_color(sibling(n)) == RB_BLACK &&
            get_color(sibling(n)->right) == RB_RED &&
            get_color(sibling(n)->left) == RB_BLACK)
    {
        sibling(n)->color = RB_RED;
        sibling(n)->right->color = RB_BLACK;
        rotate_left(sibling(n),t);
    }
    delete_case6(t, n);
}
Exemple #26
0
void RichTextLabel::_process_line(ItemFrame *p_frame,const Vector2& p_ofs,int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside,int p_char_count) {

	RID ci;
	if (r_outside)
		*r_outside=false;
	if (p_mode==PROCESS_DRAW) {
		ci=get_canvas_item();

		if (r_click_item)
			*r_click_item=NULL;

	}
	Line &l = p_frame->lines[p_line];
	Item *it = l.from;


	int line_ofs=0;
	int margin=_find_margin(it,p_base_font);
	Align align=_find_align(it);;
	int line=0;
	int spaces=0;


	if (p_mode!=PROCESS_CACHE) {

		ERR_FAIL_INDEX(line,l.offset_caches.size());
		line_ofs = l.offset_caches[line];
	}

	if (p_mode==PROCESS_CACHE) {
		l.offset_caches.clear();
		l.height_caches.clear();
		l.char_count=0;
		l.minimum_width=0;
	}

	int wofs=margin;
	int spaces_size=0;
	int align_ofs=0;


	if (p_mode!=PROCESS_CACHE && align!=ALIGN_FILL)
		wofs+=line_ofs;

	int begin=wofs;

	Ref<Font> cfont = _find_font(it);
	if (cfont.is_null())
		cfont=p_base_font;

	//line height should be the font height for the first time, this ensures that an empty line will never have zero height and succesive newlines are displayed
	int line_height=cfont->get_height();

	Variant meta;

#define NEW_LINE \
{\
	if (p_mode!=PROCESS_CACHE) {\
		line++;\
		if (line < l.offset_caches.size())\
			line_ofs=l.offset_caches[line];\
		wofs=margin;\
		if (align!=ALIGN_FILL)\
			wofs+=line_ofs;\
	} else {\
		int used=wofs-margin;\
		switch(align) {\
			case ALIGN_LEFT: l.offset_caches.push_back(0); break;\
			case ALIGN_CENTER: l.offset_caches.push_back(((p_width-margin)-used)/2); break;\
			case ALIGN_RIGHT: l.offset_caches.push_back(((p_width-margin)-used)); break;\
			case ALIGN_FILL: l.offset_caches.push_back((p_width-margin)-used/*+spaces_size*/); break;\
		}\
		l.height_caches.push_back(line_height);\
		l.space_caches.push_back(spaces);\
	}\
	y+=line_height+get_constant(SceneStringNames::get_singleton()->line_separation);\
	line_height=0;\
	spaces=0;\
	spaces_size=0;\
	wofs=begin;\
	align_ofs=0;\
	if (p_mode!=PROCESS_CACHE) {\
		lh=line<l.height_caches.size()?l.height_caches[line]:1;\
	}\
	if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x<p_ofs.x+wofs) {\
		if (r_outside) *r_outside=true;\
		*r_click_item=it;\
		*r_click_char=rchar;\
		return;\
	}\
}


#define ENSURE_WIDTH(m_width) \
	if (p_mode==PROCESS_CACHE) { \
		l.minimum_width=MAX(l.minimum_width,wofs+m_width);\
	}\
	if (wofs + m_width > p_width) {\
		if (p_mode==PROCESS_CACHE) {\
			if (spaces>0)	\
				spaces-=1;\
		}\
		if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x>p_ofs.x+wofs) {\
			if (r_outside) *r_outside=true;	\
			*r_click_item=it;\
			*r_click_char=rchar;\
			return;\
		}\
		NEW_LINE\
	}


#define ADVANCE(m_width) \
{\
	if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x>=p_ofs.x+wofs && p_click_pos.x<p_ofs.x+wofs+m_width) {\
		if (r_outside) *r_outside=false;	\
		*r_click_item=it;\
		*r_click_char=rchar;\
		return;\
	}\
	wofs+=m_width;\
}

#define CHECK_HEIGHT( m_height ) \
if (m_height > line_height) {\
	line_height=m_height;\
}

	Color selection_fg;
	Color selection_bg;

	if (p_mode==PROCESS_DRAW) {


		selection_fg = get_color("font_color_selected");
		selection_bg = get_color("selection_color");
	}
	int rchar=0;
	int lh=0;

	while (it) {

		switch(it->type) {

			case ITEM_TEXT: {

				ItemText *text = static_cast<ItemText*>(it);

				Ref<Font> font=_find_font(it);
				if (font.is_null())
					font=p_base_font;

				const CharType *c = text->text.c_str();
				const CharType *cf=c;
				int fh=font->get_height();
				int ascent = font->get_ascent();
				Color color;
				bool underline=false;

				if (p_mode==PROCESS_DRAW) {
					color=_find_color(text,p_base_color);
					underline=_find_underline(text);
					if (_find_meta(text,&meta)) {

						underline=true;
					}


				} else if (p_mode==PROCESS_CACHE) {
					l.char_count+=text->text.length();

				}

				rchar=0;

				while(*c) {

					int end=0;
					int w=0;
					int fw=0;

					lh=0;
					if (p_mode!=PROCESS_CACHE) {
						lh=line<l.height_caches.size()?l.height_caches[line]:1;
					}

					while (c[end]!=0 && !(end && c[end-1]==' ' && c[end]!=' ')) {

						int cw = font->get_char_size(c[end],c[end+1]).width;
						if (c[end]=='\t') {
							cw=tab_size*font->get_char_size(' ').width;
						}

						if (end>0 && w+cw+begin > p_width ) {
							break; //don't allow lines longer than assigned width
						}

						w+=cw;
						fw+=cw;

						end++;
					}

					ENSURE_WIDTH(w);

					if (end && c[end-1]==' ') {
						if (p_mode==PROCESS_CACHE) {
							spaces_size+=font->get_char_size(' ').width;
						} else if (align==ALIGN_FILL) {
							int ln = MIN(l.offset_caches.size()-1,line);
							if (l.space_caches[ln]) {
								align_ofs = spaces * l.offset_caches[ln] / l.space_caches[ln];
							}
						}
						spaces++;

					}


					{

						int ofs=0;

						for(int i=0;i<end;i++) {
							int pofs=wofs+ofs;


							if (p_mode==PROCESS_POINTER && r_click_char && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh) {
								//int o = (wofs+w)-p_click_pos.x;


								int cw=font->get_char_size(c[i],c[i+1]).x;

								if (c[i]=='\t') {
									cw=tab_size*font->get_char_size(' ').width;
								}


								if (p_click_pos.x-cw/2>p_ofs.x+align_ofs+pofs) {

									rchar=int((&c[i])-cf);
								}


								ofs+=cw;
							} else if (p_mode==PROCESS_DRAW) {

								bool selected=false;
								if (selection.active) {

									int cofs = (&c[i])-cf;
									if ((text->index > selection.from->index || (text->index == selection.from->index && cofs >=selection.from_char)) && (text->index < selection.to->index || (text->index == selection.to->index && cofs <=selection.to_char))) {
										selected=true;
									}
								}

								int cw=0;

								bool visible = visible_characters<0 || p_char_count<visible_characters;
								if (c[i]=='\t')
									visible=false;

								if (selected) {

									cw = font->get_char_size(c[i],c[i+1]).x;
									draw_rect(Rect2(p_ofs.x+pofs,p_ofs.y+y,cw,lh),selection_bg);
									if (visible)
										font->draw_char(ci,p_ofs+Point2(align_ofs+pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg);

								} else {
									if (visible)
										cw=font->draw_char(ci,p_ofs+Point2(align_ofs+pofs,y+lh-(fh-ascent)),c[i],c[i+1],color);
								}

								p_char_count++;
								if (c[i]=='\t') {
									cw=tab_size*font->get_char_size(' ').width;
								}


								if (underline) {
									Color uc=color;
									uc.a*=0.5;
									int uy = y+lh-fh+ascent+2;
									VS::get_singleton()->canvas_item_add_line(ci,p_ofs+Point2(align_ofs+pofs,uy),p_ofs+Point2(align_ofs+pofs+cw,uy),uc);
								}
								ofs+=cw;
							}

						}
					}


					ADVANCE(fw);
					CHECK_HEIGHT(fh); //must be done somewhere
					c=&c[end];
				}


			} break;
			case ITEM_IMAGE: {

				lh=0;
				if (p_mode!=PROCESS_CACHE)
					lh = line<l.height_caches.size()?l.height_caches[line]:1;
				else
					l.char_count+=1; //images count as chars too

				ItemImage *img = static_cast<ItemImage*>(it);

				Ref<Font> font=_find_font(it);
				if (font.is_null())
					font=p_base_font;

				if (p_mode==PROCESS_POINTER && r_click_char)
					*r_click_char=0;

				ENSURE_WIDTH( img->image->get_width() );

				bool visible = visible_characters<0 || p_char_count<visible_characters;

				if (p_mode==PROCESS_DRAW && visible) {
					img->image->draw(ci,p_ofs+Point2(align_ofs+wofs,y+lh-font->get_descent()-img->image->get_height()));
				}
				p_char_count++;

				ADVANCE( img->image->get_width() );
				CHECK_HEIGHT( (img->image->get_height()+font->get_descent()) );

			} break;
			case ITEM_NEWLINE: {


				lh=0;
				if (p_mode!=PROCESS_CACHE)
					lh = line<l.height_caches.size()?l.height_caches[line]:1;

			} break;
			case ITEM_TABLE: {

				lh=0;
				ItemTable *table = static_cast<ItemTable*>(it);
				int hseparation=get_constant("table_hseparation");
				int vseparation=get_constant("table_vseparation");
				Color ccolor = _find_color(table,p_base_color);
				Vector2 draw_ofs = Point2(wofs,y);

				if (p_mode==PROCESS_CACHE) {

					int idx=0;
					//set minimums to zero
					for(int i=0;i<table->columns.size();i++) {
						table->columns[i].min_width=0;
						table->columns[i].width=0;
					}
					//compute minimum width for each cell
					for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) {
						ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames
						ItemFrame *frame = static_cast<ItemFrame*>(E->get());

						int column = idx % table->columns.size();

						int ly=0;


						for(int i=0;i<frame->lines.size();i++) {

							_process_line(frame,Point2(),ly,p_width,i,PROCESS_CACHE,cfont,Color());
							table->columns[column].min_width=MAX( table->columns[i].min_width, frame->lines[i].minimum_width );
						}
						idx++;
					}

					//compute available width and total radio (for expanders)


					int total_ratio=0;
					int available_width=p_width - hseparation * (table->columns.size() -1);
					table->total_width=hseparation;

					for(int i=0;i<table->columns.size();i++) {
						available_width-=table->columns[i].min_width;
						if (table->columns[i].expand)
							total_ratio+=table->columns[i].expand_ratio;
					}

					//assign actual widths

					for(int i=0;i<table->columns.size();i++) {
						table->columns[i].width = table->columns[i].min_width;
						if (table->columns[i].expand)
							table->columns[i].width+=table->columns[i].expand_ratio*available_width/total_ratio;
						table->total_width+=table->columns[i].width+hseparation;
					}

					//compute caches properly again with the right width
					idx=0;
					for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) {
						ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames
						ItemFrame *frame = static_cast<ItemFrame*>(E->get());

						int column = idx % table->columns.size();


						for(int i=0;i<frame->lines.size();i++) {

							int ly=0;
							_process_line(frame,Point2(),ly,table->columns[column].width,i,PROCESS_CACHE,cfont,Color());
							frame->lines[i].height_cache=ly; //actual height
							frame->lines[i].height_accum_cache=ly; //actual height
						}
						idx++;
					}

				}



				Point2 offset(align_ofs+hseparation,vseparation);

				int row_height=0;
				//draw using computed caches
				int idx=0;
				for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) {
					ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames
					ItemFrame *frame = static_cast<ItemFrame*>(E->get());

					int column = idx % table->columns.size();

					int ly=0;
					int yofs=0;


					int lines_h = frame->lines[frame->lines.size()-1].height_accum_cache - (frame->lines[0].height_accum_cache - frame->lines[0].height_cache);
					int lines_ofs = p_ofs.y+offset.y+draw_ofs.y;

					bool visible = lines_ofs < get_size().height && lines_ofs+lines_h >=0;

					for(int i=0;i<frame->lines.size();i++) {


						if (visible) {
							if (p_mode==PROCESS_DRAW) {
								_process_line(frame,p_ofs+offset+draw_ofs+Vector2(0,yofs),ly,table->columns[column].width,i,PROCESS_DRAW,cfont,ccolor);
							} else if (p_mode==PROCESS_POINTER) {
								_process_line(frame,p_ofs+offset+draw_ofs+Vector2(0,yofs),ly,table->columns[column].width,i,PROCESS_POINTER,cfont,ccolor,p_click_pos,r_click_item,r_click_char,r_outside);
							}
						}

						yofs+=frame->lines[i].height_cache;
						if (p_mode==PROCESS_CACHE) {
							frame->lines[i].height_accum_cache=offset.y+draw_ofs.y+frame->lines[i].height_cache;
						}

					}

					row_height=MAX(yofs,row_height);
					offset.x+=table->columns[column].width+hseparation;

					if (column==table->columns.size()-1) {

						offset.y+=row_height+vseparation;
						offset.x=hseparation;
						row_height=0;
					}
					idx++;
				}

				int total_height = offset.y;
				if (row_height) {
					total_height=row_height+vseparation;
				}



				ADVANCE( table->total_width );
				CHECK_HEIGHT( total_height );

			} break;

			default: {}

		}


		Item *itp = it;

		it = _get_next_item(it);

		if (p_mode == PROCESS_POINTER && r_click_item && itp && !it && p_click_pos.y>p_ofs.y+y+lh) {
			//at the end of all, return this
			if (r_outside) *r_outside=true;
			*r_click_item=itp;
			*r_click_char=rchar;
			return;
		}

		if (it && (p_line+1 < p_frame->lines.size()) && p_frame->lines[p_line+1].from==it) {

			if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh) {
				//went to next line, but pointer was on the previous one
				if (r_outside) *r_outside=true;
				*r_click_item=itp;
				*r_click_char=rchar;
				return;
			}

			break;
		}
	}

	NEW_LINE;

#undef NEW_LINE
#undef ENSURE_WIDTH
#undef ADVANCE
#undef CHECK_HEIGHT

}
Exemple #27
0
void RichTextLabel::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_RESIZED: {

			main->first_invalid_line=0; //invalidate ALL
			update();

		} break;
		case NOTIFICATION_ENTER_TREE: {

			set_bbcode(bbcode);
			main->first_invalid_line=0; //invalidate ALL
			update();

		} break;
		case NOTIFICATION_THEME_CHANGED: {

			if (is_inside_tree() && use_bbcode) {
				parse_bbcode(bbcode);
				//first_invalid_line=0; //invalidate ALL
				//update();
			}

		} break;
		case NOTIFICATION_DRAW: {

			_validate_line_caches(main);
			_update_scroll();


			RID ci=get_canvas_item();
			Size2 size = get_size();

			VisualServer::get_singleton()->canvas_item_set_clip(ci,true);

			if (has_focus()) {
				VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,true);
				draw_style_box(get_stylebox("focus"),Rect2(Point2(),size));
				VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,false);
			}

			int ofs = vscroll->get_val();

			//todo, change to binary search

			int from_line = 0;
			int total_chars = 0;
			while (from_line<main->lines.size()) {

				if (main->lines[from_line].height_accum_cache>=ofs)
					break;
				from_line++;
				total_chars+=main->lines[from_line].char_count;
			}

			if (from_line>=main->lines.size())
				break; //nothing to draw

			int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs;
			Ref<Font> base_font=get_font("normal_font");
			Color base_color=get_color("default_color");

			while (y<size.height && from_line<main->lines.size()) {

				_process_line(main,Point2(),y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars);
				total_chars+=main->lines[from_line].char_count;
				from_line++;
			}
		}
	}
}
Exemple #28
0
Error RichTextLabel::append_bbcode(const String& p_bbcode) {

	int pos = 0;

	List<String> tag_stack;
	Ref<Font> normal_font=get_font("normal_font");
	Ref<Font> bold_font=get_font("bold_font");
	Ref<Font> italics_font=get_font("italics_font");
	Ref<Font> bold_italics_font=get_font("bold_italics_font");
	Ref<Font> mono_font=get_font("mono_font");

	Color base_color=get_color("default_color");

	int indent_level=0;

	bool in_bold=false;
	bool in_italics=false;

	while(pos < p_bbcode.length()) {


		int brk_pos = p_bbcode.find("[",pos);

		if (brk_pos<0)
			brk_pos=p_bbcode.length();

		if (brk_pos > pos) {
			add_text(p_bbcode.substr(pos,brk_pos-pos));
		}

		if (brk_pos==p_bbcode.length())
			break; //nothing else o add

		int brk_end = p_bbcode.find("]",brk_pos+1);

		if (brk_end==-1) {
			//no close, add the rest
			add_text(p_bbcode.substr(brk_pos,p_bbcode.length()-brk_pos));
			break;
		}


		String tag = p_bbcode.substr(brk_pos+1,brk_end-brk_pos-1);


		if (tag.begins_with("/") && tag_stack.size()) {

			bool tag_ok = tag_stack.size() && tag_stack.front()->get()==tag.substr(1,tag.length());



			if (tag_stack.front()->get()=="b")
				in_bold=false;
			if (tag_stack.front()->get()=="i")
				in_italics=false;
			if (tag_stack.front()->get()=="indent")
				indent_level--;


			if (!tag_ok) {

				add_text("[");
				pos++;
				continue;
			}

			tag_stack.pop_front();
			pos=brk_end+1;
			if (tag!="/img")
				pop();

		} else if (tag=="b") {

			//use bold font
			in_bold=true;
			if (in_italics)
				push_font(bold_italics_font);
			else
				push_font(bold_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="i") {

			//use italics font
			in_italics=true;
			if (in_bold)
				push_font(bold_italics_font);
			else
				push_font(italics_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="code") {

			//use monospace font
			push_font(mono_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("table=")) {

			int columns = tag.substr(6,tag.length()).to_int();
			if (columns<1)
				columns=1;
			//use monospace font
			push_table(columns);
			pos=brk_end+1;
			tag_stack.push_front("table");
		} else if (tag=="cell") {

			push_cell();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("cell=")) {

			int ratio = tag.substr(6,tag.length()).to_int();
			if (ratio<1)
				ratio=1;
			//use monospace font
			set_table_column_expand(get_current_table_column(),true,ratio);
			push_cell();
			pos=brk_end+1;
			tag_stack.push_front("cell");
		} else if (tag=="u") {

			//use underline
			push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="s") {

			//use strikethrough (not supported underline instead)
			push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="center") {

			//use underline
			push_align(ALIGN_CENTER);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="fill") {

			//use underline
			push_align(ALIGN_FILL);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="right") {

			//use underline
			push_align(ALIGN_RIGHT);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="ul") {

			//use underline
			push_list(LIST_DOTS);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="ol") {

			//use underline
			push_list(LIST_NUMBERS);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="indent") {

			//use underline
			indent_level++;
			push_indent(indent_level);
			pos=brk_end+1;
			tag_stack.push_front(tag);

		} else if (tag=="url") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String url = p_bbcode.substr(brk_end+1,end-brk_end-1);
			push_meta(url);

			pos=brk_end+1;
			tag_stack.push_front(tag);

		} else if (tag.begins_with("url=")) {

			String url = tag.substr(4,tag.length());
			push_meta(url);
			pos=brk_end+1;
			tag_stack.push_front("url");
		} else if (tag=="img") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String image = p_bbcode.substr(brk_end+1,end-brk_end-1);

			Ref<Texture> texture = ResourceLoader::load(image,"Texture");
			if (texture.is_valid())
				add_image(texture);

			pos=end;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("color=")) {

			String col = tag.substr(6,tag.length());
			Color color;

			if (col.begins_with("#"))
				color=Color::html(col);
			else if (col=="aqua")
				color=Color::html("#00FFFF");
			else if (col=="black")
				color=Color::html("#000000");
			else if (col=="blue")
				color=Color::html("#0000FF");
			else if (col=="fuchsia")
				color=Color::html("#FF00FF");
			else if (col=="gray" || col=="grey")
				color=Color::html("#808080");
			else if (col=="green")
				color=Color::html("#008000");
			else if (col=="lime")
				color=Color::html("#00FF00");
			else if (col=="maroon")
				color=Color::html("#800000");
			else if (col=="navy")
				color=Color::html("#000080");
			else if (col=="olive")
				color=Color::html("#808000");
			else if (col=="purple")
				color=Color::html("#800080");
			else if (col=="red")
				color=Color::html("#FF0000");
			else if (col=="silver")
				color=Color::html("#C0C0C0");
			else if (col=="teal")
				color=Color::html("#008008");
			else if (col=="white")
				color=Color::html("#FFFFFF");
			else if (col=="yellow")
				color=Color::html("#FFFF00");
			else
				color=base_color;



			push_color(color);
			pos=brk_end+1;
			tag_stack.push_front("color");

		} else if (tag.begins_with("font=")) {

			String fnt = tag.substr(5,tag.length());


			Ref<Font> font = ResourceLoader::load(fnt,"Font");
			if (font.is_valid())
				push_font(font);
			else
				push_font(normal_font);

			pos=brk_end+1;
			tag_stack.push_front("font");


		} else {

			add_text("["); //ignore
			pos=brk_pos+1;

		}
	}

	return OK;
}
void grid_segment::draw()
{
    glLineWidth(2);
    utility::gl_color(get_color());

    if(active_survey_param::non_ros::cell_drawing_mode!=2)
    {
        if(convexhull_.size() >= 3)
        {
//            double dc = 1;
//            if(!convexhull_.empty())
//                dc = 1.0/convexhull_.size();
            double i = 0;

            glBegin(GL_LINES);
            for(auto it=begin_convexhull(); it!=end_convexhull(); ++it)
            {
                //glColor3f(i*dc, 0, 1);
                utility::gl_vertex3f(*it, 0.3);
                utility::gl_vertex3f(*(it+1!=end_convexhull()?it+1:begin_convexhull()), 0.3);
                i+=1.0;
            }
            glEnd();
        }
    }


    //    glPointSize(4);
    //    glBegin(GL_POINTS);
    //    for(auto cell:boundary_cells_)
    //        utility::gl_vertex3f(cell->get_center(), 0.4);
    //    glEnd();

//    glColor4f(1, 1,1, 0.8);
//    glPointSize(10);
//    glBegin(GL_POINTS);
//    for(auto cell:uncertain_boundary_)
//        utility::gl_vertex3f(cell->get_center(), 0.4);
//    glEnd();

    if(is_valid())
    {

//            utility::gl_color(cross_color_);
//            if(is_uncertain())
//                glLineWidth(8);
//            else
//                glLineWidth(3);

//            glBegin(GL_LINES);
//            utility::draw_cross(sudo_center_, 0.5);
//            glEnd();

//            if(delayed_segment_)
//            {
//                glColor3f(0.5, 0.5,1);
//                glLineWidth(2);
//                glBegin(GL_LINES);
//                utility::gl_vertex3f(delayed_segment_->get_sudo_center(), 0.51);
//                utility::gl_vertex3f(sudo_center_, 0.51);
//                glEnd();
//            }

//            if(is_uncertain())
//            {
//                utility::gl_color(cross_color_);
//                glLineWidth(1);
//                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//                glBegin(GL_POLYGON);
//                utility::draw_circle(sudo_center_, 2*active_survey_param::coarse_coverage_height, 0.52);
//                glEnd();
//            }
    }

//        if(is_valid())
//        {
//            glColor3f(0,1,0);
//            glLineWidth(2);
//            glBegin(GL_LINES);
//            for(size_t i=0; i+1<coverage_path_.size();i++)
//            {
//                utility::gl_vertex3f(coverage_path_[i]);
//                utility::gl_vertex3f(coverage_path_[i+1]);
//                //glColor3f(1,0,0);
//            }
//            glEnd();

//	    glColor3f(1,1,0);
//            glPointSize(3);
//            glBegin(GL_POINTS);
//            for(size_t i=0; i<coverage_path_.size();i++)
//            {
//                utility::gl_vertex3f(coverage_path_[i]+Vector3f(0,0,0.1));
//            }
//            glEnd();
//        }

    //    glPointSize(6);
    //    glBegin(GL_POINTS);

    //    dc=1;
    //    if(!convexhull_.empty())
    //        dc = 1.0/convexhull_.size();
    //    i=1.0;

    //    for(auto it=begin_convexhull(); it!= end_convexhull(); it++)
    //    {
    //        glColor3f(i*dc, 1,0);
    //        utility::gl_vertex3f(*it, 0.3);
    //        i+=1.0;
    //    }

    //    glEnd();
}
/*
 * must be called from start area.
 * get 4 static columns and build a temple on the disc
 */
uint8_t strat_static_columns(uint8_t configuration)
{
	uint8_t err;
	uint8_t col1_present = 0, col4_present = 0;
	uint16_t old_spdd, old_spda;

	DEBUG(E_USER_STRAT, "%s(%d)", __FUNCTION__, configuration);

	strat_get_speed(&old_spdd, &old_spda);

	/* calibrate scanner */
	i2c_sensorboard_scanner_calib();

	i2c_mechboard_mode_harvest();

	/* go straight. total distance is less than 5 meters */
	strat_set_speed(1000, 1000);
	trajectory_d_rel(&mainboard.traj, BIG_DIST);

	/* when y > 50, break */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(500), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);

	/* turn to 90° abs while going forward */
	DEBUG(E_USER_STRAT, "turn now");
	strat_set_speed(1000, 350);
	trajectory_only_a_abs(&mainboard.traj, COLOR_A(90));

	/* when y > 100, check the presence of column 4 */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1000), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);
	if (get_color() == I2C_COLOR_RED && sensor_get(S_COLUMN_RIGHT))
		col4_present = 1;
	if (get_color() == I2C_COLOR_GREEN && sensor_get(S_COLUMN_LEFT))
		col4_present = 1;

	/* when y > 120, check the presence of column 1 */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1200), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);
	if (get_color() == I2C_COLOR_RED && sensor_get(S_COLUMN_RIGHT))
		col1_present = 1;
	if (get_color() == I2C_COLOR_GREEN && sensor_get(S_COLUMN_LEFT))
		col1_present = 1;

	/* when y > 130, break */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1300), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);

	strat_infos.s_cols.flags |= STATIC_COL_LINE0_DONE;

	DEBUG(E_USER_STRAT, "col4=%d col1=%d", col4_present, col1_present);
	DEBUG(E_USER_STRAT, "have %d cols", get_column_count());

	if (configuration == 0) {
		if (get_column_count() > 2) {
			configuration = 1;
			if (col4_present || col1_present) {
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE2_DONE;
			}
			else {
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE1_DONE;
			}
		}

		/* only 2 colums on the first line */
		else {
			/* all other colums are on line 1 */
			if (col4_present && col1_present) {
				configuration = 2;
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE2_DONE;
			}

			/* only 2 columns on line 1, so there are also
			 * 2 on line 2 */
			else if (col4_present || col1_present) {
				configuration = 4;
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE2_DONE;
			}

			/* all other columns are on line 2 */
			else {
				configuration = 3;
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE1_DONE;
			}
		}
	}

	strat_infos.s_cols.configuration = configuration;
	DEBUG(E_USER_STRAT, "use configuration %d", configuration);

	if (configuration == 1) {
		/* we already got 4 columns, go to the disc directly */

		strat_set_speed(1500, 900);
		trajectory_only_a_abs(&mainboard.traj, COLOR_A(0));
		err = WAIT_COND_OR_TRAJ_END(x_is_more_than(1100), TRAJ_FLAGS_STD);

		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	}
	else if (configuration == 2 /* go from line 0 to line 1 */) {
		strat_set_speed(800, 1000);
		/* relative is needed here */
		trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1300), TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
		strat_set_speed(1000, 600);
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1100),
					    TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	}
	else if (configuration == 3 /* go from line 0 to line 2 and there is 4 columns
		    on line 2*/) {
		strat_set_speed(1000, 600);
		/* relative is needed here */
		trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1110), TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	} 	
	else if (configuration == 4 /* go from line 0 to line 2 and there is 2 columns
		      on line 2 */) {
		strat_set_speed(1000, 600);
		/* relative is needed here */
		trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(600), TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	}
	else {
		trajectory_stop(&mainboard.traj);
	}

	ERROUT(END_TRAJ);

 end:
	strat_set_speed(old_spdd, old_spda);
	return err;
}