示例#1
0
void debug_frame(std::vector<SDL_Event>& events) {
	int mouse_x = gui.mouse_x;
	int mouse_y = gui.mouse_y;
	int mouse_buttons = gui.mouse_buttons;

	for (const auto& ev : events) {
		switch (ev.type) {
		case SDL_MOUSEMOTION:
			mouse_x = ev.motion.x;
			mouse_y = ev.motion.y;
			break;
		case SDL_MOUSEBUTTONUP:
		case SDL_MOUSEBUTTONDOWN:
			int button_bit = BIT(ev.button.button);
			mouse_buttons = (mouse_buttons & (~button_bit)) | (ev.button.state == SDL_MOUSEBUTTONDOWN ? button_bit : 0);
			break;
		}
	}
	events.clear();

	gui.update_input(mouse_x, mouse_y, mouse_buttons);

	fillSurface(3, debug_win.getSurface());
	gui.label("HELLO WORLD!", 8, 8);
	gui.label("HELLO WORLD!", gui.mouse_x, gui.mouse_y, 8);

	debug_win.present();
}
示例#2
0
	void redraw()
	{
		fillSurface(winSurf, cBgNorm);

		for (size_t i = 0; i < widgets.size(); ++i)
			widgets[i]->draw(winSurf);

		if (state == AwaitingInput)
		{
			char buf[64];
			snprintf(buf, sizeof(buf), "Press key or joystick button for \"%s\"", captureName);

			drawOff = Vec2i();

			SDL_Surface *dark = createSurface(winSize.x, winSize.y);
			fillSurface(dark, 0);
			SDL_SetSurfaceAlphaMod(dark, 128);
			SDL_SetSurfaceBlendMode(dark, SDL_BLENDMODE_BLEND);
			SDL_Surface *txt = createTextSurface(buf, false);

			SDL_BlitSurface(dark, 0, winSurf, 0);

			SDL_Rect fill;
			fill.x = (winSize.x - txt->w - 20) / 2;
			fill.y = (winSize.y - txt->h - 20) / 2;
			fill.w = txt->w + 20;
			fill.h = txt->h + 20;

			fillRect(winSurf, cBgNorm, fill.x, fill.y, fill.w, fill.h);
			strokeRectInner(winSurf, cLine, fill.x, fill.y, fill.w, fill.h, 2);

			fill.x += 10;
			fill.y += 10;
			fill.w = txt->w;
			fill.h = txt->h;

			SDL_BlitSurface(txt, 0, winSurf, &fill);

			SDL_FreeSurface(txt);
			SDL_FreeSurface(dark);
		}

		SDL_UpdateWindowSurface(window);
	}