Beispiel #1
0
void main_io_loop( void )
{
  char *cp;
  while ( 1 )
  {
    default_color( );
    __snprintf_chk( prompt_str, 80, 1, 80, "%d%s", cur_equation + 1, html_flag != 0 ? "-> " : "—> " );
    if ( cp == 0 )
      break;
    process( cp );
  }
}
Beispiel #2
0
int cvfprintf(FILE *stream, int color, const char *fmt, va_list args)
{
	int tty = isatty(fileno(stream));
	
	if (tty)
		start_color(stream, color);

	int ret = vfprintf(stream, fmt, args);

	if (tty)
		default_color(stream);

	return ret;
}
Beispiel #3
0
pcltools::Palette::Palette (unsigned num_colors, unsigned char value, unsigned char saturation) {
  cv::Scalar default_color (0, saturation, value);
  cv::Mat palette (1, num_colors, CV_8UC3, default_color);

  for (int i = 0; i < num_colors; i++) {
    uchar hue = static_cast<uchar>(round (static_cast<double>(i * 180) / num_colors));
    palette.at <cv::Vec3b> (cv::Point (i, 0))[0] = hue;
  }

  cv::cvtColor (palette, palette, CV_HSV2RGB);

  for (int i = 0; i < num_colors; i++) {
    cv::Vec3b const & pixel = palette.at <cv::Vec3b> (cv::Point (i, 0));
    auto color = RGBColor {pixel[0], pixel[1], pixel[2]};
    rgb_colors_.push_back (color);
  }

  auto size = rgb_colors_.size ();
  auto new_indices = std::vector <size_t> (size);
  auto is_set = std::vector <bool> (size);
  auto current_index = 0UL;

  for (auto & new_index : new_indices) {
    new_index = current_index;
    is_set.at (current_index) = true;
    current_index = (current_index + (size / 2)) % size;

    auto try_count = 0;
    while (is_set.at (current_index) && try_count < size) {
      if (current_index == 0)
        current_index = size - 1;
      else
        --current_index;
      ++try_count;
    }
  }

  auto rgb_colors_copy = rgb_colors_;

  auto old_index = 0UL;
  for (auto const & index : new_indices) {
    rgb_colors_.at (old_index) = rgb_colors_copy.at (index);
    ++old_index;
  }
}
Beispiel #4
0
	virtual void do_draw_overlay( const ui::paint_event_t& event) const
	{
		RAMEN_ASSERT( node()->composition());

		move2d_node_t::matrix3_type lm( param_->matrix_at_frame( node()->composition()->frame(), node()->aspect_ratio()));

		Imath::V2f p = get_absolute_value<Imath::V2f>( param_->center_param());
	    p = p * lm;
		p.x *= node()->aspect_ratio();

		gl_line_width( default_line_width());
	    manipulators::draw_xy_axes( p, 70 / event.pixel_scale, 70 / event.pixel_scale,
									get_value<float>( param_->rotate_param()),
									event.aspect_ratio / node()->aspect_ratio(),
									  ui::palette_t::instance().color("x_axis"),
									  ui::palette_t::instance().color("y_axis"), event.pixel_scale);

	    manipulators::draw_cross( p, 3 / event.pixel_scale, 3 / event.pixel_scale, default_color(), event.pixel_scale);
		manipulators::draw_ellipse( p, 7 / event.pixel_scale, 7 / event.pixel_scale, Imath::Color3c( 255, 255, 255), 20);

		// draw the boundary
		move2d_node_t::matrix3_type gm( node()->global_matrix());
		gm *= move2d_node_t::matrix3_type().setScale( move2d_node_t::vector2_type( node()->aspect_ratio(), 1));

	    Imath::Box2i bbox( node()->format());
		++bbox.max.x;
		++bbox.max.y;

		float offset = manipulators::shadow_offset( event.pixel_scale);
		gl_line_width( manipulator_t::default_line_width());
		gl_point_size( manipulator_t::default_control_point_size());

		// shadow
		gl_color3ub( 0, 0, 0);
	    gl_begin( GL_LINE_LOOP);
			manipulators::gl_transformed_box( bbox, gm, offset);
	    gl_end();

		// color
		gl_color( manipulator_t::default_color());
	    gl_begin( GL_LINE_LOOP);
			manipulators::gl_transformed_box( bbox, gm);
	    gl_end();
	}
Beispiel #5
0
void quad_manipulator_t::do_draw_overlay( const ui::paint_event_t& event) const
{	
	boost::array<Imath::V2f, 4> dst_pts;
	get_corners( dst_pts, event.aspect_ratio);

	gl_line_width( default_line_width());
	gl_point_size( default_control_point_size());	
	// shadow
	float off = manipulators::shadow_offset( event.pixel_scale);
	gl_color3ub( 0, 0, 0);
	gl_begin( GL_LINE_LOOP);
		for( int i = 0; i < 4; ++i)
			gl_vertex2f( dst_pts[i].x + off, dst_pts[i].y + off);
	gl_end();

	gl_begin( GL_POINTS);
		for( int i = 0; i < 4; ++i)
			gl_vertex2f( dst_pts[i].x + off, dst_pts[i].y + off);
	gl_end();
	
	// color	
	gl_color( default_color());
	gl_begin( GL_LINE_LOOP);
		for( int i = 0; i < 4; ++i)
			gl_vertex2f( dst_pts[i].x, dst_pts[i].y);
	gl_end();

	// draw corners
	gl_begin( GL_POINTS);
	for( int i = 0; i < 4; ++i)
	{
		if( i != picked_corner_)
			gl_vertex2f( dst_pts[i].x, dst_pts[i].y);
	}
	gl_end();
	
	for( int i = 0; i < 4; ++i)
	{
		if( i == picked_corner_)
			manipulators::draw_small_box( dst_pts[i], 3 / event.pixel_scale);
	}
}
Beispiel #6
0
void engine::load() {
    color default_color(255, 0, 0, 255);
    rast = new rasterizer(default_color);
    player = new t_transform();
    cam = new camera(frame->get_width(), frame->get_height());
    t_transform::set_camera(cam);
    vector3* start = new vector3(-20, 0, 0);
    cam->set_position(start);
    t_transform::set_projection((float)70, (float) frame->get_width(), frame->get_height(), (float) 1, (float)1000);
    game_input->inputs.push_back(cam);
    mesh m;
    m.from_obj("res/testgolem.obj");
    mesh m2;
    m2.from_obj("res/testalduinsmall.obj");
    image texture;
    texture.from_ppm_raw("res/testgolem.ppm");
    image texture2;
    texture2.from_ppm_raw("res/alduin_lod.ppm");
    thing* t = new thing();
    t->set_mesh(m);
    t->set_texture(texture);
    t->t.set_scale(1, 1, 1);
    thing* t2 = new thing();
    t2->set_mesh(m2);
    t2->set_texture(texture2);
    t2->t.set_scale(2, 2, 2);
    t2->t.set_translation(20, 0, 0);
    mesh m3;
    m3.from_obj("res/testplane.obj");
    image texture3;
    texture3.from_ppm_raw("res/testkoala.ppm");
    thing* t3 = new thing();
    t3->set_mesh(m3);
    t3->set_texture(texture3);
    t3->t.set_translation(0, -5, 0);
    //scene.things.push_back(t);
    scene.things.push_back(t2);
    //scene.things.push_back(t3);
}
    Palette(int num_colors) {
        if(num_colors <=0)
            num_colors = DEFAULT_NUM_COLORS;

        cv::Scalar default_color(DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_VALUE);
        cv::Mat palette(1, num_colors, CV_8UC3, default_color);

        for(int i=0; i<num_colors; i++) {
            uchar hue = static_cast<uchar>(round(static_cast<double>(i * MAX_HUE)/num_colors));
            palette.at<cv::Vec3b>(cv::Point(i,0))[0] = hue;
        }

        cv::cvtColor(palette, palette, CV_HSV2BGR);

        for(int i=0; i<num_colors; i++) {
            cv::Vec3b &pixel = palette.at<cv::Vec3b>(cv::Point(i, 0));
            cv::Scalar color(pixel[0], pixel[1], pixel[2]);
            colors_.push_back(color);
        }

        // TODO: Something better than just shuffling
        std::default_random_engine engine(std::random_device{}());
        std::shuffle(std::begin(colors_), std::end(colors_), engine);
    }
Beispiel #8
0
void GUITable::setTable(const TableOptions &options,
		const TableColumns &columns,
		std::vector<std::string> &content)
{
	clear();

	// Naming conventions:
	// i is always a row index, 0-based
	// j is always a column index, 0-based
	// k is another index, for example an option index

	// Handle a stupid error case... (issue #1187)
	if (columns.empty()) {
		TableColumn text_column;
		text_column.type = "text";
		TableColumns new_columns;
		new_columns.push_back(text_column);
		setTable(options, new_columns, content);
		return;
	}

	// Handle table options
	video::SColor default_color(255, 255, 255, 255);
	s32 opendepth = 0;
	for (size_t k = 0; k < options.size(); ++k) {
		const std::string &name = options[k].name;
		const std::string &value = options[k].value;
		if (name == "color")
			parseColorString(value, m_color, false);
		else if (name == "background")
			parseColorString(value, m_background, false);
		else if (name == "border")
			m_border = is_yes(value);
		else if (name == "highlight")
			parseColorString(value, m_highlight, false);
		else if (name == "highlight_text")
			parseColorString(value, m_highlight_text, false);
		else if (name == "opendepth")
			opendepth = stoi(value);
		else
			errorstream<<"Invalid table option: \""<<name<<"\""
				<<" (value=\""<<value<<"\")"<<std::endl;
	}

	// Get number of columns and rows
	// note: error case columns.size() == 0 was handled above
	s32 colcount = columns.size();
	assert(colcount >= 1);
	// rowcount = ceil(cellcount / colcount) but use integer arithmetic
	s32 rowcount = (content.size() + colcount - 1) / colcount;
	assert(rowcount >= 0);
	// Append empty strings to content if there is an incomplete row
	s32 cellcount = rowcount * colcount;
	while (content.size() < (u32) cellcount)
		content.push_back("");

	// Create temporary rows (for processing columns)
	struct TempRow {
		// Current horizontal position (may different between rows due
		// to indent/tree columns, or text/image columns with width<0)
		s32 x;
		// Tree indentation level
		s32 indent;
		// Next cell: Index into m_strings or m_images
		s32 content_index;
		// Next cell: Width in pixels
		s32 content_width;
		// Vector of completed cells in this row
		std::vector<Cell> cells;
		// Stores colors and how long they last (maximum column index)
		std::vector<std::pair<video::SColor, s32> > colors;

		TempRow(): x(0), indent(0), content_index(0), content_width(0) {}
	};
	TempRow *rows = new TempRow[rowcount];

	// Get em width. Pedantically speaking, the width of "M" is not
	// necessarily the same as the em width, but whatever, close enough.
	s32 em = 6;
	if (m_font)
		em = m_font->getDimension(L"M").Width;

	s32 default_tooltip_index = allocString("");

	std::map<s32, s32> active_image_indices;

	// Process content in column-major order
	for (s32 j = 0; j < colcount; ++j) {
		// Check column type
		ColumnType columntype = COLUMN_TYPE_TEXT;
		if (columns[j].type == "text")
			columntype = COLUMN_TYPE_TEXT;
		else if (columns[j].type == "image")
			columntype = COLUMN_TYPE_IMAGE;
		else if (columns[j].type == "color")
			columntype = COLUMN_TYPE_COLOR;
		else if (columns[j].type == "indent")
			columntype = COLUMN_TYPE_INDENT;
		else if (columns[j].type == "tree")
			columntype = COLUMN_TYPE_TREE;
		else
			errorstream<<"Invalid table column type: \""
				<<columns[j].type<<"\""<<std::endl;

		// Process column options
		s32 padding = myround(0.5 * em);
		s32 tooltip_index = default_tooltip_index;
		s32 align = 0;
		s32 width = 0;
		s32 span = colcount;

		if (columntype == COLUMN_TYPE_INDENT) {
			padding = 0; // default indent padding
		}
		if (columntype == COLUMN_TYPE_INDENT ||
				columntype == COLUMN_TYPE_TREE) {
			width = myround(em * 1.5); // default indent width
		}

		for (size_t k = 0; k < columns[j].options.size(); ++k) {
			const std::string &name = columns[j].options[k].name;
			const std::string &value = columns[j].options[k].value;
			if (name == "padding")
				padding = myround(stof(value) * em);
			else if (name == "tooltip")
				tooltip_index = allocString(value);
			else if (name == "align" && value == "left")
				align = 0;
			else if (name == "align" && value == "center")
				align = 1;
			else if (name == "align" && value == "right")
				align = 2;
			else if (name == "align" && value == "inline")
				align = 3;
			else if (name == "width")
				width = myround(stof(value) * em);
			else if (name == "span" && columntype == COLUMN_TYPE_COLOR)
				span = stoi(value);
			else if (columntype == COLUMN_TYPE_IMAGE &&
					!name.empty() &&
					string_allowed(name, "0123456789")) {
				s32 content_index = allocImage(value);
				active_image_indices.insert(std::make_pair(
							stoi(name),
							content_index));
			}
			else {
				errorstream<<"Invalid table column option: \""<<name<<"\""
					<<" (value=\""<<value<<"\")"<<std::endl;
			}
		}

		// If current column type can use information from "color" columns,
		// find out which of those is currently active
		if (columntype == COLUMN_TYPE_TEXT) {
			for (s32 i = 0; i < rowcount; ++i) {
				TempRow *row = &rows[i];
				while (!row->colors.empty() && row->colors.back().second < j)
					row->colors.pop_back();
			}
		}

		// Make template for new cells
		Cell newcell;
		memset(&newcell, 0, sizeof newcell);
		newcell.content_type = columntype;
		newcell.tooltip_index = tooltip_index;
		newcell.reported_column = j+1;

		if (columntype == COLUMN_TYPE_TEXT) {
			// Find right edge of column
			s32 xmax = 0;
			for (s32 i = 0; i < rowcount; ++i) {
				TempRow *row = &rows[i];
				row->content_index = allocString(content[i * colcount + j]);
				const core::stringw &text = m_strings[row->content_index];
				row->content_width = m_font ?
					m_font->getDimension(text.c_str()).Width : 0;
				row->content_width = MYMAX(row->content_width, width);
				s32 row_xmax = row->x + padding + row->content_width;
				xmax = MYMAX(xmax, row_xmax);
			}
			// Add a new cell (of text type) to each row
			for (s32 i = 0; i < rowcount; ++i) {
				newcell.xmin = rows[i].x + padding;
				alignContent(&newcell, xmax, rows[i].content_width, align);
				newcell.content_index = rows[i].content_index;
				newcell.color_defined = !rows[i].colors.empty();
				if (newcell.color_defined)
					newcell.color = rows[i].colors.back().first;
				rows[i].cells.push_back(newcell);
				rows[i].x = newcell.xmax;
			}
		}
		else if (columntype == COLUMN_TYPE_IMAGE) {
			// Find right edge of column
			s32 xmax = 0;
			for (s32 i = 0; i < rowcount; ++i) {
				TempRow *row = &rows[i];
				row->content_index = -1;

				// Find content_index. Image indices are defined in
				// column options so check active_image_indices.
				s32 image_index = stoi(content[i * colcount + j]);
				std::map<s32, s32>::iterator image_iter =
					active_image_indices.find(image_index);
				if (image_iter != active_image_indices.end())
					row->content_index = image_iter->second;

				// Get texture object (might be NULL)
				video::ITexture *image = NULL;
				if (row->content_index >= 0)
					image = m_images[row->content_index];

				// Get content width and update xmax
				row->content_width = image ? image->getOriginalSize().Width : 0;
				row->content_width = MYMAX(row->content_width, width);
				s32 row_xmax = row->x + padding + row->content_width;
				xmax = MYMAX(xmax, row_xmax);
			}
			// Add a new cell (of image type) to each row
			for (s32 i = 0; i < rowcount; ++i) {
				newcell.xmin = rows[i].x + padding;
				alignContent(&newcell, xmax, rows[i].content_width, align);
				newcell.content_index = rows[i].content_index;
				rows[i].cells.push_back(newcell);
				rows[i].x = newcell.xmax;
			}
			active_image_indices.clear();
		}
		else if (columntype == COLUMN_TYPE_COLOR) {
			for (s32 i = 0; i < rowcount; ++i) {
				video::SColor cellcolor(255, 255, 255, 255);
				if (parseColorString(content[i * colcount + j], cellcolor, true))
					rows[i].colors.push_back(std::make_pair(cellcolor, j+span));
			}
		}
		else if (columntype == COLUMN_TYPE_INDENT ||
				columntype == COLUMN_TYPE_TREE) {
			// For column type "tree", reserve additional space for +/-
			// Also enable special processing for treeview-type tables
			s32 content_width = 0;
			if (columntype == COLUMN_TYPE_TREE) {
				content_width = m_font ? m_font->getDimension(L"+").Width : 0;
				m_has_tree_column = true;
			}
			// Add a new cell (of indent or tree type) to each row
			for (s32 i = 0; i < rowcount; ++i) {
				TempRow *row = &rows[i];

				s32 indentlevel = stoi(content[i * colcount + j]);
				indentlevel = MYMAX(indentlevel, 0);
				if (columntype == COLUMN_TYPE_TREE)
					row->indent = indentlevel;

				newcell.xmin = row->x + padding;
				newcell.xpos = newcell.xmin + indentlevel * width;
				newcell.xmax = newcell.xpos + content_width;
				newcell.content_index = 0;
				newcell.color_defined = !rows[i].colors.empty();
				if (newcell.color_defined)
					newcell.color = rows[i].colors.back().first;
				row->cells.push_back(newcell);
				row->x = newcell.xmax;
			}
		}
	}

	// Copy temporary rows to not so temporary rows
	if (rowcount >= 1) {
		m_rows.resize(rowcount);
		for (s32 i = 0; i < rowcount; ++i) {
			Row *row = &m_rows[i];
			row->cellcount = rows[i].cells.size();
			row->cells = new Cell[row->cellcount];
			memcpy((void*) row->cells, (void*) &rows[i].cells[0],
					row->cellcount * sizeof(Cell));
			row->indent = rows[i].indent;
			row->visible_index = i;
			m_visible_rows.push_back(i);
		}
	}

	if (m_has_tree_column) {
		// Treeview: convert tree to indent cells on leaf rows
		for (s32 i = 0; i < rowcount; ++i) {
			if (i == rowcount-1 || m_rows[i].indent >= m_rows[i+1].indent)
				for (s32 j = 0; j < m_rows[i].cellcount; ++j)
					if (m_rows[i].cells[j].content_type == COLUMN_TYPE_TREE)
						m_rows[i].cells[j].content_type = COLUMN_TYPE_INDENT;
		}

		// Treeview: close rows according to opendepth option
		std::set<s32> opened_trees;
		for (s32 i = 0; i < rowcount; ++i)
			if (m_rows[i].indent < opendepth)
				opened_trees.insert(i);
		setOpenedTrees(opened_trees);
	}

	// Delete temporary information used only during setTable()
	delete[] rows;
	allocationComplete();

	// Clamp scroll bar position
	updateScrollBar();
}