Пример #1
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);
		}
	}
}
Пример #2
0
void GameSwitcher::refreshBackground() {
	if (background_image) {
		background_image->ref();
		Rect dest = resizeToScreen(background_image->getWidth(), background_image->getHeight(), true, ALIGN_CENTER);

		Image *resized = background_image->resize(dest.w, dest.h);
		if (resized) {
			if (background)
				delete background;

			background = resized->createSprite();
			resized->unref();
		}

		if (background)
			background->setDest(dest);
	}
}
Пример #3
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);
			}
		}
	}
}