- Allow to change display zoom and fullscreen
This commit is contained in:
36
mini.cpp
36
mini.cpp
@@ -18,6 +18,7 @@ char window_title[256];
|
|||||||
uint16_t screen_width = 160;
|
uint16_t screen_width = 160;
|
||||||
uint16_t screen_height = 120;
|
uint16_t screen_height = 120;
|
||||||
uint8_t screen_zoom = 4;
|
uint8_t screen_zoom = 4;
|
||||||
|
bool screen_fullscreen = false;
|
||||||
uint8_t show_cursor = SDL_ENABLE;
|
uint8_t show_cursor = SDL_ENABLE;
|
||||||
|
|
||||||
surface_t surfaces[10];
|
surface_t surfaces[10];
|
||||||
@@ -184,6 +185,21 @@ void setmap(uint8_t surface) {
|
|||||||
map_surface = &surfaces[surface];
|
map_surface = &surfaces[surface];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void createDisplay() {
|
||||||
|
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN);
|
||||||
|
mini_ren = SDL_CreateRenderer(mini_win, -1, 0);
|
||||||
|
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
||||||
|
SDL_RenderSetLogicalSize(mini_ren, screen_width, screen_height);
|
||||||
|
SDL_ShowCursor(show_cursor);
|
||||||
|
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyDisplay() {
|
||||||
|
SDL_DestroyTexture(mini_bak);
|
||||||
|
SDL_DestroyRenderer(mini_ren);
|
||||||
|
SDL_DestroyWindow(mini_win);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc,char*argv[]){
|
int main(int argc,char*argv[]){
|
||||||
|
|
||||||
while (!should_quit) {
|
while (!should_quit) {
|
||||||
@@ -201,12 +217,7 @@ int main(int argc,char*argv[]){
|
|||||||
setdest(newsurf(screen_width, screen_height));
|
setdest(newsurf(screen_width, screen_height));
|
||||||
|
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width*screen_zoom, screen_height*screen_zoom, SDL_WINDOW_SHOWN);
|
createDisplay();
|
||||||
mini_ren = SDL_CreateRenderer(mini_win, -1, 0);
|
|
||||||
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
|
||||||
SDL_RenderSetLogicalSize(mini_ren, screen_width, screen_height);
|
|
||||||
SDL_ShowCursor(show_cursor);
|
|
||||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
|
||||||
|
|
||||||
Mix_Init(MIX_INIT_OGG);
|
Mix_Init(MIX_INIT_OGG);
|
||||||
|
|
||||||
@@ -227,6 +238,15 @@ int main(int argc,char*argv[]){
|
|||||||
while(SDL_PollEvent(&mini_eve)) {
|
while(SDL_PollEvent(&mini_eve)) {
|
||||||
if (mini_eve.type == SDL_QUIT) { should_exit=true; should_quit=true; break; }
|
if (mini_eve.type == SDL_QUIT) { should_exit=true; should_quit=true; break; }
|
||||||
if (mini_eve.type == SDL_KEYDOWN) {
|
if (mini_eve.type == SDL_KEYDOWN) {
|
||||||
|
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F2) {
|
||||||
|
screen_zoom+=2; if (screen_zoom>=10) screen_zoom=2;
|
||||||
|
destroyDisplay();
|
||||||
|
createDisplay();
|
||||||
|
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F3) {
|
||||||
|
screen_fullscreen = !screen_fullscreen;
|
||||||
|
destroyDisplay();
|
||||||
|
createDisplay();
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F1) {
|
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F1) {
|
||||||
if (lua_is_playing()) {
|
if (lua_is_playing()) {
|
||||||
@@ -274,9 +294,7 @@ int main(int argc,char*argv[]){
|
|||||||
Mix_Quit();
|
Mix_Quit();
|
||||||
|
|
||||||
for (int i=0;i<10;++i) freesurf(i);
|
for (int i=0;i<10;++i) freesurf(i);
|
||||||
SDL_DestroyTexture(mini_bak);
|
destroyDisplay();
|
||||||
SDL_DestroyRenderer(mini_ren);
|
|
||||||
SDL_DestroyWindow(mini_win);
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user