- [NEW] Modul de fonts

This commit is contained in:
2023-10-17 18:48:35 +02:00
parent 11d3309c82
commit c1bbcace85
2 changed files with 87 additions and 0 deletions

59
source/aux_font.cpp Normal file
View File

@@ -0,0 +1,59 @@
#include "aux_font.h"
#include "jgame.h"
namespace font
{
static draw::surface *font1 = nullptr;
static draw::surface *font2 = nullptr;
static int mode = font::type::normal;
void init()
{
font::font1 = draw::loadSurface("fuente1.gif");
font::font2 = draw::loadSurface("fuente2.gif");
}
void selectFont(const int which)
{
font::mode = which;
}
void setColor(const int color)
{
switch (color) {
case font::color::white: draw::setPaletteEntry(63, 255, 255, 255); break;
case font::color::red: draw::setPaletteEntry(63, 255, 0, 0); break;
case font::color::green: draw::setPaletteEntry(63, 0, 255, 0); break;
case font::color::blue: draw::setPaletteEntry(63, 0, 0, 255); break;
}
}
void print(const int x, const int y, const std::string text)
{
draw::setSource(font::mode == font::type::colored ? font::font2 : font::font1);
draw::setTrans(0);
if (font::mode == font::type::fade) for (int i=64;i<=67;++i) draw::swapcol(i, i+4);
const int len = text.length();
for (int i=0;i<len;++i)
{
char chr = text[i];
if (font::mode == font::type::colored)
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
else
draw::draw(x+i*7, y, 5, 5, (int(chr)-32)*7, 0);
}
for (int i=64;i<=67;++i) draw::restorecol(i);
draw::setTrans(255);
}
void print(const int x, const int y, const int num)
{
const char txt[3] = { char(num/10 + 48), char(num%10 + 48), 0 };
print(x, y, txt);
}
}

28
source/aux_font.h Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#include <string>
namespace font
{
namespace type
{
const int normal = 0;
const int colored = 1;
const int fade = 2;
}
namespace color
{
const int white = 0;
const int red = 1;
const int green = 2;
const int blue = 3;
}
void init();
void selectFont(const int which);
void setColor(const int color);
void print(const int x, const int y, const std::string text);
void print(const int x, const int y, const int num);
}