mirror of
https://github.com/libretro/libretro-chailove.git
synced 2024-11-27 02:01:00 +00:00
Add window module
This commit is contained in:
parent
b46b6cec29
commit
b6440a711e
@ -30,33 +30,12 @@ void Application::quit(void) {
|
||||
filesystem.unload();
|
||||
image.unload();
|
||||
sound.unload();
|
||||
SDL_Quit();
|
||||
window.unload();
|
||||
}
|
||||
|
||||
bool Application::load(const std::string& file) {
|
||||
// Initialize SDL.
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
|
||||
printf("Unable to initialize SDL: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Build the Screen.
|
||||
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE | SDL_SRCALPHA | SDL_RESIZABLE);
|
||||
if (screen == NULL) {
|
||||
printf("Unable to create screen: %s", SDL_GetError());
|
||||
SDL_Quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enable video buffering.
|
||||
videoBuffer = (unsigned int *)screen->pixels;
|
||||
|
||||
// Fix alpha blending.
|
||||
if (SDL_SetAlpha(screen, SDL_SRCALPHA, 0) == -1) {
|
||||
printf("Warning: Enabling alpha blending failed.");
|
||||
}
|
||||
|
||||
// Initalize the chaigame subsystems.
|
||||
window.load();
|
||||
filesystem.init(file);
|
||||
graphics.load();
|
||||
keyboard.load();
|
||||
@ -144,5 +123,9 @@ void Application::draw(){
|
||||
|
||||
// Update the screen.
|
||||
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
||||
SDL_Flip(screen);
|
||||
|
||||
// Flip the buffer.
|
||||
if (SDL_Flip(screen) == -1) {
|
||||
printf("Failed to swap the buffers: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
chaigame::joystick joystick;
|
||||
chaigame::mouse mouse;
|
||||
chaigame::math math;
|
||||
chaigame::window window;
|
||||
|
||||
void quit(void);
|
||||
bool load(const std::string& file);
|
||||
|
1
Makefile
1
Makefile
@ -67,6 +67,7 @@ OBJECTS := libretro.o Application.o \
|
||||
chaigame/image.o \
|
||||
chaigame/sound.o \
|
||||
chaigame/math.o \
|
||||
chaigame/window.o \
|
||||
chaigame/mouse.o \
|
||||
chaigame/system.o \
|
||||
chaigame/src/ImageData.o \
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "sound.h"
|
||||
#include "math.h"
|
||||
#include "mouse.h"
|
||||
#include "window.h"
|
||||
#include "src/Quad.h"
|
||||
#include "system.h"
|
||||
#include "audio.h"
|
||||
|
@ -16,6 +16,10 @@ namespace chaigame {
|
||||
}
|
||||
|
||||
bool graphics::load() {
|
||||
// Enable alpha blending.
|
||||
if (SDL_SetAlpha(getScreen(), SDL_SRCALPHA, 0) == -1) {
|
||||
printf("Warning: Enabling alpha blending failed.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "script.h"
|
||||
#include "chaigame.h"
|
||||
#include "../Application.h"
|
||||
//#include "filesystem.h"
|
||||
#include <SDL.h>
|
||||
|
||||
#ifdef __HAVE_CHAISCRIPT__
|
||||
@ -89,6 +88,11 @@ namespace chaigame {
|
||||
chai.add(fun(&audio::play), "play");
|
||||
chai.add_global(var(std::ref(app->audio)), "audio");
|
||||
|
||||
// Register the Window module.
|
||||
chai.add(fun(&window::setTitle), "setTitle");
|
||||
chai.add(fun(&window::getTitle), "getTitle");
|
||||
chai.add_global(var(std::ref(app->window)), "window");
|
||||
|
||||
// Register the Joystick module.
|
||||
chai.add(fun(&joystick::getJoysticks), "getJoysticks");
|
||||
chai.add(fun(&joystick::getJoystickCount), "getJoystickCount");
|
||||
|
45
chaigame/window.cpp
Normal file
45
chaigame/window.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "window.h"
|
||||
#include "../Application.h"
|
||||
#include <SDL.h>
|
||||
#include <string>
|
||||
|
||||
namespace chaigame {
|
||||
|
||||
bool window::load() {
|
||||
Application* app = Application::getInstance();
|
||||
|
||||
// Initialize SDL.
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
|
||||
printf("Unable to initialize SDL: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Build the Screen.
|
||||
app->screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE | SDL_SRCALPHA | SDL_RESIZABLE);
|
||||
if (app->screen == NULL) {
|
||||
printf("Unable to create screen: %s", SDL_GetError());
|
||||
SDL_Quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enable video buffering.
|
||||
app->videoBuffer = (unsigned int *)app->screen->pixels;
|
||||
|
||||
// Set the title.
|
||||
setTitle("ChaiGame");
|
||||
}
|
||||
|
||||
bool window::unload() {
|
||||
SDL_Quit();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string window::getTitle() {
|
||||
// TODO: Implement SDL_WM_GetCaption().
|
||||
return "ChaiGame";
|
||||
}
|
||||
|
||||
void window::setTitle(std::string title) {
|
||||
SDL_WM_SetCaption(title.c_str(), 0);
|
||||
}
|
||||
}
|
17
chaigame/window.h
Normal file
17
chaigame/window.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef _WINDOW_H_INCLUDED_
|
||||
#define _WINDOW_H_INCLUDED_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace chaigame {
|
||||
class window {
|
||||
public:
|
||||
bool load();
|
||||
bool unload();
|
||||
|
||||
std::string getTitle();
|
||||
void setTitle(std::string title);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user