allow window to be dynamically resized
This commit is contained in:
parent
f0d8fc397f
commit
175282aac9
13 changed files with 82 additions and 33 deletions
|
@ -10,7 +10,7 @@ level=2
|
|||
alignment=chaotic
|
||||
advanceto=Troll Warrior
|
||||
cost=19
|
||||
unit_description="Trolls are strong, brutal humanoid monsters that have the amazing hability to regenerate, recovering from their wounds in the middle of battle."
|
||||
unit_description="Trolls are strong, brutal humanoid monsters that have the amazing ability to regenerate, recovering from their wounds in the middle of battle."
|
||||
usage=fighter
|
||||
[attack]
|
||||
name=club
|
||||
|
|
|
@ -11,7 +11,7 @@ alignment=chaotic
|
|||
advanceto=null
|
||||
cost=26
|
||||
usage=fighter
|
||||
unit_description="Hardened by battle, the Troll Warrior can deliver deadly blows with his mace, besides being able to regenerate its wounds during combat."
|
||||
unit_description="Hardened by battle, the Troll Warrior can deliver deadly blows with its mace, besides being able to regenerate its wounds during combat."
|
||||
[attack]
|
||||
name=mace
|
||||
type=impact
|
||||
|
|
|
@ -3,8 +3,8 @@ name=Troll Whelp
|
|||
image=troll-whelp.png
|
||||
image_defensive=troll-whelp-defend.png
|
||||
ability=regenerates
|
||||
hitpoints=36
|
||||
movement_type=smallfoot
|
||||
hitpoints=42
|
||||
movement_type=largefoot
|
||||
movement=4
|
||||
experience=25
|
||||
level=1
|
||||
|
@ -12,7 +12,7 @@ alignment=chaotic
|
|||
advanceto=Troll
|
||||
cost=12
|
||||
usage=fighter
|
||||
unit_description="Trolls are strong, brutal humanoid monsters that have the amazing hability to regenerate, recovering from their wounds in the middle of battle.
|
||||
unit_description="Trolls are strong, brutal humanoid monsters that have the amazing ability to regenerate, recovering from their wounds in the middle of battle.
|
||||
|
||||
Although this Troll is still a weak whelp, their race is known for developing amazingly fast."
|
||||
[attack]
|
||||
|
|
|
@ -328,6 +328,9 @@ void display::bounds_check_position()
|
|||
|
||||
void display::redraw_everything()
|
||||
{
|
||||
if(update_locked())
|
||||
return;
|
||||
|
||||
lastTimeOfDay_ = gamestatus::NUM_TIMES;
|
||||
sideBarBgDrawn_ = false;
|
||||
minimapDecorationsDrawn_ = false;
|
||||
|
@ -343,6 +346,11 @@ void display::draw(bool update,bool force)
|
|||
if(image != NULL) {
|
||||
|
||||
if(image->h != screen->h) {
|
||||
SDL_FreeSurface(image);
|
||||
images_.erase("misc/rightside.png");
|
||||
|
||||
image = getImage("misc/rightside.png",UNSCALED);
|
||||
|
||||
SDL_Surface* const new_image
|
||||
= scale_surface(image,image->w,screen->h);
|
||||
if(new_image != NULL) {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "menu.hpp"
|
||||
#include "playlevel.hpp"
|
||||
#include "preferences.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
|
@ -145,6 +146,8 @@ HOTKEY_COMMAND check_keys(display& disp)
|
|||
{
|
||||
const double zoom_amount = 5.0;
|
||||
|
||||
::pump_events();
|
||||
|
||||
CKey key;
|
||||
if(key[KEY_ESCAPE]) {
|
||||
const int res = gui::show_dialog(disp,NULL,"",
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
void show_intro(display& screen, config& data)
|
||||
{
|
||||
update_locker lock(screen);
|
||||
|
||||
CKey key;
|
||||
|
||||
gui::button next_button(screen,string_table["next_button"] + ">>>");
|
||||
|
@ -107,6 +109,8 @@ void show_intro(display& screen, config& data)
|
|||
|
||||
const bool left_button = mouse_flags&SDL_BUTTON_LMASK;
|
||||
|
||||
pump_events();
|
||||
|
||||
if(key[KEY_ESCAPE] ||
|
||||
skip_button.process(mousex,mousey,left_button))
|
||||
return;
|
||||
|
@ -131,6 +135,8 @@ void show_map_scene(display& screen, config& data)
|
|||
gui::draw_solid_tinted_rectangle(0,0,screen.x()-1,screen.y()-1,0,0,0,1.0,
|
||||
screen.video().getSurface());
|
||||
|
||||
update_locker lock(screen);
|
||||
|
||||
std::vector<config*>& sequence = data.children["bigmap"];
|
||||
if(sequence.empty()) {
|
||||
return;
|
||||
|
@ -220,6 +226,7 @@ void show_map_scene(display& screen, config& data)
|
|||
}
|
||||
|
||||
screen.video().update(0,0,screen.x(),screen.y());
|
||||
pump_events();
|
||||
}
|
||||
|
||||
if(!key[KEY_ESCAPE]) {
|
||||
|
@ -249,7 +256,7 @@ void show_map_scene(display& screen, config& data)
|
|||
last_state = new_state;
|
||||
|
||||
SDL_Delay(20);
|
||||
SDL_PumpEvents();
|
||||
pump_events();
|
||||
}
|
||||
|
||||
//clear the screen
|
||||
|
|
|
@ -42,7 +42,6 @@ CKey::CKey() : is_enabled(true)
|
|||
|
||||
int CKey::operator[]( int code )
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
return (code == KEY_ESCAPE || is_enabled) && int(key_list[code]);
|
||||
}
|
||||
|
||||
|
|
16
src/menu.cpp
16
src/menu.cpp
|
@ -797,7 +797,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
}
|
||||
}
|
||||
|
||||
SDL_PumpEvents();
|
||||
pump_events();
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -887,7 +887,7 @@ TITLE_RESULT show_title(display& screen)
|
|||
if(key[KEY_ESCAPE])
|
||||
return QUIT_GAME;
|
||||
|
||||
SDL_PumpEvents();
|
||||
pump_events();
|
||||
|
||||
SDL_Delay(20);
|
||||
}
|
||||
|
@ -895,16 +895,4 @@ TITLE_RESULT show_title(display& screen)
|
|||
return QUIT_GAME;
|
||||
}
|
||||
|
||||
void check_quit(display& gui)
|
||||
{
|
||||
CKey key;
|
||||
if(key[KEY_ESCAPE]) {
|
||||
const int res = gui::show_dialog(gui,NULL,"",
|
||||
string_table["quit_message"],gui::YES_NO);
|
||||
if(res == 0) {
|
||||
throw end_level_exception(QUIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //end namespace gui
|
||||
|
|
|
@ -866,5 +866,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
gui.draw();
|
||||
|
||||
game_events::pump();
|
||||
|
||||
pump_events();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,21 +93,31 @@ std::pair<int,int> resolution()
|
|||
const string_map::const_iterator y = prefs.values.find("yresolution");
|
||||
if(x != prefs.values.end() && y != prefs.values.end() &&
|
||||
x->second.empty() == false && y->second.empty() == false) {
|
||||
return std::pair<int,int>(maximum(atoi(x->second.c_str()),1024),
|
||||
maximum(atoi(y->second.c_str()),768));
|
||||
std::pair<int,int> res (maximum(atoi(x->second.c_str()),1024),
|
||||
maximum(atoi(y->second.c_str()),768));
|
||||
res.first &= ~1;
|
||||
res.second &= ~1;
|
||||
return res;
|
||||
} else {
|
||||
return std::pair<int,int>(1024,768);
|
||||
}
|
||||
}
|
||||
|
||||
void set_resolution(const std::pair<int,int>& res)
|
||||
void set_resolution(const std::pair<int,int>& resolution)
|
||||
{
|
||||
if(disp != NULL) {
|
||||
std::pair<int,int> res = resolution;
|
||||
|
||||
//dimensions must be even
|
||||
res.first &= ~1;
|
||||
res.second &= ~1;
|
||||
|
||||
CVideo& video = disp->video();
|
||||
const int flags = video.isFullScreen() ? FULL_SCREEN : 0;
|
||||
if(video.modePossible(res.first,res.second,16,flags)) {
|
||||
|
||||
video.setMode(res.first,res.second,16,flags);
|
||||
|
||||
disp->redraw_everything();
|
||||
|
||||
char buf[50];
|
||||
|
@ -347,7 +357,7 @@ void show_preferences_dialog(display& disp)
|
|||
disp.update_display();
|
||||
|
||||
SDL_Delay(10);
|
||||
SDL_PumpEvents();
|
||||
pump_events();
|
||||
}
|
||||
|
||||
disp.invalidate_all();
|
||||
|
|
|
@ -26,9 +26,12 @@ team::team_info::team_info(config& cfg)
|
|||
{
|
||||
gold = cfg.values["gold"];
|
||||
name = cfg.values["name"];
|
||||
aggression = atof(cfg.values["aggression"].c_str());
|
||||
if(aggression == 0.0)
|
||||
|
||||
const std::string& aggression_val = cfg.values["aggression"];
|
||||
if(aggression_val.empty())
|
||||
aggression = 0.5;
|
||||
else
|
||||
aggression = atof(aggression_val.c_str());
|
||||
|
||||
const std::string& enemies_list = cfg.values["enemy"];
|
||||
if(!enemies_list.empty()) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "preferences.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
#define TEST_VIDEO_ON 0
|
||||
|
@ -60,6 +61,14 @@ int main( int argc, char** argv )
|
|||
|
||||
namespace {
|
||||
bool fullScreen = false;
|
||||
|
||||
unsigned int get_flags(unsigned int flags)
|
||||
{
|
||||
if((flags&SDL_FULLSCREEN) == 0)
|
||||
flags |= SDL_RESIZABLE;
|
||||
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
|
||||
CVideo::CVideo(const char* text) : frameBuffer(NULL), backBuffer(NULL)
|
||||
|
@ -100,11 +109,12 @@ CVideo::~CVideo()
|
|||
|
||||
int CVideo::modePossible( int x, int y, int bits_per_pixel, int flags )
|
||||
{
|
||||
return SDL_VideoModeOK( x, y, bits_per_pixel, flags );
|
||||
return SDL_VideoModeOK( x, y, bits_per_pixel, get_flags(flags) );
|
||||
}
|
||||
|
||||
int CVideo::setMode( int x, int y, int bits_per_pixel, int flags )
|
||||
{
|
||||
flags = get_flags(flags);
|
||||
const int res = SDL_VideoModeOK( x, y, bits_per_pixel, flags );
|
||||
|
||||
if( res == 0 )
|
||||
|
@ -260,12 +270,12 @@ void CVideo::update( int x, int y, int w, int h )
|
|||
if( y+h > frameBuffer->h )
|
||||
h = frameBuffer->h - y;
|
||||
|
||||
SRectangle rect = {x,y,w,h};
|
||||
SDL_Rect rect = {x,y,w,h};
|
||||
SDL_BlitSurface( backBuffer, &rect, frameBuffer, &rect );
|
||||
SDL_UpdateRect( frameBuffer, x, y, w, h );
|
||||
}
|
||||
|
||||
void CVideo::update( SRectangle* rect )
|
||||
void CVideo::update( SDL_Rect* rect )
|
||||
{
|
||||
SDL_BlitSurface( backBuffer, rect, frameBuffer, rect );
|
||||
SDL_UpdateRect( frameBuffer, rect->x, rect->y, rect->w, rect->h );
|
||||
|
@ -326,3 +336,22 @@ int CVideo::drawText(int x, int y, int pixel, int bg, const char* text, int sz)
|
|||
}
|
||||
|
||||
bool CVideo::isFullScreen() const { return fullScreen; }
|
||||
|
||||
void pump_events()
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_VIDEORESIZE: {
|
||||
const SDL_ResizeEvent* const resize
|
||||
= reinterpret_cast<SDL_ResizeEvent*>(&event);
|
||||
size_t newx = resize->w > 1024 ? resize->w : 1024;
|
||||
size_t newy = resize->h > 768 ? resize->h : 768;
|
||||
|
||||
preferences::set_resolution(std::pair<int,int>(newx,newy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
#define VIDEO_MEMORY SDL_HWSURFACE
|
||||
#define SYSTEM_MEMORY SDL_SWSURFACE
|
||||
|
||||
typedef SDL_Rect SRectangle;
|
||||
|
||||
class CVideo {
|
||||
public:
|
||||
CVideo(const char* text);
|
||||
|
@ -49,7 +47,7 @@ class CVideo {
|
|||
void setPixel( int x, int y, int pixel );
|
||||
int convertColour(int r, int g, int b);
|
||||
void update( int x, int y, int w, int h );
|
||||
void update( SRectangle* area );
|
||||
void update( SDL_Rect* area );
|
||||
|
||||
SDL_Surface* getSurface( void );
|
||||
|
||||
|
@ -68,4 +66,6 @@ class CVideo {
|
|||
char text_[256*8];
|
||||
};
|
||||
|
||||
void pump_events();
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue