- v_text updated and moved to 'common'.

# Conflicts:
#	source/CMakeLists.txt
This commit is contained in:
Christoph Oelckers 2020-04-08 18:04:21 +02:00
parent 272d85663a
commit e500db97b1
5 changed files with 127 additions and 2 deletions

View file

@ -733,7 +733,6 @@ set (PCH_SOURCES
core/fonts/hexfont.cpp core/fonts/hexfont.cpp
core/fonts/singlelumpfont.cpp core/fonts/singlelumpfont.cpp
core/fonts/v_font.cpp core/fonts/v_font.cpp
core/fonts/v_text.cpp
core/console/c_console.cpp core/console/c_console.cpp
core/console/d_event.cpp core/console/d_event.cpp
@ -750,6 +749,7 @@ set (PCH_SOURCES
common/thirdparty/sfmt/SFMT.cpp common/thirdparty/sfmt/SFMT.cpp
common/textures/texture.cpp common/textures/texture.cpp
common/textures/animtexture.cpp common/textures/animtexture.cpp
common/fonts/v_text.cpp
common/textures/bitmap.cpp common/textures/bitmap.cpp
common/textures/m_png.cpp common/textures/m_png.cpp
common/textures/image.cpp common/textures/image.cpp

View file

@ -41,6 +41,11 @@
#include "v_font.h" #include "v_font.h"
#include "utf8.h" #include "utf8.h"
#include "filesystem.h"
#include "gstrings.h"
#include "vm.h"
#include "serializer.h"
//========================================================================== //==========================================================================
// //
@ -169,3 +174,69 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
} }
return Lines; return Lines;
} }
FSerializer &Serialize(FSerializer &arc, const char *key, FBrokenLines& g, FBrokenLines *def)
{
if (arc.BeginObject(key))
{
arc("text", g.Text)
("width", g.Width)
.EndObject();
}
return arc;
}
class DBrokenLines : public DObject
{
DECLARE_CLASS(DBrokenLines, DObject)
public:
TArray<FBrokenLines> mBroken;
DBrokenLines() = default;
DBrokenLines(TArray<FBrokenLines> &broken)
{
mBroken = std::move(broken);
}
void Serialize(FSerializer &arc) override
{
arc("lines", mBroken);
}
};
IMPLEMENT_CLASS(DBrokenLines, false, false);
DEFINE_ACTION_FUNCTION(DBrokenLines, Count)
{
PARAM_SELF_PROLOGUE(DBrokenLines);
ACTION_RETURN_INT(self->mBroken.Size());
}
DEFINE_ACTION_FUNCTION(DBrokenLines, StringWidth)
{
PARAM_SELF_PROLOGUE(DBrokenLines);
PARAM_INT(index);
ACTION_RETURN_INT((unsigned)index >= self->mBroken.Size()? -1 : self->mBroken[index].Width);
}
DEFINE_ACTION_FUNCTION(DBrokenLines, StringAt)
{
PARAM_SELF_PROLOGUE(DBrokenLines);
PARAM_INT(index);
ACTION_RETURN_STRING((unsigned)index >= self->mBroken.Size() ? -1 : self->mBroken[index].Text);
}
DEFINE_ACTION_FUNCTION(FFont, BreakLines)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_STRING(text);
PARAM_INT(maxwidth);
auto broken = V_BreakLines(self, maxwidth, text, true);
ACTION_RETURN_OBJECT(Create<DBrokenLines>(broken));
}

View file

@ -0,0 +1,52 @@
/*
** v_text.h
**
**---------------------------------------------------------------------------
** Copyright 1998-2006 Randy Heit
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#ifndef __V_TEXT_H__
#define __V_TEXT_H__
#include "v_font.h"
#include "printf.h"
struct FBrokenLines
{
unsigned Width;
FString Text;
};
TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str, bool preservecolor = false);
inline TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const char *str, bool preservecolor = false)
{ return V_BreakLines (font, maxwidth, (const uint8_t *)str, preservecolor); }
inline TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const FString &str, bool preservecolor = false)
{ return V_BreakLines (font, maxwidth, (const uint8_t *)str.GetChars(), preservecolor); }
#endif //__V_TEXT_H__

View file

@ -322,6 +322,7 @@ void DMenu::Drawer ()
if (this == DMenu::CurrentMenu && BackbuttonAlpha > 0 && m_show_backbutton >= 0 && m_use_mouse) if (this == DMenu::CurrentMenu && BackbuttonAlpha > 0 && m_show_backbutton >= 0 && m_use_mouse)
{ {
FTexture* tex = TileFiles.GetTexture("engine/graphics/m_back.png"); FTexture* tex = TileFiles.GetTexture("engine/graphics/m_back.png");
if (tex)
{ {
int w = tex->GetDisplayWidth() * CleanXfac; int w = tex->GetDisplayWidth() * CleanXfac;
int h = tex->GetDisplayHeight() * CleanYfac; int h = tex->GetDisplayHeight() * CleanYfac;

View file

@ -774,7 +774,8 @@ FTexture* BuildTiles::GetTexture(const char* path)
// let this go away. // let this go away.
auto res = textures.CheckKey(path); auto res = textures.CheckKey(path);
if (res) return *res; if (res) return *res;
auto tex = FTexture::CreateTexture(path, -1, ETextureType::Override); auto lump = fileSystem.FindFile(path);
auto tex = FTexture::CreateTexture(path, lump, ETextureType::Override);
if (tex) textures.Insert(path, tex); if (tex) textures.Insert(path, tex);
return tex; return tex;
} }