Ejemplo n.º 1
0
void GameSwitcher::showFPS(int fps) {
    if (SHOW_FPS) {
        if (!label_fps) label_fps = new WidgetLabel();
        std::string sfps = toString(typeid(fps), &fps) + std::string(" fps");
        Rect pos = fps_position;
        alignToScreenEdge(fps_corner, &pos);
        label_fps->set(pos.x, pos.y, JUSTIFY_LEFT, VALIGN_TOP, sfps, fps_color);
        label_fps->render();
    }
}
Ejemplo n.º 2
0
/**
 * Aligns the menu relative to one of these positions:
 * topleft, top, topright, left, center, right, bottomleft, bottom, bottomright
 */
void Menu::align() {
	alignToScreenEdge(alignment, &window_area);

	if (background) {
		background->setClip(
			0,
			0,
			window_area.w,
			window_area.h
		);
		background->setDest(window_area);
	}
}
Ejemplo n.º 3
0
void Scene::refreshWidgets() {
	if (!caption.empty()) {
		int caption_width = VIEW_W - static_cast<int>(VIEW_W * (caption_margins.x * 2.0f));
		font->setFont("font_captions");
		caption_size = font->calc_size(caption, caption_width);

		if (!caption_box) {
			caption_box = new WidgetScrollBox(VIEW_W, caption_size.y);
			caption_box->setBasePos(0, 0, ALIGN_BOTTOM);
		}
		else {
			caption_box->pos.h = caption_size.y;
			caption_box->resize(VIEW_W, caption_size.y);
		}

		caption_box->setPos(0, static_cast<int>(static_cast<float>(VIEW_H) * caption_margins.y) * (-1));

		font->renderShadowed(caption, VIEW_W / 2, 0,
							 JUSTIFY_CENTER,
							 caption_box->contents->getGraphics(),
							 caption_width,
							 FONT_WHITE);
	}

	if (art) {
		Rect art_dest;
		if (scale_graphics) {
			art_dest = resizeToScreen(art_size.x, art_size.y, false, ALIGN_CENTER);

			art->getGraphics()->ref(); // resize unref's our image (which we want to keep), so counter that here
			Image *resized = art->getGraphics()->resize(art_dest.w, art_dest.h);
			if (resized != NULL) {
				if (art_scaled) {
					delete art_scaled;
				}
				art_scaled = resized->createSprite();
				resized->unref();
			}

			if (art_scaled)
				art_scaled->setDest(art_dest);
		}
		else {
			art_dest.w = art_size.x;
			art_dest.h = art_size.y;

			alignToScreenEdge(ALIGN_CENTER, &art_dest);
			art->setDest(art_dest);
		}
	}
}
Ejemplo n.º 4
0
void GameSwitcher::showFPS(int fps) {
	if (SHOW_FPS && SHOW_HUD) {
		if (!label_fps) label_fps = new WidgetLabel();
		if (fps_ticks == 0) {
			fps_ticks = MAX_FRAMES_PER_SEC / 4;

			int avg_fps = (fps + last_fps) / 2;
			last_fps = fps;
			std::string sfps = toString(typeid(avg_fps), &avg_fps) + std::string(" fps");
			Rect pos = fps_position;
			alignToScreenEdge(fps_corner, &pos);
			label_fps->set(pos.x, pos.y, JUSTIFY_LEFT, VALIGN_TOP, sfps, fps_color);
		}
		label_fps->render();
		fps_ticks--;
	}
}
Ejemplo n.º 5
0
void Subtitles::updateLabelAndBackground() {
	// position subtitle
	Rect r;
	r.x = label_pos.x;
	r.y = label_pos.y;
	alignToScreenEdge(label_alignment, &r);
	label.set(r.x + text_pos.x, r.y + text_pos.y, text_pos.justify, text_pos.valign, current_text, font->getColor("menu_normal"), text_pos.font_style);

	// background is transparent, no need to create a background surface
	if (background_color.a == 0)
		return;

	// create padded background rectangle
	Rect old_background_rect = background_rect;
	background_rect = label.bounds;
	int padding = font->getLineHeight()/4;
	background_rect.x -= padding;
	background_rect.y -= padding;
	background_rect.w += padding*2;
	background_rect.h += padding*2;

	// update our background surface if needed
	if (!background || old_background_rect.w != background_rect.w || old_background_rect.h != background_rect.h) {
		if (background) {
			delete background;
			background = NULL;
		}

		// fill the background rectangle
		Image *temp = render_device->createImage(background_rect.w, background_rect.h);
		if (temp) {
			// translucent black background
			temp->fillWithColor(background_color);
			background = temp->createSprite();
			temp->unref();
		}
	}

	if (background) {
		background->setDest(background_rect.x, background_rect.y);
	}
}
Ejemplo n.º 6
0
Rect resizeToScreen(int w, int h, bool crop, ALIGNMENT align) {
	Rect r;

	// fit to height
	float ratio = VIEW_H / static_cast<float>(h);
	r.w = static_cast<int>(static_cast<float>(w) * ratio);
	r.h = VIEW_H;

	if (!crop) {
		// fit to width
		if (r.w > VIEW_W) {
			ratio = VIEW_W / static_cast<float>(w);
			r.h = static_cast<int>(static_cast<float>(h) * ratio);
			r.w = VIEW_W;
		}
	}

	alignToScreenEdge(align, &r);

	return r;
}
Ejemplo n.º 7
0
void GameSwitcher::loadFPS() {
	// Load FPS rendering settings
	FileParser infile;
	// @CLASS GameSwitcher: FPS counter|Description of menus/fps.txt
	if (infile.open("menus/fps.txt")) {
		while(infile.next()) {
			// @ATTR position|x (integer), y (integer), align (alignment)|Position of the fps counter.
			if(infile.key == "position") {
				fps_position.x = popFirstInt(infile.val);
				fps_position.y = popFirstInt(infile.val);
				fps_corner = popFirstString(infile.val);
			}
			// @ATTR color|r (integer), g (integer), b (integer)|Color of the fps counter text.
			else if(infile.key == "color") {
				fps_color = toRGB(infile.val);
			}
			else {
				infile.error("GameSwitcher: '%s' is not a valid key.", infile.key.c_str());
			}
		}
		infile.close();
	}

	// this is a dummy string used to approximate the fps position when aligned to the right
	font->setFont("font_regular");
	fps_position.w = font->calc_width("00 fps");
	fps_position.h = font->getLineHeight();

	alignToScreenEdge(fps_corner, &fps_position);

	// Delete the label object if it exists (we'll recreate this with showFPS())
	if (label_fps) {
		delete label_fps;
		label_fps = NULL;
	}
}
Ejemplo n.º 8
0
void Scene::refreshWidgets() {
	if (cutscene_type ==  CUTSCENE_STATIC) {
		if (!caption.empty()) {
			int caption_width = VIEW_W - static_cast<int>(VIEW_W * (settings.caption_margins.x * 2.0f));
			font->setFont("font_captions");
			Point caption_size = font->calc_size(caption, caption_width);

			if (!caption_box) {
				caption_box = new WidgetScrollBox(VIEW_W, caption_size.y);
				caption_box->setBasePos(0, 0, ALIGN_BOTTOM);
			}
			else {
				caption_box->pos.h = caption_size.y;
				caption_box->resize(VIEW_W, caption_size.y);
			}

			caption_box->setPos(0, static_cast<int>(static_cast<float>(VIEW_H) * settings.caption_margins.y) * (-1));

			font->renderShadowed(caption, VIEW_W / 2, 0,
								 JUSTIFY_CENTER,
								 caption_box->contents->getGraphics(),
								 caption_width,
								 FONT_WHITE);
		}

		if (art) {
			Rect art_dest;
			if (settings.scale_graphics) {
				art_dest = resizeToScreen(art_size.x, art_size.y, false, ALIGN_CENTER);

				art->getGraphics()->ref(); // resize unref's our image (which we want to keep), so counter that here
				Image *resized = art->getGraphics()->resize(art_dest.w, art_dest.h);
				if (resized != NULL) {
					if (art_scaled) {
						delete art_scaled;
					}
					art_scaled = resized->createSprite();
					resized->unref();
				}

				if (art_scaled)
					art_scaled->setDest(art_dest);
			}
			else {
				art_dest.w = art_size.x;
				art_dest.h = art_size.y;

				alignToScreenEdge(ALIGN_CENTER, &art_dest);
				art->setDest(art_dest);
			}
		}
	}
	else if (cutscene_type == CUTSCENE_VSCROLL) {
		// position elements relative to the vertical offset
		for (size_t i = 0; i < vscroll_components.size(); ++i) {
			if (vscroll_components[i].text) {
				vscroll_components[i].text->setX(VIEW_W/2);
				vscroll_components[i].text->setY(vscroll_components[i].pos.y - vscroll_offset);
			}
			else if (vscroll_components[i].image) {
				int x = VIEW_W/2 - vscroll_components[i].image_size.x/2;
				int y = vscroll_components[i].pos.y - vscroll_offset;
				vscroll_components[i].image->setDest(x, y);
			}
		}
	}
}