예제 #1
0
void static draw_room(t_room *room, sf::RenderWindow& window, sf::Font& font, t_map *map, uint arrived_count, uint last_ant_id, Scaler& scaler)
{
	const uint room_half = ROOM_SIZE / 2;
	(void)font;
	uint xpos, ypos;
	xpos = scaler.scale(room->coord_x);
	ypos = scaler.scale(room->coord_y);
	sf::RectangleShape rectangle(sf::Vector2f(ROOM_SIZE, ROOM_SIZE));
	rectangle.setPosition(xpos, ypos);
	window.draw(rectangle);

	sf::Text text;
	text.setFont(font);
	text.setString(room->name);
	text.setCharacterSize(24);
	text.setColor(sf::Color::Black);
	text.setPosition(scaler.scale(room->coord_x) + 5, scaler.scale(room->coord_y) + room_half);
	window.draw(text);
	text.setPosition(scaler.scale(room->coord_x) + 5, scaler.scale(room->coord_y));
	text.setCharacterSize(12);
	if (room == map->start)
		text.setString("start " + std::string(ft_itoa(map->ant_count - last_ant_id)));
	else if (room == map->end)
		text.setString("end " + std::string(ft_itoa(arrived_count)));
	else
		return;
	window.draw(text);
}
예제 #2
0
static void draw_move(Move& move, uint frame_index, t_map *map, sf::RenderWindow& window, uint last_ant_id, sf::Font& font, Scaler& scaler)
{
	t_room *room_a;
	if (move.ant_id > last_ant_id)
		room_a = map->start;
	else
		room_a = get_room_by_ant_id(move.ant_id, map);
	t_room *room_b = get_room_by_name(move.room_name.c_str(), map);
	const uint room_half = ROOM_SIZE / 2;
	sf::Vector2f original_pos(scaler.scale(room_a->coord_x) + room_half - ANT_SIZE, scaler.scale(room_a->coord_y) + room_half - ANT_SIZE);
	sf::Vector2f dest_pos(scaler.scale(room_b->coord_x) + room_half - ANT_SIZE, scaler.scale(room_b->coord_y) + room_half - ANT_SIZE);
	sf::Vector2f delta_vec = dest_pos - original_pos;
	delta_vec.x *= ((double)frame_index / FRAME_COUNT);
	delta_vec.y *= ((double)frame_index / FRAME_COUNT);
	sf::Vector2f draw_pos = original_pos + delta_vec;
	sf::CircleShape shape(ANT_SIZE);
	shape.setPosition(draw_pos);
	shape.setFillColor(sf::Color::Red);
	window.draw(shape);
	sf::Text text;
	text.setFont(font);
	text.setString(ft_itoa(move.ant_id));
	text.setCharacterSize(16);
	text.setColor(sf::Color::Black);
	text.setPosition(draw_pos.x + 5, draw_pos.y + 5);
	window.draw(text);
}
예제 #3
0
void static draw_tube(t_room *rooma, t_room *roomb, sf::RenderWindow& window, Scaler& scaler)
{
	const uint room_half = ROOM_SIZE / 2;
	sf::Vertex line[] =
	{
	    sf::Vertex(sf::Vector2f(scaler.scale(rooma->coord_x) + room_half, scaler.scale(rooma->coord_y) + room_half)),
	    sf::Vertex(sf::Vector2f(scaler.scale(roomb->coord_x) + room_half, scaler.scale(roomb->coord_y) + room_half))
	};
	window.draw(line, 2, sf::Lines);
}
예제 #4
0
void showPolygon(const Value& p, const Value& polygon, const Scaler& scaler)
{
    std::cout << "\t<polygon points=\"";
    double x, y;
    for(int i = 0; i < polygon.Size(); i++)
    {
        const Value& p = polygon[i];
        x = p[0].GetDouble();
        y = p[1].GetDouble();
        scaler.scale(x, y);
        std::cout << 100+x << "," << 100+y << " ";
        // std::cout << p[0].GetDouble() << "," << p[1].GetDouble() << " ";
    }
    std::cout << "\"/>" << std::endl;
}
예제 #5
0
Size RadioButton::getPreferredSize(int width, int height) const {
	if (width && height) {
		return Size(width, height);
	}
	SIZE size = {width, height};
	Scaler scaler;
	//if (!SendMessageW(handle(), BCM_GETIDEALSIZE, 0, (LPARAM)&size)) { // XP でうまく動作せず
		Graphics graphics(*this);
		auto oldFont = graphics.font(font());
		auto measureSize = graphics.measureText(text());
		size.cx = measureSize.width;
		size.cy = measureSize.height;
		if (!pushLike()) {
			size.cx += scaler.scale(25);
			size.cy += scaler.scale( 5);
		}
	//}
	if (pushLike()) {
		size.cx += scaler.scale(14);
		size.cy += scaler.scale( 9);
	}
	return Size(width  ? width  : size.cx
			   ,height ? height : size.cy);
}