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

WIP: continue to add proper support for hebrew

It concerns mostly the layout (flipped).
This commit is contained in:
Mathieu Schroeter 2019-01-29 21:53:16 +01:00
parent ca1b6ce01c
commit e62eb9a7cb
9 changed files with 108 additions and 60 deletions

View File

@ -144,28 +144,30 @@ void
CButton::Draw ()
{
Sint32 i;
Point pos;
Point pos = this->m_pos;
Rect rect;
if (IsRightReading ())
pos.x = LXIMAGE () - pos.x - m_dim.x;
if (m_bHide) // bouton caché ?
{
rect.left = m_pos.x;
rect.right = m_pos.x + m_dim.x;
rect.top = m_pos.y;
rect.bottom = m_pos.y + m_dim.y;
m_pPixmap->DrawPart (-1, CHBACK, m_pos, rect); // dessine le fond
rect.left = pos.x;
rect.right = pos.x + m_dim.x;
rect.top = pos.y;
rect.bottom = pos.y + m_dim.y;
m_pPixmap->DrawPart (-1, CHBACK, pos, rect); // dessine le fond
return;
}
if (m_bEnable) // bouton actif ?
m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, m_mouseState, m_pos);
m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, m_mouseState, pos);
else
m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, 4, m_pos);
m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, 4, pos);
if (m_nbMenu == 0)
return;
pos = m_pos;
if (m_nbMenu > 0)
{
m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, m_iconMenu[m_selMenu] + 6, pos);
@ -174,7 +176,6 @@ CButton::Draw ()
if (m_nbMenu == 1 || !m_bEnable || !m_bMouseDown)
return;
pos = m_pos;
pos.x += m_dim.x + 2;
for (i = 0; i < m_nbMenu; i++)
{

View File

@ -23,19 +23,21 @@
#include <SDL_stdinc.h>
#include "display.h"
#include "misc.h"
// clang-format off
#define _INTRO true // true for init screen
#define POSDRAWX 144 // draw surface
#define POSDRAWY 15
#define DIMDRAWX (LXIMAGE () - (LXLOGIC () - LYLOGIC ()))
#define DIMDRAWY 450
#define POSDRAWX_ 144
#define POSDRAWX (IsRightReading () ? LXIMAGE () - POSDRAWX_ - DIMDRAWX : POSDRAWX_) // draw surface
#define POSDRAWY 15
#define POSMAPX 8 // map surface
#define POSMAPY 15
#define DIMMAPX 128
#define DIMMAPY 128
#define POSMAPX (IsRightReading () ? LXIMAGE () - 8 - DIMMAPX : 8) // map surface
#define POSMAPY 15
#define MAXCELX 200 // max cells for a world
#define MAXCELY 200
@ -56,10 +58,10 @@
#define DIMJAUGEX 124 // progress size
#define DIMJAUGEY 22
#define POSSTATX 12 // statistics
#define POSSTATY 220
#define DIMSTATX 60
#define DIMSTATY 30
#define POSSTATX (IsRightReading () ? LXIMAGE () - 12 - DIMSTATX * 2 : 12) // statistics
#define POSSTATY 220
#define DIMTEXTX 16 // max char size
#define DIMTEXTY 16

View File

@ -180,7 +180,7 @@ static Phase table[] =
EV_PHASE_HISTORY0,
"image/history0.png",
"image/back-book.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
true,
{
{
@ -205,7 +205,7 @@ static Phase table[] =
EV_PHASE_HISTORY1,
"image/history1.png",
"image/back-book.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
true,
{
{
@ -230,7 +230,7 @@ static Phase table[] =
EV_PHASE_INFO,
"image/info%.3d.png",
"image/back-book.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
false,
{
{
@ -297,7 +297,7 @@ static Phase table[] =
EV_PHASE_PLAY,
"image/play.png",
"",
CPixmap::Mode::EXPAND,
CPixmap::Mode::EXPAND_REVERSABLE,
false,
{
{
@ -328,7 +328,7 @@ static Phase table[] =
EV_PHASE_STOP,
"image/stop%.3d.png",
"image/back-book.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
false,
{
{
@ -377,7 +377,7 @@ static Phase table[] =
EV_PHASE_HELP,
"image/help.png",
"image/back-book.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
true,
{
{
@ -578,7 +578,7 @@ static Phase table[] =
EV_PHASE_READ,
"image/read.png",
"image/back-chest-r.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
false,
{
{
@ -657,7 +657,7 @@ static Phase table[] =
EV_PHASE_WRITE,
"image/write.png",
"image/back-chest-w.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
false,
{
{
@ -736,7 +736,7 @@ static Phase table[] =
EV_PHASE_WRITEp,
"image/write.png",
"image/back-chest-w.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
false,
{
{
@ -872,7 +872,7 @@ static Phase table[] =
EV_PHASE_BUILD,
"image/build.png",
"",
CPixmap::Mode::EXPAND,
CPixmap::Mode::EXPAND_REVERSABLE,
true,
{
{
@ -989,7 +989,7 @@ static Phase table[] =
EV_PHASE_BUTTON,
"image/button.png",
"image/back-build.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
true,
{
{
@ -1211,7 +1211,7 @@ static Phase table[] =
EV_PHASE_TERM,
"image/term.png",
"image/back-build.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
true,
{
{
@ -1302,7 +1302,7 @@ static Phase table[] =
EV_PHASE_MUSIC,
"image/music.png",
"image/back-build.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
true,
{
{
@ -1387,7 +1387,7 @@ static Phase table[] =
EV_PHASE_REGION,
"image/region.png",
"image/back-build.png",
CPixmap::Mode::FIX,
CPixmap::Mode::FIX_REVERSABLE,
true,
{
{

View File

@ -98,6 +98,12 @@ GetLocale ()
return gettext ("en");
}
bool
IsRightReading ()
{
return GetLocale () == "he";
}
// Retourne le nom de dossier en cours.
std::string

View File

@ -40,6 +40,7 @@ std::string GetBaseDir ();
std::string GetShareDir ();
std::string GetBinDir ();
std::string GetLocale ();
bool IsRightReading ();
extern void AddUserPath (std::string & pFilename);
enum Location { LOCATION_ABSOLUTE, LOCATION_BASE, LOCATION_USER };

View File

@ -124,7 +124,8 @@ CPixmap::CreateMainTexture ()
}
Sint32
CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR)
CPixmap::BltFast (
Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR, SDL_RendererFlip flip)
{
Sint32 res;
@ -159,16 +160,18 @@ CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR)
if (this->mainTexture)
SDL_SetRenderTarget (g_renderer, target ? target : this->mainTexture);
res = SDL_RenderCopy (
g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect);
res = SDL_RenderCopyEx (
g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect, 0,
nullptr, flip);
if (this->mainTexture)
SDL_SetRenderTarget (g_renderer, target);
}
else
{
SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[dstCh].texture);
res = SDL_RenderCopy (
g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect);
res = SDL_RenderCopyEx (
g_renderer, m_SDLTextureInfo[srcCh].texture, &srcRect, &dstRect, 0,
nullptr, flip);
SDL_SetRenderTarget (g_renderer, target);
}
@ -179,7 +182,8 @@ CPixmap::BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR)
// Les modes sont 0=transparent, 1=opaque.
Sint32
CPixmap::BltFast (Sint32 chDst, size_t channel, Point dst, Rect rcRect)
CPixmap::BltFast (
Sint32 chDst, size_t channel, Point dst, Rect rcRect, SDL_RendererFlip flip)
{
Sint32 limit;
@ -209,7 +213,7 @@ CPixmap::BltFast (Sint32 chDst, size_t channel, Point dst, Rect rcRect)
dstRect.top = dst.y;
dstRect.right = dstRect.left + rcRect.right - rcRect.left;
dstRect.bottom = dstRect.top + rcRect.bottom - rcRect.top;
return this->BltFast (chDst, channel, dstRect, rcRect);
return this->BltFast (chDst, channel, dstRect, rcRect, flip);
}
// Effectue un appel BltFast.
@ -376,9 +380,15 @@ CPixmap::Cache (
SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture);
SDL_RendererFlip flip =
(mode == FIX_REVERSABLE || mode == EXPAND_REVERSABLE) && IsRightReading ()
? SDL_FLIP_HORIZONTAL
: SDL_FLIP_NONE;
switch (mode)
{
case FIX:
case FIX_REVERSABLE:
{
if (channel == CHBACK && (ow < LXIMAGE () || oh < LYIMAGE ()))
{
@ -389,7 +399,8 @@ CPixmap::Cache (
SDL_Texture * texture =
SDL_CreateTextureFromSurface (g_renderer, surface);
SDL_FreeSurface (surface);
SDL_RenderCopy (g_renderer, texture, nullptr, nullptr);
SDL_RenderCopyEx (
g_renderer, texture, nullptr, nullptr, 0, nullptr, flip);
SDL_DestroyTexture (texture);
}
@ -398,32 +409,37 @@ CPixmap::Cache (
dst.y = 0;
dst.w = ow;
dst.h = oh;
SDL_RenderCopy (g_renderer, texture, nullptr, &dst);
SDL_RenderCopyEx (g_renderer, texture, nullptr, &dst, 0, nullptr, flip);
}
else
SDL_RenderCopy (g_renderer, texture, nullptr, nullptr);
SDL_RenderCopyEx (
g_renderer, texture, nullptr, nullptr, 0, nullptr, flip);
break;
}
case EXPAND:
case EXPAND_REVERSABLE:
{
auto isFlipped = flip == SDL_FLIP_HORIZONTAL;
SDL_Rect src, dst;
src.x = 0;
src.y = 0;
src.w = POSDRAWX - 1;
src.w = POSDRAWX_ - 1;
src.h = LYIMAGE ();
dst = src;
SDL_RenderCopy (g_renderer, texture, &src, &dst);
dst.x = isFlipped ? LXIMAGE () - src.w : src.x;
SDL_RenderCopyEx (g_renderer, texture, &src, &dst, 0, nullptr, flip);
src.x = ow - 16;
src.w = 16;
dst.x = LXIMAGE () - 16;
dst.x = isFlipped ? 0 : LXIMAGE () - 16;
dst.w = src.w;
SDL_RenderCopy (g_renderer, texture, &src, &dst);
src.x = POSDRAWX - 1;
SDL_RenderCopyEx (g_renderer, texture, &src, &dst, 0, nullptr, flip);
src.x = POSDRAWX_ - 1;
src.w = ow - src.x - 16;
dst.x = src.x;
dst.x = isFlipped ? 16 : src.x;
dst.w = DIMDRAWX + 1;
SDL_RenderCopy (g_renderer, texture, &src, &dst);
SDL_RenderCopyEx (g_renderer, texture, &src, &dst, 0, nullptr, flip);
break;
}
}
@ -644,12 +660,13 @@ CPixmap::DrawIconPart (
// Dessine une partie d'image n'importe o�.
bool
CPixmap::DrawPart (Sint32 chDst, size_t channel, Point dest, Rect rect)
CPixmap::DrawPart (
Sint32 chDst, size_t channel, Point dest, Rect rect, SDL_RendererFlip flip)
{
if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ())
return false;
return !BltFast (chDst, channel, dest, rect);
return !BltFast (chDst, channel, dest, rect, flip);
}
// Dessine une partie d'image rectangulaire.

View File

@ -55,7 +55,9 @@ class CPixmap
public:
enum Mode {
FIX = 0,
FIX_REVERSABLE,
EXPAND,
EXPAND_REVERSABLE,
};
CPixmap (CEvent * event);
@ -82,7 +84,9 @@ public:
bool DrawIconPart (
Sint32 chDst, size_t channel, Sint32 rank, Point pos, Sint32 startY,
Sint32 endY);
bool DrawPart (Sint32 chDst, size_t channel, Point dest, Rect rect);
bool DrawPart (
Sint32 chDst, size_t channel, Point dest, Rect rect,
SDL_RendererFlip flip = SDL_FLIP_NONE);
bool DrawImage (Sint32 chDst, size_t channel, Rect rect);
bool BuildIconMask (
@ -102,8 +106,12 @@ public:
void FromGameToDisplay (Sint32 & x, Sint32 & y);
protected:
Sint32 BltFast (Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR);
Sint32 BltFast (Sint32 chDst, size_t channel, Point dst, Rect rcRect);
Sint32 BltFast (
Sint32 dstCh, size_t srcCh, Rect dstR, Rect srcR,
SDL_RendererFlip flip = SDL_FLIP_NONE);
Sint32 BltFast (
Sint32 chDst, size_t channel, Point dst, Rect rcRect,
SDL_RendererFlip flip = SDL_FLIP_NONE);
Sint32 BltFast (
SDL_Texture * lpSDL, size_t channel, Point dst, Rect rcRect,
SDL_BlendMode = SDL_BLENDMODE_BLEND);

View File

@ -63,32 +63,42 @@ CJauge::Draw ()
{
Sint32 part;
Rect rect;
Point pos = this->m_pos;
if (IsRightReading ())
pos.x = LXIMAGE () - pos.x - m_dim.x;
if (m_bHide) // bouton caché ?
{
rect.left = m_pos.x;
rect.right = m_pos.x + m_dim.x;
rect.top = m_pos.y;
rect.bottom = m_pos.y + m_dim.y;
m_pPixmap->DrawPart (-1, CHBACK, m_pos, rect); // dessine le fond
rect.left = pos.x;
rect.right = pos.x + m_dim.x;
rect.top = pos.y;
rect.bottom = pos.y + m_dim.y;
m_pPixmap->DrawPart (-1, CHBACK, pos, rect); // dessine le fond
return;
}
SDL_RendererFlip flip = SDL_FLIP_NONE;
if (IsRightReading ())
flip = SDL_FLIP_HORIZONTAL;
part = (m_level * (DIMJAUGEX - 6 - 4)) / 100;
rect.left = 0;
rect.right = DIMJAUGEX;
rect.top = DIMJAUGEY * 0;
rect.bottom = DIMJAUGEY * 1;
m_pPixmap->DrawPart (-1, CHJAUGE, m_pos, rect); // partie noire
m_pPixmap->DrawPart (-1, CHJAUGE, pos, rect, flip); // partie noire
if (part > 0)
{
if (IsRightReading ())
pos.x += DIMJAUGEX - part - 6;
rect.left = 0;
rect.right = 6 + part;
rect.top = DIMJAUGEY * m_type;
rect.bottom = DIMJAUGEY * (m_type + 1);
m_pPixmap->DrawPart (-1, CHJAUGE, m_pos, rect); // partie colorée
m_pPixmap->DrawPart (-1, CHJAUGE, pos, rect, flip); // partie colorée
}
}

View File

@ -211,6 +211,9 @@ DrawTextPente (
{
Sint32 rank, lg, rel, start;
if (IsRightReading ())
pos.x = LXIMAGE () - pos.x;
start = pos.y;
rel = 0;
while (*pText != 0)
@ -227,7 +230,7 @@ DrawTextPente (
pText++;
pText++;
rel += lg;
pos.x += lg;
pos.x += IsRightReading () ? -lg : lg;
pos.y = start + rel / pente;
}
}