Skip to content

Commit

Permalink
add transitions between screens
Browse files Browse the repository at this point in the history
they are horizonal scroll, wipe, bar wipe, and bar scroll

for #21

refactor actions of user interface

and modify blacktooth-frame of present set
  • Loading branch information
dougmencken committed Feb 26, 2018
1 parent ec599d2 commit b896595
Show file tree
Hide file tree
Showing 42 changed files with 299 additions and 240 deletions.
Binary file modified gamedata/gfx/gui.gfx/blacktooth-frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ bool Camera::centerOn( PlayerItem* player )
else if ( offsetX > 0 && player->getX() <= maxX && player->getX() >= minX )
{
// Si no se han alcanzado los límites de la sala el desplazamiento al sur es posible
if ( delta.first <= ( room->getPicture()->w - ScreenWidth ) && delta.second <= ( room->getPicture()->h - ScreenHeight ) )
if ( delta.first <= ( room->getPicture()->w - static_cast< int >( ScreenWidth ) ) &&
delta.second <= ( room->getPicture()->h - static_cast< int >( ScreenHeight ) ) )
{
delta.first += ( offsetX << 1 );
delta.second += offsetX;
Expand All @@ -198,7 +199,7 @@ bool Camera::centerOn( PlayerItem* player )
if ( offsetY < 0 && player->getY() <= maxY - 1 && player->getY() >= minY - 1 )
{
// Si no se han alcanzado los límites de la sala el desplazamiento al este es posible
if ( delta.first <= room->getPicture()->w - ScreenWidth && delta.second >= 0 )
if ( delta.first <= room->getPicture()->w - static_cast< int >( ScreenWidth ) && delta.second >= 0 )
{
delta.first -= ( offsetY << 1 );
delta.second += offsetY;
Expand All @@ -209,7 +210,7 @@ bool Camera::centerOn( PlayerItem* player )
else if ( offsetY > 0 && player->getY() <= maxY && player->getY() >= minY )
{
// Si no se han alcanzado los límites de la sala el desplazamiento al oeste es posible
if ( delta.first >= 0 && delta.second <= room->getPicture()->h - ScreenHeight )
if ( delta.first >= 0 && delta.second <= room->getPicture()->h - static_cast< int >( ScreenHeight ) )
{
delta.first -= ( offsetY << 1 );
delta.second += offsetY;
Expand All @@ -219,7 +220,7 @@ bool Camera::centerOn( PlayerItem* player )
}
}

// Actualización del punto de referencia
// refresh point of reference
reference.first = player->getX();
reference.second = player->getY();

Expand Down
4 changes: 2 additions & 2 deletions src/Ism.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ namespace isomot
Mistake /* Estado imposible, se utiliza en el gestor de sonido */
} ;

const int ScreenWidth = 640 ;
const unsigned int ScreenWidth = 640 ;

const int ScreenHeight = 480 ;
const unsigned int ScreenHeight = 480 ;

const int Top = -1 ;

Expand Down
16 changes: 10 additions & 6 deletions src/gui/GuiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ void GuiManager::begin ()
}
}

void GuiManager::changeScreen( Screen* newScreen )
void GuiManager::changeScreen( Screen* newScreen, bool dive )
{
assert( newScreen );
if ( newScreen == 0 ) return ;

# if defined( DEBUG_GUI ) && DEBUG_GUI

Expand Down Expand Up @@ -183,6 +183,7 @@ void GuiManager::changeScreen( Screen* newScreen )

if ( listOfScreens.find( newScreen->getActionOfScreen()->getNameOfAction() ) != listOfScreens.end () )
{
Screen::barWipeHorizontally( this->screen, newScreen, dive );
this->screen = newScreen;
redraw() ;
}
Expand All @@ -193,10 +194,13 @@ void GuiManager::changeScreen( Screen* newScreen )
}
}

Screen * GuiManager::findOrCreateScreenForAction ( Action* action, BITMAP* picture )
Screen * GuiManager::findOrCreateScreenForAction ( Action* action )
{
assert( action );
assert( picture );
if ( action == 0 )
{
std::cerr << "screen for nil action is nil screen" << std::endl ;
return 0 ;
}

std::string nameOfAction = action->getNameOfAction() ;

Expand All @@ -208,7 +212,7 @@ Screen * GuiManager::findOrCreateScreenForAction ( Action* action, BITMAP* pictu
}

std::cout << "going to create new screen for action \" " << nameOfAction << " \"" << std::endl ;
Screen * newScreen = new Screen( picture, action );
Screen * newScreen = new Screen( action );
listOfScreens[ nameOfAction ] = newScreen;
return newScreen;
}
Expand Down
9 changes: 3 additions & 6 deletions src/gui/GuiManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ class GuiManager
*/
void begin () ;

/**
* Change the current screen
*/
void changeScreen ( Screen* newScreen ) ;
void changeScreen ( Screen* newScreen, bool dive ) ;

/*
* Search in list of screens for the one associated with this action
* When there's no such screen found, create a new one with a given picture
* When theres no such screen found, create a new one
*/
Screen * findOrCreateScreenForAction ( Action * action, BITMAP * picture ) ;
Screen * findOrCreateScreenForAction ( Action * action ) ;

void freeScreens () ;

Expand Down
165 changes: 156 additions & 9 deletions src/gui/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@ namespace gui
}


Screen::Screen( BITMAP* picture, Action* action ) :
Screen::Screen( Action* action ) :
Widget( 0, 0 ),
backgroundColor( Color::redColor() ),
where( picture ),
imageOfScreen( 0 ),
actionOfScreen( action ),
escapeAction( 0 ),
keyHandler( 0 ),
pictureOfHead( 0 ),
pictureOfHeels( 0 )
{
refreshPicturesOfHeadAndHeels ();
if ( action != 0 && action->getWhereToDraw() != 0 )
{
imageOfScreen = action->getWhereToDraw ();
refreshPicturesOfHeadAndHeels ();
}
}

Screen::~Screen( )
{
freeWidgets() ;
delete backgroundColor ;
}

void Screen::setEscapeAction ( Action * action )
Expand Down Expand Up @@ -108,20 +110,33 @@ void Screen::refreshPicturesOfHeadAndHeels ()

void Screen::draw( BITMAP* where )
{
this->imageOfScreen = where ;

redraw();
drawOnGlobalScreen( );
}

void Screen::redraw( )
{
if ( imageOfScreen == 0 ) return ;

// fill with color of background
clear_to_color( where, backgroundColor->toAllegroColor() );
clear_to_color( imageOfScreen, Color::redColor()->toAllegroColor() );

// draw background, if any
if ( Screen::backgroundPicture != 0 )
{
blit( backgroundPicture, where, 0, 0, 0, 0, backgroundPicture->w, backgroundPicture->h );
blit( backgroundPicture, imageOfScreen, 0, 0, 0, 0, backgroundPicture->w, backgroundPicture->h );
}

// draw each component
std::for_each( widgets.begin (), widgets.end (), std::bind2nd( std::mem_fun( &Widget::draw ), where ) );
std::for_each( widgets.begin (), widgets.end (), std::bind2nd( std::mem_fun( &Widget::draw ), imageOfScreen ) );
}

void Screen::drawOnGlobalScreen( )
{
// copy resulting image to screen
blit( where, screen, 0, 0, 0, 0, where->w, where->h );
blit( imageOfScreen, /* allegro global variable */ screen, 0, 0, 0, 0, imageOfScreen->w, imageOfScreen->h );
}

void Screen::handleKey( int rawKey )
Expand Down Expand Up @@ -310,4 +325,136 @@ std::vector< BITMAP * > Screen::loadAnimation ( const char * nameOfGif )
return animation;
}

/* static */
void Screen::scrollHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft )
{
if ( oldScreen == 0 || newScreen == 0 ||
oldScreen == newScreen ||
oldScreen->imageOfScreen == 0 || newScreen->imageOfScreen == 0 ) return ;

BITMAP * oldPicture = create_bitmap( oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h );
blit( oldScreen->imageOfScreen, oldPicture, 0, 0, 0, 0, oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h );

newScreen->redraw ();
BITMAP * newPicture = newScreen->imageOfScreen ;

unsigned int step = 2;
for ( unsigned int x = step ; x < isomot::ScreenWidth ; x += step )
{
/* void blit( BITMAP* from, BITMAP* to, int fromX, int fromY, int toX, int toY, int width, int height ) */

if ( rightToLeft )
{
blit( oldPicture, screen, x, 0, 0, 0, oldPicture->w - x, isomot::ScreenHeight );
blit( newPicture, screen, 0, 0, oldPicture->w - x, 0, x, isomot::ScreenHeight );
}
else
{
blit( newPicture, screen, newPicture->w - x, 0, 0, 0, x, isomot::ScreenHeight );
blit( oldPicture, screen, 0, 0, x, 0, newPicture->w - x, isomot::ScreenHeight );
}

sleep( 1 );
}

destroy_bitmap( oldPicture );
}

/* static */
void Screen::wipeHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft )
{
if ( oldScreen == 0 || newScreen == 0 ||
oldScreen == newScreen || newScreen->imageOfScreen == 0 ) return ;

newScreen->redraw ();
BITMAP * newPicture = newScreen->imageOfScreen ;

unsigned int step = 2;
for ( unsigned int x = step ; x < isomot::ScreenWidth ; x += step )
{
/* void blit( BITMAP* from, BITMAP* to, int fromX, int fromY, int toX, int toY, int width, int height ) */

if ( rightToLeft )
{
blit( newPicture, screen, newPicture->w - x, 0, newPicture->w - x, 0, x, isomot::ScreenHeight );
}
else
{
blit( newPicture, screen, 0, 0, 0, 0, x, isomot::ScreenHeight );
}

sleep( 1 );
}
}

/* static */
void Screen::barScrollHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft )
{
if ( oldScreen == 0 || newScreen == 0 ||
oldScreen == newScreen ||
oldScreen->imageOfScreen == 0 || newScreen->imageOfScreen == 0 ) return ;

BITMAP * oldPicture = create_bitmap( oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h );
blit( oldScreen->imageOfScreen, oldPicture, 0, 0, 0, 0, oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h );

newScreen->redraw ();
BITMAP * newPicture = newScreen->imageOfScreen ;

unsigned int pieces = isomot::ScreenWidth >> 6 ;
unsigned int widthOfPiece = isomot::ScreenWidth / pieces ;

unsigned int step = 1;
for ( unsigned int x = step ; x < widthOfPiece ; x += step )
{
for ( unsigned int pieceX = 0 ; pieceX < isomot::ScreenWidth ; pieceX += widthOfPiece )
{
if ( rightToLeft )
{
blit( oldPicture, screen, pieceX + x, 0, pieceX, 0, widthOfPiece - x, isomot::ScreenHeight );
blit( newPicture, screen, pieceX, 0, pieceX + widthOfPiece - x, 0, x, isomot::ScreenHeight );
}
else
{
blit( newPicture, screen, pieceX + widthOfPiece - x, 0, pieceX, 0, x, isomot::ScreenHeight );
blit( oldPicture, screen, pieceX, 0, pieceX + x, 0, widthOfPiece - x, isomot::ScreenHeight );
}
}

sleep( 4 );
}

destroy_bitmap( oldPicture );
}

/* static */
void Screen::barWipeHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft )
{
if ( oldScreen == 0 || newScreen == 0 ||
oldScreen == newScreen || newScreen->imageOfScreen == 0 ) return ;

newScreen->redraw ();
BITMAP * newPicture = newScreen->imageOfScreen ;

unsigned int pieces = isomot::ScreenWidth >> 6 ;
unsigned int widthOfPiece = isomot::ScreenWidth / pieces ;

unsigned int step = 1;
for ( unsigned int x = step ; x < widthOfPiece ; x += step )
{
for ( unsigned int pieceX = 0 ; pieceX < isomot::ScreenWidth ; pieceX += widthOfPiece )
{
if ( rightToLeft )
{
blit( newPicture, screen, pieceX + widthOfPiece - x, 0, pieceX + widthOfPiece - x, 0, x, isomot::ScreenHeight );
}
else
{
blit( newPicture, screen, pieceX, 0, pieceX, 0, x, isomot::ScreenHeight );
}
}

sleep( 4 );
}
}

}
33 changes: 19 additions & 14 deletions src/gui/Screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ class Screen : public Widget

/**
* Constructor
* @param picture Where to draw this screen
* @param action Action for which this screen is created
*/
Screen( BITMAP * picture, Action * action ) ;
Screen( Action * action ) ;

virtual ~Screen( ) ;

/**
* Dibuja todo el contenido de la pantalla
* @param where Imagen donde será dibujada
* Draw parts of screen
*/
void draw ( BITMAP* where ) ;

/**
* Responde a la pulsación de una tecla
*/
void redraw () ;

void drawOnGlobalScreen () ;

void handleKey ( int key ) ;

void addWidget ( Widget* widget ) ;
Expand All @@ -68,21 +67,29 @@ class Screen : public Widget

void placeHeadAndHeels ( bool imagesToo, bool copyrightsToo ) ;

static void refreshBackground () ;

static BITMAP * loadPicture ( const char * nameOfPicture ) ;

static std::vector < BITMAP * > loadAnimation ( const char * nameOfGif ) ;

private:
static void scrollHorizontally ( Screen * oldScreen, Screen * newScreen, bool rightToLeft ) ;

Color * backgroundColor ;
static void wipeHorizontally ( Screen * oldScreen, Screen * newScreen, bool rightToLeft ) ;

static void barScrollHorizontally ( Screen * oldScreen, Screen * newScreen, bool rightToLeft ) ;

static void barWipeHorizontally ( Screen * oldScreen, Screen * newScreen, bool rightToLeft ) ;

private:

/**
* Imagen donde se volcarán la pantalla
* Image of this screen
*/
BITMAP * where ;
BITMAP * imageOfScreen ;

/**
* Elementos de la interfaz de usuario contenidos en la pantalla
* Elements of interface to draw on screen
*/
std::list < Widget * > widgets ;

Expand All @@ -105,8 +112,6 @@ class Screen : public Widget

public:

static void refreshBackground () ;

void refreshPicturesOfHeadAndHeels () ;

Action * getActionOfScreen () const { return actionOfScreen ; }
Expand Down
Loading

0 comments on commit b896595

Please sign in to comment.