1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

WIP: add landscape support

This commit is contained in:
Mathieu Schroeter 2017-10-06 18:23:07 +02:00
parent d47108c3aa
commit fd43a6ef01
8 changed files with 65 additions and 40 deletions

View File

@ -192,8 +192,8 @@ UpdateFrame (void)
rcRect.left = 0; rcRect.left = 0;
rcRect.top = 0; rcRect.top = 0;
rcRect.right = LXIMAGE; rcRect.right = LXLOGIC;
rcRect.bottom = LYIMAGE; rcRect.bottom = LYLOGIC;
g_pPixmap->DrawImage (-1, CHBACK, rcRect); // draw the background g_pPixmap->DrawImage (-1, CHBACK, rcRect); // draw the background
if (phase == EV_PHASE_INTRO1) if (phase == EV_PHASE_INTRO1)
@ -724,8 +724,8 @@ DoInit (int argc, char * argv[], bool & exit)
} }
OutputDebug ("Image: init\n"); OutputDebug ("Image: init\n");
totalDim.x = LXIMAGE; totalDim.x = LXLOGIC;
totalDim.y = LYIMAGE; totalDim.y = LYLOGIC;
iconDim.x = 0; iconDim.x = 0;
iconDim.y = 0; iconDim.y = 0;
#if _INTRO #if _INTRO
@ -736,8 +736,8 @@ DoInit (int argc, char * argv[], bool & exit)
return EXIT_FAILURE; return EXIT_FAILURE;
OutputDebug ("Image: init\n"); OutputDebug ("Image: init\n");
totalDim.x = LXIMAGE; totalDim.x = LXLOGIC;
totalDim.y = LYIMAGE; totalDim.y = LYLOGIC;
iconDim.x = 0; iconDim.x = 0;
iconDim.y = 0; iconDim.y = 0;
if (!g_pPixmap->Cache (CHGROUND, "image/init.png", totalDim, iconDim)) if (!g_pPixmap->Cache (CHGROUND, "image/init.png", totalDim, iconDim))
@ -745,8 +745,8 @@ DoInit (int argc, char * argv[], bool & exit)
rcRect.left = 0; rcRect.left = 0;
rcRect.top = 0; rcRect.top = 0;
rcRect.right = LXIMAGE; rcRect.right = LXLOGIC;
rcRect.bottom = LYIMAGE; rcRect.bottom = LYLOGIC;
g_pPixmap->DrawImage (-1, CHBACK, rcRect); // dessine le fond g_pPixmap->DrawImage (-1, CHBACK, rcRect); // dessine le fond
g_pPixmap->Display (); g_pPixmap->Display ();

View File

@ -26,12 +26,15 @@
#include "config.h" #include "config.h"
class CEvent;
extern SDL_Window * g_window; extern SDL_Window * g_window;
extern SDL_Renderer * g_renderer; extern SDL_Renderer * g_renderer;
extern bool g_bFullScreen; extern bool g_bFullScreen;
extern bool g_restoreBugs; extern bool g_restoreBugs;
extern bool g_enableRecorder; extern bool g_enableRecorder;
extern std::string g_playRecord; extern std::string g_playRecord;
extern CEvent * g_pEvent;
struct Point { struct Point {
Sint32 x; Sint32 x;

View File

@ -25,13 +25,16 @@
// clang-format off // clang-format off
#define _INTRO true // true for init screen #define _INTRO true // true for init screen
#define SCRFACTOR 4 / 3 #define SCRFACTOR 16 / 9
#define LXIMAGE (480 * SCRFACTOR + (480 * SCRFACTOR) % 2) // window size #define LXLOGIC 640
#define LYIMAGE 480 #define LYLOGIC 480
#define LXIMAGE (LYLOGIC * SCRFACTOR + (LYLOGIC * SCRFACTOR) % 2) // window size
#define LYIMAGE LYLOGIC
#define LXOFFSET ((LXIMAGE - LXLOGIC) / 2)
#define POSDRAWX 144 // draw surface #define POSDRAWX 144 // draw surface
#define POSDRAWY 15 #define POSDRAWY 15
#define DIMDRAWX (LXIMAGE - (640 - 480)) #define DIMDRAWX (LXIMAGE - (LXLOGIC - LYLOGIC))
#define DIMDRAWY 450 #define DIMDRAWY 450
#define POSMAPX 8 // map surface #define POSMAPX 8 // map surface

View File

@ -1876,7 +1876,7 @@ CEvent::SetMenu (Sint32 button, Sint32 menu)
// Crée tous les boutons nécessaires à la phase en cours. // Crée tous les boutons nécessaires à la phase en cours.
bool bool
CEvent::CreateButtons () CEvent::CreateButtons (Sint32 phase)
{ {
Sint32 i = 0, message; Sint32 i = 0, message;
Point pos; Point pos;
@ -1890,6 +1890,9 @@ CEvent::CreateButtons ()
pos.y = table[m_index].buttons[i].y; pos.y = table[m_index].buttons[i].y;
message = table[m_index].buttons[i].message; message = table[m_index].buttons[i].message;
if (phase != EV_PHASE_PLAY && phase != EV_PHASE_BUILD)
pos.x += LXOFFSET;
if (m_bPrivate) if (m_bPrivate)
{ {
if (message == EV_PHASE_SKILL1) if (message == EV_PHASE_SKILL1)
@ -2004,7 +2007,7 @@ CEvent::DrawButtons ()
if (!this->m_updateVersion.empty () && this->m_updateBlinking++ % 80 < 40) if (!this->m_updateVersion.empty () && this->m_updateBlinking++ % 80 < 40)
{ {
pos.x = 70; pos.x = 70 + LXOFFSET;
pos.y = 465; pos.y = 465;
snprintf ( snprintf (
res, sizeof (res), res, sizeof (res),
@ -2218,7 +2221,7 @@ CEvent::DrawButtons ()
else else
snprintf (res, sizeof (res), "%s", gettext ("Save this game")); snprintf (res, sizeof (res), "%s", gettext ("Save this game"));
pos.x = 420; pos.x = 420 + LXOFFSET;
pos.y = 8; pos.y = 8;
DrawText (m_pPixmap, pos, res); DrawText (m_pPixmap, pos, res);
@ -2229,11 +2232,11 @@ CEvent::DrawButtons ()
snprintf (text, sizeof (text), "%d", i + 1); snprintf (text, sizeof (text), "%d", i + 1);
lg = GetTextWidth (text); lg = GetTextWidth (text);
pos.x = (420 + 460) / 2 - lg / 2; pos.x = (420 + 460) / 2 - lg / 2 + LXOFFSET;
pos.y = 30 + 12 + 42 * i; pos.y = 30 + 12 + 42 * i;
DrawText (m_pPixmap, pos, text, FONTSLIM); DrawText (m_pPixmap, pos, text, FONTSLIM);
pos.x = 420 + 50; pos.x = 420 + 50 + LXOFFSET;
if (world >= 0) if (world >= 0)
{ {
@ -2264,14 +2267,14 @@ CEvent::DrawButtons ()
DrawTextCenter (gettext ("Ending conditions"), (10 + 134) / 2, 20); DrawTextCenter (gettext ("Ending conditions"), (10 + 134) / 2, 20);
pos.x = 170 + 42 * 2 + 4; pos.x = 170 + 42 * 2 + 4 + LXOFFSET;
pos.y = 30 + 12 + 42 * 4; pos.y = 30 + 12 + 42 * 4;
snprintf ( snprintf (
text, sizeof (text), gettext ("Lost if less than %d Blupi"), text, sizeof (text), gettext ("Lost if less than %d Blupi"),
pTerm->nbMinBlupi); pTerm->nbMinBlupi);
DrawText (m_pPixmap, pos, text); DrawText (m_pPixmap, pos, text);
pos.x = 170 + 42 * 2 + 4; pos.x = 170 + 42 * 2 + 4 + LXOFFSET;
pos.y = 30 + 12 + 42 * 5; pos.y = 30 + 12 + 42 * 5;
snprintf ( snprintf (
text, sizeof (text), gettext ("Impossible to win if less than %d Blupi"), text, sizeof (text), gettext ("Impossible to win if less than %d Blupi"),
@ -2303,7 +2306,7 @@ CEvent::DrawButtons ()
snprintf (res, sizeof (res), "%s", gettext ("Construction number")); snprintf (res, sizeof (res), "%s", gettext ("Construction number"));
lg = GetTextWidth (res); lg = GetTextWidth (res);
pos.x = (140 + 270) / 2 - lg / 2; pos.x = (140 + 270) / 2 - lg / 2 + LXOFFSET;
pos.y = 70; pos.y = 70;
if (m_bSchool) if (m_bSchool)
pos.x -= 40; pos.x -= 40;
@ -2319,7 +2322,7 @@ CEvent::DrawButtons ()
{ {
char * text = gettext ("Game paused"); char * text = gettext ("Game paused");
lg = GetTextWidth (text); lg = GetTextWidth (text);
pos.x = (140 + 270) / 2 - lg / 2; pos.x = (140 + 270) / 2 - lg / 2 + LXOFFSET;
pos.y = 70; pos.y = 70;
if (m_bSchool) if (m_bSchool)
pos.x -= 40; pos.x -= 40;
@ -2335,7 +2338,7 @@ CEvent::DrawButtons ()
{ {
char * text = gettext ("Help number"); char * text = gettext ("Help number");
lg = GetTextWidth (text); lg = GetTextWidth (text);
pos.x = (140 + 270) / 2 - lg / 2; pos.x = (140 + 270) / 2 - lg / 2 + LXOFFSET;
pos.y = 70; pos.y = 70;
if (m_bSchool) if (m_bSchool)
pos.x -= 40; pos.x -= 40;
@ -2359,7 +2362,7 @@ CEvent::DrawButtons ()
world = m_private; world = m_private;
lg = GetBignumWidth (world + 1); lg = GetBignumWidth (world + 1);
pos.x = (140 + 270) / 2 - lg / 2; pos.x = (140 + 270) / 2 - lg / 2 + LXOFFSET;
pos.y = 100; pos.y = 100;
if (m_bSchool) if (m_bSchool)
pos.x -= 40; pos.x -= 40;
@ -2387,6 +2390,7 @@ CEvent::DrawButtons ()
pos.x = 150 + 50; pos.x = 150 + 50;
pos.y = 230 + 13; pos.y = 230 + 13;
} }
pos.x += LXOFFSET;
DrawText (m_pPixmap, pos, gettext ("Easy"), FONTSLIM); DrawText (m_pPixmap, pos, gettext ("Easy"), FONTSLIM);
} }
@ -2402,6 +2406,7 @@ CEvent::DrawButtons ()
pos.x = 150 + 50; pos.x = 150 + 50;
pos.y = 230 + 42 + 13; pos.y = 230 + 42 + 13;
} }
pos.x += LXOFFSET;
DrawText (m_pPixmap, pos, gettext ("Difficult"), FONTSLIM); DrawText (m_pPixmap, pos, gettext ("Difficult"), FONTSLIM);
} }
} }
@ -2426,6 +2431,7 @@ CEvent::DrawButtons ()
pente = 0; pente = 0;
else else
pente = 19; pente = 19;
pos.x += LXOFFSET;
DrawTextRect (m_pPixmap, pos, m_libelle, pente, FONTSLIM); DrawTextRect (m_pPixmap, pos, m_libelle, pente, FONTSLIM);
} }
@ -2440,7 +2446,7 @@ CEvent::DrawButtons ()
gettext ("No, not that way !"), gettext ("No, not that way !"),
}; };
pos.x = 60; pos.x = 60 + LXOFFSET;
pos.y = 443; pos.y = 443;
DrawText (m_pPixmap, pos, list[GetWorld () % 5]); DrawText (m_pPixmap, pos, list[GetWorld () % 5]);
} }
@ -2454,7 +2460,7 @@ CEvent::DrawButtons ()
gettext ("Mission over..."), gettext ("Mission over..."),
}; };
pos.x = 60; pos.x = 60 + LXOFFSET;
pos.y = 443; pos.y = 443;
DrawText (m_pPixmap, pos, list[GetWorld () % 5]); DrawText (m_pPixmap, pos, list[GetWorld () % 5]);
} }
@ -2471,7 +2477,7 @@ CEvent::DrawButtons ()
if (m_bPrivate) if (m_bPrivate)
text = gettext ("Last construction resolved !"); text = gettext ("Last construction resolved !");
pos.x = 60; pos.x = 60 + LXOFFSET;
pos.y = 443; pos.y = 443;
DrawText (m_pPixmap, pos, text); DrawText (m_pPixmap, pos, text);
} }
@ -2487,19 +2493,19 @@ CEvent::DrawButtons ()
snprintf (res, sizeof (res), "x%d", m_speed); snprintf (res, sizeof (res), "x%d", m_speed);
lg = GetTextWidth (res); lg = GetTextWidth (res);
pos.x = (54 + 40) - lg / 2; pos.x = (54 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, res); DrawText (m_pPixmap, pos, res);
snprintf (res, sizeof (res), "%d", m_pSound->GetAudioVolume ()); snprintf (res, sizeof (res), "%d", m_pSound->GetAudioVolume ());
lg = GetTextWidth (res); lg = GetTextWidth (res);
pos.x = (284 + 40) - lg / 2; pos.x = (284 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, res); DrawText (m_pPixmap, pos, res);
snprintf (res, sizeof (res), "%d", m_pSound->GetMidiVolume ()); snprintf (res, sizeof (res), "%d", m_pSound->GetMidiVolume ());
lg = GetTextWidth (res); lg = GetTextWidth (res);
pos.x = (399 + 40) - lg / 2; pos.x = (399 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, res); DrawText (m_pPixmap, pos, res);
@ -2507,7 +2513,7 @@ CEvent::DrawButtons ()
if (m_pMovie->GetEnable () && m_bMovie) if (m_pMovie->GetEnable () && m_bMovie)
text = gettext ("Yes"); text = gettext ("Yes");
lg = GetTextWidth (text); lg = GetTextWidth (text);
pos.x = (514 + 40) - lg / 2; pos.x = (514 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, text); DrawText (m_pPixmap, pos, text);
@ -2516,7 +2522,7 @@ CEvent::DrawButtons ()
else else
snprintf (res, sizeof (res), "%d", m_scrollSpeed); snprintf (res, sizeof (res), "%d", m_scrollSpeed);
lg = GetTextWidth (res); lg = GetTextWidth (res);
pos.x = (169 + 40) - lg / 2; pos.x = (169 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, res); DrawText (m_pPixmap, pos, res);
} }
@ -2542,14 +2548,14 @@ CEvent::DrawButtons ()
lang = "Italiano"; lang = "Italiano";
lg = GetTextWidth (lang.c_str ()); lg = GetTextWidth (lang.c_str ());
pos.x = (54 + 40) - lg / 2; pos.x = (54 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, lang.c_str ()); DrawText (m_pPixmap, pos, lang.c_str ());
const char * text = const char * text =
m_bFullScreen ? gettext ("Fullscreen") : gettext ("Windowed"); m_bFullScreen ? gettext ("Fullscreen") : gettext ("Windowed");
lg = GetTextWidth (text); lg = GetTextWidth (text);
pos.x = (169 + 40) - lg / 2; pos.x = (169 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, text); DrawText (m_pPixmap, pos, text);
@ -2557,7 +2563,7 @@ CEvent::DrawButtons ()
{ {
snprintf (res, sizeof (res), "%dx", m_WindowScale); snprintf (res, sizeof (res), "%dx", m_WindowScale);
lg = GetTextWidth (res); lg = GetTextWidth (res);
pos.x = (284 + 40) - lg / 2; pos.x = (284 + 40) - lg / 2 + LXOFFSET;
pos.y = 330 - 20; pos.y = 330 - 20;
DrawText (m_pPixmap, pos, res); DrawText (m_pPixmap, pos, res);
} }
@ -2599,7 +2605,7 @@ CEvent::DrawButtons ()
for (size_t i = 0; i < countof (libs); ++i) for (size_t i = 0; i < countof (libs); ++i)
{ {
pos.x = 30; pos.x = 30 + LXOFFSET;
pos.y = 120 + i * 20; pos.y = 120 + i * 20;
DrawText (m_pPixmap, pos, libs[i].c_str ()); DrawText (m_pPixmap, pos, libs[i].c_str ());
} }
@ -3171,7 +3177,7 @@ CEvent::ChangePhase (Uint32 phase)
m_jauges[0].SetHide (true); // cache les jauges m_jauges[0].SetHide (true); // cache les jauges
m_jauges[1].SetHide (true); m_jauges[1].SetHide (true);
CreateButtons (); // crée les boutons selon la phase CreateButtons (phase); // crée les boutons selon la phase
m_bMenu = false; m_bMenu = false;
m_pDecor->HideTooltips (false); m_pDecor->HideTooltips (false);
m_menu.Delete (); m_menu.Delete ();

View File

@ -24,7 +24,6 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "blupi.h"
#include "button.h" #include "button.h"
#include "menu.h" #include "menu.h"
#include "progress.h" #include "progress.h"
@ -148,7 +147,7 @@ public:
protected: protected:
void DrawTextCenter (const char * text, Sint32 x, Sint32 y, Sint32 font = 0); void DrawTextCenter (const char * text, Sint32 x, Sint32 y, Sint32 font = 0);
bool CreateButtons (); bool CreateButtons (Sint32 phase);
bool EventButtons (const SDL_Event & event, Point pos); bool EventButtons (const SDL_Event & event, Point pos);
bool MouseOnButton (Point pos); bool MouseOnButton (Point pos);
Sint32 SearchPhase (Uint32 phase); Sint32 SearchPhase (Uint32 phase);

View File

@ -497,8 +497,16 @@ CPixmap::DrawImage (Sint32 chDst, size_t channel, Rect rect)
if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ())
return false; return false;
dst.x = rect.left; if (channel == CHBACK)
dst.y = rect.top; {
dst.x = (LXIMAGE - LXLOGIC) / 2;
dst.y = (LYIMAGE - LYLOGIC) / 2;
}
else
{
dst.x = rect.left;
dst.y = rect.top;
}
res = BltFast (chDst, channel, dst, rect); res = BltFast (chDst, channel, dst, rect);

View File

@ -20,6 +20,8 @@
#pragma once #pragma once
#include "blupi.h"
class CPixmap; class CPixmap;
class CDecor; class CDecor;
class CSound; class CSound;

View File

@ -21,7 +21,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "blupi.h"
#include "def.h" #include "def.h"
#include "event.h"
#include "pixmap.h" #include "pixmap.h"
#include "text.h" #include "text.h"
@ -122,6 +124,8 @@ DrawText (CPixmap * pPixmap, Point pos, const char * pText, Sint32 font)
{ {
Sint32 rank; Sint32 rank;
auto phase = g_pEvent->GetPhase ();
while (*pText != '\0') while (*pText != '\0')
{ {
rank = GetOffset (pText); rank = GetOffset (pText);