Merge branch 'fixes' into atys

13-inventory-fixes
Nuno 3 years ago
commit 0fbbf10361

6
.gitignore vendored

@ -128,6 +128,9 @@ aes_state.txt
# intellij project folder
.idea/
# VSCode project folder
.vscode/
# Python cache
*.pyd
*.pyc
@ -244,6 +247,9 @@ external_stlport
nel_tools*
ryzom_tools*
#personal projects
personal/
# Dumps
*.dmp

@ -54,8 +54,8 @@ ENDIF()
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(RyzomCore CXX C)
SET(NL_VERSION_MAJOR 1)
SET(NL_VERSION_MINOR 0)
SET(NL_VERSION_PATCH 2)
SET(NL_VERSION_MINOR 1)
SET(NL_VERSION_PATCH 0 CACHE STRING "Patch version")
SET(YEAR "2001-${CURRENT_YEAR}")
SET(AUTHOR "Winch Gate and The Ryzom Core Community")

@ -1,74 +0,0 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef XML_MACROS_H
#define XML_MACROS_H
//
// xmlNodePtr cur;
// CXMLAutoPtr prop;
//
// sint i;
// XML_READ_SINT(cur, "prop_name", i, -1);
//
#define XML_READ_UINT(node, name, var, def) { \
uint tmp; \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop && fromString((const char*)prop, tmp)) \
var = tmp; \
else \
var = def; \
}
#define XML_READ_SINT(node, name, var, def) { \
sint tmp; \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop && fromString((const char*)prop, tmp)) \
var = tmp; \
else \
var = def; \
}
#define XML_READ_BOOL(node, name, var, def) { \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop) \
var = NLMISC::toBool((const char*)prop); \
else \
var = def; \
}
#define XML_READ_COLOR(node, name, var, def) { \
NLMISC::CRGBA tmp; \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop && fromString((const char*)prop, tmp)) \
var = tmp; \
else \
var = def; \
}
#define XML_READ_STRING(node, name, var, def) { \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop) \
var = (const char*)prop; \
else \
var = def; \
}
#endif // XML_MACROS_H

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
@ -40,7 +43,7 @@ class CTextureFile;
class CAsyncFileManager3D
{
NLMISC_SAFE_SINGLETON_DECL(CAsyncFileManager3D);
NLMISC_SAFE_RELEASABLE_SINGLETON_DECL(CAsyncFileManager3D);
CAsyncFileManager3D();
public:

@ -1,8 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2018 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -181,7 +181,8 @@ public:
CVertexBuffer Vertices;
CMaterial *Material;
CRGBA Color;
ucstring Text;
std::string Text;
size_t Length;
uint32 CacheVersion;

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -262,10 +262,10 @@ public:
virtual NLMISC::IEventEmitter *getEventEmitter() = 0;
/// Copy a string to system clipboard.
virtual bool copyTextToClipboard(const ucstring &text) = 0;
virtual bool copyTextToClipboard(const std::string &text) = 0;
/// Paste a string from system clipboard.
virtual bool pasteTextFromClipboard(ucstring &text) = 0;/// Return the depth of the driver after init().
virtual bool pasteTextFromClipboard(std::string &text) = 0;/// Return the depth of the driver after init().
virtual uint8 getBitPerPixel() = 0;

@ -4,7 +4,7 @@
// This source file has been modified by the following contributors:
// Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
// Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
// Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -558,10 +558,10 @@ public:
// @}
// Copy a string to system clipboard.
virtual bool copyTextToClipboard(const ucstring &text);
virtual bool copyTextToClipboard(const std::string &text);
// Paste a string from system clipboard.
virtual bool pasteTextFromClipboard(ucstring &text);
virtual bool pasteTextFromClipboard(std::string &text);
virtual uint64 getSwapBufferCounter();

@ -1,5 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2018 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -33,7 +36,7 @@ typedef struct FT_FaceRec_* FT_Face;
#include "nel/misc/types_nl.h"
#include <string>
#include <vector>
namespace NL3D {
@ -64,17 +67,17 @@ public:
* \param height height of the generated bitmap, this value is set by this function
* \param pitch pitch of the generated bitmap (+ or - the number of bytes per row), this value is set by this function
*/
uint8 *getBitmap (ucchar c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex);
uint8 *getBitmap (u32char c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex);
/** returns the width and height of a character using a specific size and
*
* \warning this function is not very fast (but faster than getBitmap()) because it has to load the char before.
*/
void getSizes (ucchar c, uint32 size, uint32 &width, uint32 &height);
void getSizes (u32char c, uint32 size, uint32 &width, uint32 &height);
void getKerning (ucchar left, ucchar right, sint32 &kernx);
void getKerning (u32char left, u32char right, sint32 &kernx);
uint32 getCharIndex (ucchar c);
uint32 getCharIndex (u32char c);
uint32 getUID() { return _UID; }
@ -85,6 +88,7 @@ private:
static uint32 _FontGeneratorCounterUID;
uint32 _UID;
std::string _FontFileName;
std::vector<std::string> _FontFileNames;
#ifndef NL_DONT_USE_EXTERNAL_CODE
const char *getFT2Error(FT_Error fte);
@ -92,7 +96,7 @@ private:
static FT_Library _Library;
static uint _LibraryInit;
FT_Face _Face;
std::vector<FT_Face> _Faces;
#else // NL_DONT_USE_EXTERNAL_CODE
#endif // NL_DONT_USE_EXTERNAL_CODE

@ -1,5 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2018 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -19,6 +22,7 @@
#include "nel/misc/types_nl.h"
#include "nel/misc/smart_ptr.h"
#include "nel/misc/utf_string_view.h"
#include "nel/3d/texture.h"
#include "nel/3d/material.h"
#include "nel/3d/texture_font.h"
@ -111,6 +115,7 @@ public:
* \param output computed string
* \param keep800x600Ratio true if you want that CFontManager look at Driver window size, and resize fontSize so it keeps same size...
*/
/*
void computeString (const std::string& s,
CFontGenerator *fontGen,
const NLMISC::CRGBA &color,
@ -120,11 +125,26 @@ public:
IDriver *driver,
CComputedString& output,
bool keep800x600Ratio= true);
*/
/**
* Same as computeString but works with a unicode string (ucstring)
*/
void computeString (const ucstring &s,
void computeString (NLMISC::CUtfStringView sv,
CFontGenerator *fontGen,
const NLMISC::CRGBA &color,
uint32 fontSize,
bool embolden,
bool oblique,
IDriver *driver,
CComputedString &output,
bool keep800x600Ratio= true);
/**
* Same as computeString but do not make vertex buffers and primitives
*/
void computeStringInfo (NLMISC::CUtfStringView sv,
size_t len,
CFontGenerator *fontGen,
const NLMISC::CRGBA &color,
uint32 fontSize,
@ -137,7 +157,7 @@ public:
/**
* Same as computeString but do not make vertex buffers and primitives
*/
void computeStringInfo (const ucstring &s,
void computeStringInfo (NLMISC::CUtfStringView sv,
CFontGenerator *fontGen,
const NLMISC::CRGBA &color,
uint32 fontSize,

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the

@ -837,7 +837,7 @@ private:
void restoreOriginalSkinVertices();
// apply Skin to all vertices from _OriginalSkin* to _VBuffer.
void applySkin(CSkeletonModel *skeleton);
void applySkin(void *dstVb, CSkeletonModel *skeleton);
void flagSkinVerticesForMatrixBlock(uint8 *skinFlags, CMatrixBlock &mb);

@ -1,8 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2018 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -134,7 +134,7 @@ public:
uint32 textPush (const char *format, ...);
/// computes an ucstring and adds the result to the cache (return the index)
uint32 textPush (const ucstring &str);
uint32 textPush (NLMISC::CUtfStringView sv);
/// remove a string from the cache
void erase (uint32 index);
@ -262,12 +262,12 @@ public:
}
/// Directly print a string
void printAt (float x, float z, const ucstring &ucstr)
void printAt (float x, float z, NLMISC::CUtfStringView sv)
{
nlassert(_FontGen);
// compute the string just one time
_FontManager->computeString (ucstr, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, _TempString, _Keep800x600Ratio);
_FontManager->computeString (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, _TempString, _Keep800x600Ratio);
// draw shaded
if (_Shaded)
@ -372,14 +372,19 @@ public:
* \param an ucstring
* \param the computed string
*/
void computeString (const ucstring& s, CComputedString& output)
void computeString (NLMISC::CUtfStringView sv, CComputedString& output)
{
_FontManager->computeString (s, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio);
_FontManager->computeString (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio);
}
void computeStringInfo (NLMISC::CUtfStringView sv, CComputedString& output)
{
_FontManager->computeStringInfo (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio);
}
void computeStringInfo (const ucstring& s, CComputedString& output)
void computeStringInfo (NLMISC::CUtfStringView sv, CComputedString& output, size_t len)
{
_FontManager->computeStringInfo (s, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio);
_FontManager->computeStringInfo (sv, len, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio);
}
/// Debug : write to the disk the texture cache

@ -1,8 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2018 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -97,13 +97,14 @@ public:
*/
// @{
uint32 textPush(const char *format, ...) ;
uint32 textPush(const ucstring &str) ;
uint32 textPush(NLMISC::CUtfStringView sv) ;
void setStringColor(uint32 i, CRGBA newCol);
void setStringSelection(uint32 i, uint32 selectStart, uint32 selectSize);
void resetStringSelection(uint32 i);
void erase(uint32 i) ;
virtual CStringInfo getStringInfo (uint32 i);
virtual CStringInfo getStringInfo (const ucstring &ucstr);
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv);
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv, size_t len);
void clear() ;
void printAt(float x, float y, uint32 i) ;
@ -111,10 +112,10 @@ public:
void printClipAtUnProjected(URenderStringBuffer &renderBuffer, class NL3D::CFrustum &frustum, const NLMISC::CMatrix &scaleMatrix, float x, float y, float depth, uint32 i, float xmin, float ymin, float xmax, float ymax);
void printClipAtOld (float x, float y, uint32 i, float xmin, float ymin, float xmax, float ymax);
void printAt(float x, float y, const ucstring &ucstr) ;
void printAt(float x, float y, NLMISC::CUtfStringView sv) ;
void printfAt(float x, float y, const char * format, ...) ;
void render3D(const CMatrix &mat, const ucstring &ucstr) ;
void render3D(const CMatrix &mat, NLMISC::CUtfStringView sv) ;
void render3D(const CMatrix &mat, const char *format, ...) ;
float getLastXBound() const ;

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the

@ -1,5 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -35,12 +38,43 @@ class CTextureFont : public ITexture
public:
struct SLetterKey
{
u32char Char;
sint Size;
bool Embolden;
bool Oblique;
CFontGenerator *FontGenerator;
SLetterKey() : Char(0), Size(0), Embolden(false), Oblique(false), FontGenerator(NULL)
{
}
// Does not use FontGenerator in return value
inline uint64 getVal() const
{
return Char // 32 bits
| (uint64(Size & 0xFFFF) << 32) // 16 bits
| (uint64(Embolden) << (32+16)) // 1 bit
| (uint64(Oblique) << (32+16+1)); // 1 bit
}
bool operator<(const SLetterKey &rhs) const
{
uint64 a = getVal();
uint64 b = rhs.getVal();
return (a < b) || ((a == b) && (FontGenerator < rhs.FontGenerator));
}
};
// Holds info for glyphs rendered on atlas
struct SGlyphInfo
struct SGlyphInfo : SLetterKey
{
// font atlas info
uint32 CacheVersion;
uint32 GlyphIndex;
// atlas region with padding
uint32 X, Y, W, H;
@ -51,30 +85,17 @@ public:
// UV coords for rendered glyph without padding
float U0, V0, U1, V1;
uint32 GlyphIndex;
sint Size;
bool Embolden;
bool Oblique;
CFontGenerator *FontGenerator;
SGlyphInfo()
: CacheVersion(0),
: CacheVersion(0), GlyphIndex(0),
U0(0.f), V0(0.f), U1(0.f), V1(0.f),
X(0), Y(0), W(0), H(0), CharWidth(0), CharHeight(0),
GlyphIndex(0), Size(0), Embolden(false), Oblique(false), FontGenerator(NULL)
X(0), Y(0), W(0), H(0), CharWidth(0), CharHeight(0)
{
}
};
// Holds info for glyphs displayed on screen
struct SLetterInfo
struct SLetterInfo : SLetterKey
{
ucchar Char;
sint Size;
bool Embolden;
bool Oblique;
CFontGenerator *FontGenerator;
uint32 GlyphIndex;
uint32 CharWidth; // Displayed glyph height
uint32 CharHeight; // Displayed glyph height
@ -85,29 +106,12 @@ public:
SGlyphInfo* glyph;
SLetterInfo()
: Char(0), Size(0), Embolden(false), Oblique(false), FontGenerator(NULL),
GlyphIndex(0), CharWidth(0), CharHeight(0), Top(0), Left(0), AdvX(0),
: GlyphIndex(0), CharWidth(0), CharHeight(0), Top(0), Left(0), AdvX(0),
glyph(NULL)
{
}
};
struct SLetterKey
{
ucchar Char;
sint Size;
bool Embolden;
bool Oblique;
CFontGenerator *FontGenerator;
// Does not use FontGenerator in return value
uint32 getVal();
SLetterKey():Char(0), FontGenerator(NULL), Size(0), Embolden(false), Oblique(false)
{
}
};
public:
/**
@ -148,7 +152,7 @@ private:
// Keep track of available space in main texture
std::vector<NLMISC::CRect> _AtlasNodes;
std::vector <SLetterInfo> _Letters;
std::map<SLetterKey, SLetterInfo> _Letters;
// lookup letter from letter cache or create new
SLetterInfo* findLetter(SLetterKey& k, bool insert);
@ -162,7 +166,7 @@ private:
uint _GlyphSizeStep;
// rendered glyph cache
std::list<SGlyphInfo> _GlyphCache;
std::map<SLetterKey, SGlyphInfo> _GlyphCache;
SGlyphInfo* findLetterGlyph(SLetterInfo *letter, bool insert);
// render letter glyph into glyph cache

@ -4,7 +4,7 @@
// This source file has been modified by the following contributors:
// Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
// Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
// Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -835,10 +835,10 @@ public:
/// \name Clipboard management
// @{
// Copy a string to system clipboard.
virtual bool copyTextToClipboard(const ucstring &text) =0;
virtual bool copyTextToClipboard(const std::string &text) =0;
// Paste a string from system clipboard.
virtual bool pasteTextFromClipboard(ucstring &text) =0;
virtual bool pasteTextFromClipboard(std::string &text) =0;
// @}
public:

@ -1,8 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2018 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -24,7 +24,7 @@
#include "nel/misc/rgba.h"
#include "nel/misc/ucstring.h"
#include "nel/misc/matrix.h"
#include "nel/misc/utf_string_view.h"
namespace NL3D {
@ -104,8 +104,11 @@ public:
*/
float StringLine;
CStringInfo() {StringWidth= StringHeight= StringLine= 0;}
CStringInfo(float w, float h, float l) {StringWidth= w; StringHeight= h; StringLine = l;}
/// The length in characters
size_t StringLength;
CStringInfo() { StringWidth = StringHeight = StringLine = 0; StringLength = 0; }
CStringInfo(float w, float h, float l, size_t len) { StringWidth = w; StringHeight = h; StringLine = l; StringLength = len; }
/**
* Get the string's origin
@ -248,7 +251,7 @@ public:
* \param an ucstring
* \return the index where computed string has been inserted
*/
virtual uint32 textPush (const ucstring &str) = 0;
virtual uint32 textPush (NLMISC::CUtfStringView sv) = 0;
/**
* set the color of a string.
*/
@ -274,7 +277,12 @@ public:
* Get a string information from the ucstring
* The returned string info is in pixel size per default.
*/
virtual CStringInfo getStringInfo (const ucstring &ucstr) = 0;
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv) = 0;
/**
* Get a string information from the ucstring
* The returned string info is in pixel size per default.
*/
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv, size_t len) = 0;
/**
* empty the map
*/
@ -299,7 +307,7 @@ public:
/**
* compute and print a ucstring at the location (2D method) x/y E [0,1]
*/
virtual void printAt (float x, float y, const ucstring &ucstr) = 0;
virtual void printAt (float x, float y, NLMISC::CUtfStringView sv) = 0;
/**
* compute and print a string at the location (2D method) x/y E [0,1]
*/
@ -309,7 +317,7 @@ public:
* compute and render a ucstring at the location (3D method)
* render3D() use UDriver Matrix context for Frustum/ViewMatrix, but use its own modelmatrix (mat).
*/
virtual void render3D (const NLMISC::CMatrix &mat, const ucstring &ucstr) = 0;
virtual void render3D (const NLMISC::CMatrix &mat, NLMISC::CUtfStringView sv) = 0;
/**
* compute and render a string at the location (3D method)
* render3D() use UDriver Matrix context for Frustum/ViewMatrix, but use its own modelmatrix (mat).

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -22,6 +22,7 @@
#include "nel/misc/types_nl.h"
#include "nel/georges/u_form.h"
#include "form_dfn.h"
#include "form_elm.h"
#include "header.h"
@ -124,6 +125,10 @@ private:
// The form filename
std::string _Filename;
// The dfn
NLMISC::CSmartPtr<CFormDfn> _Dfn;
};
} // NLGEORGES

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -282,6 +282,10 @@ public:
{
Element = NULL;
}
~CFormElmStructElm()
{
nlassert(!Element);
}
std::string Name;
CFormElm* Element;
@ -400,6 +404,10 @@ public:
{
Element = NULL;
}
~CElement ()
{
nlassert(!Element);
}
std::string Name;
CFormElm* Element;
@ -631,7 +639,7 @@ inline bool CFormElm::convertValue (bool &result, const std::string &value) cons
}
else
{
std::string temp = NLMISC::toLower(value);
std::string temp = NLMISC::toLowerAscii(value);
if (strcmp (temp.c_str (), "true") == 0)
{
result = true;

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -69,7 +70,7 @@ namespace NLGUI
static CAHManager* getInstance()
{
if (_GlobalInstance == NULL)
if (_GlobalInstance == NULL && !s_Deleted)
_GlobalInstance = new CAHManager;
return _GlobalInstance;
}
@ -134,6 +135,19 @@ namespace NLGUI
static CAHManager *_GlobalInstance;
static bool editorMode;
class CDeleter
{
public:
~CDeleter()
{
delete _GlobalInstance;
_GlobalInstance = NULL;
s_Deleted = true;
}
};
static CDeleter s_Deleter;
static bool s_Deleted;
};
/// Ah name must all be lower case

@ -0,0 +1,83 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CL_CSS_BACKGROUND_H
#define CL_CSS_BACKGROUND_H
#include "nel/misc/types_nl.h"
#include "nel/misc/rgba.h"
#include "nel/gui/css_types.h"
#include "nel/gui/css_length.h"
namespace NLGUI
{
/**
* \brief CSS background info
* \date 2021-07-02 11:36 GMT
* \author Meelis Mägi (Nimetu)
*/
class CSSBackground
{
public:
CSSBackground()
:color(NLMISC::CRGBA::Transparent),
repeatX(CSS_VALUE_REPEAT), repeatY(CSS_VALUE_REPEAT), attachment(CSS_VALUE_SCROLL),
xAnchor(CSS_VALUE_LEFT), yAnchor(CSS_VALUE_TOP),
clip(CSS_VALUE_BORDER_BOX), origin(CSS_VALUE_PADDING_BOX), size(CSS_VALUE_AUTO)
{}
void setImage(const std::string &value);
void setPosition(const std::string &value);
void setSize(const std::string &value);
void setRepeat(const std::string &value);
void setOrigin(const std::string &value);
void setClip(const std::string &value);
void setAttachment(const std::string &value);
void setColor(const std::string &value);
public:
// TODO: only final layer has color
NLMISC::CRGBA color;
std::string image;
CSSValueType repeatX;
CSSValueType repeatY;
CSSValueType attachment;
CSSValueType xAnchor;
CSSValueType yAnchor;
CSSLength xPosition;
CSSLength yPosition;
CSSValueType clip;
CSSValueType origin;
CSSValueType size;
CSSLength width;
CSSLength height;
private:
void positionFromOne(const std::vector<std::string> &parts);
void positionFromTwo(const std::vector<std::string> &parts);
void positionFromThree(const std::vector<std::string> &parts);
void positionFromFour(const std::vector<std::string> &parts);
};
}//namespace
#endif // CL_CSS_BACKGROUND_H

@ -0,0 +1,193 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NL_CSS_BACKGROUND_RENDERER_H
#define NL_CSS_BACKGROUND_RENDERER_H
#include "nel/misc/types_nl.h"
#include "nel/misc/rgba.h"
#include "nel/misc/geom_ext.h"
#include "nel/gui/css_types.h"
#include "nel/gui/css_background.h"
namespace NLGUI
{
class CInterfaceElement;
/**
* \brief Border renderer for GUI classes
* \date 2021-06-29 15:17 GMT
* \author Meelis Mägi (Nimetu)
*/
class CSSBackgroundRenderer
{
public:
// alpha value from parent
uint8 CurrentAlpha;
// TODO: should be moved to CSSBackground
sint32 TextureId;
public:
CSSBackgroundRenderer();
~CSSBackgroundRenderer();
// return true if no background is set
bool isEmpty() const
{
return m_Background.image.empty() && m_Background.color.A == 0;
}
void setModulateGlobalColor(bool m) { m_ModulateGlobalColor = m; }
void updateCoords();
void invalidateCoords() { m_Dirty = true; }
void invalidateContent() { m_Dirty = true; };
void clear();
void setBackground(const CSSBackground &bg);
// helper function to change background image
void setImage(const std::string &bgtex);
void setImageRepeat(bool b);
void setImageCover(bool b);
// helper function to change background color
void setColor(const NLMISC::CRGBA &color)
{
m_Dirty = true;
m_Background.color = color;
}
NLMISC::CRGBA getColor() const
{
return m_Background.color;
}
// override painting area to be at least the size of viewport (ie, <html> background)
void setFillViewport(bool b) {
m_Dirty = true;
m_FillViewport = b;
}
void setViewport(CInterfaceElement *root)
{
m_Dirty = true;
m_Viewport = root;
}
void setBorderArea(sint32 x, sint32 y, sint32 w, sint32 h)
{
m_Dirty = true;
m_BorderX = x;
m_BorderY = y;
m_BorderW = w;
m_BorderH = h;
}
void setPaddingArea(sint32 x, sint32 y, sint32 w, sint32 h)
{
m_Dirty = true;
m_PaddingX = x;
m_PaddingY = y;
m_PaddingW = w;
m_PaddingH = h;
}
void setContentArea(sint32 x, sint32 y, sint32 w, sint32 h)
{
m_Dirty = true;
m_ContentX = x;
m_ContentY = y;
m_ContentW = w;
m_ContentH = h;
}
// sizes for em, rem units
void setFontSize(float rootFontSize, float fontSize)
{
m_Dirty = true;
m_RootFontSize = rootFontSize;
m_FontSize = fontSize;
}
void draw();
private:
sint32 m_BorderX, m_BorderY, m_BorderW, m_BorderH;
sint32 m_PaddingX, m_PaddingY, m_PaddingW, m_PaddingH;
sint32 m_ContentX, m_ContentY, m_ContentW, m_ContentH;
// font size for 'rem'
float m_RootFontSize;
// font size for 'em'
float m_FontSize;
// viewport element for vw,wh,vmin,vmax
CInterfaceElement* m_Viewport;
struct SDrawQueue
{
sint32 TextureId;
NLMISC::CQuadUV Quad;
NLMISC::CRGBA Color;
};
std::vector<SDrawQueue> m_DrawQueue;
const sint8 m_RenderLayer;
bool m_ModulateGlobalColor;
// if true, painting area returns area at least the size of viewport (ie, <html> background)
bool m_FillViewport;
// if true, then updateCoords() is called from draw()
bool m_Dirty;
CSSBackground m_Background;
// get clip area based on background-clip
void getPaintingArea(const CSSBackground &bg, sint32 &areaX, sint32 &areaY, sint32 &areaW, sint32 &areaH) const;
// get positioning area based on background-origin
void getPositioningArea(const CSSBackground &bg, sint32 &areaX, sint32 &areaY, sint32 &areaW, sint32 &areaH) const;
// calculate image size based on background-size
void calculateSize(const CSSBackground &bg, sint32 &texW, sint32 &texH) const;
// calculate image position based on background-position
void calculatePosition(const CSSBackground &bg, sint32 &texX, sint32 &texY, sint32 &texW, sint32 &texH) const;
// calculate image tile position, size, count, and spacing based on background-repeat
void calculateTiles(const CSSBackground &bg, sint32 &texX, sint32 &texY, sint32 &texW, sint32 &texH, sint32 &tilesX, sint32 &tilesY, sint32 &spacingX, sint32 &spacingY) const;
// position, size, and count for first tile to cover an area
void getImageTile(sint32 &tilePos, sint32 &tileSize, sint32 &spacing, sint32 &tiles, sint32 areaPos, sint32 areaSize, CSSValueType repeat) const;
// push background color to draw queue
void buildColorQuads(const CSSBackground &bg);
// push background image to draw quque
void buildImageQuads(const CSSBackground &bg, sint32 textureId);
}; // CSSBackgroundRenderer
}//namespace
#endif // NL_CSS_BACKGROUND_RENDERER_H

@ -0,0 +1,72 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CL_CSS_BORDER_H
#define CL_CSS_BORDER_H
#include "nel/misc/types_nl.h"
#include "nel/misc/rgba.h"
#include "nel/gui/css_types.h"
#include "nel/gui/css_length.h"
namespace NLGUI
{
/**
* \brief CSS border info
* \date 2021-07-23 09:51 GMT
* \author Meelis Mägi (Nimetu)
*/
class CSSBorder
{
public:
CSSBorder()
{
reset();
}
CSSBorder(uint width, CSSLineStyle style, NLMISC::CRGBA color)
{
set(width, style, color);
}
void reset()
{
set(CSS_LINE_WIDTH_MEDIUM, CSS_LINE_STYLE_NONE, NLMISC::CRGBA::Transparent);
}
void set(uint width, CSSLineStyle style, NLMISC::CRGBA color)
{
Width.setFloatValue(width, "px");
Style = style;
Color = color;
}
bool empty() const
{
return Style == CSS_LINE_STYLE_NONE || Style == CSS_LINE_STYLE_HIDDEN
|| Width.getFloat() == 0;
}
CSSLength Width;
CSSLineStyle Style;
NLMISC::CRGBA Color;
};
}//namespace
#endif // CL_CSS_BORDER_H

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -23,9 +23,12 @@
#include "nel/misc/rgba.h"
#include "nel/misc/geom_ext.h"
#include "nel/gui/css_types.h"
#include "nel/gui/css_border.h"
namespace NLGUI
{
class CInterfaceElement;
/**
* \brief Border renderer for GUI classes
* \date 2019-09-03 10:50 GMT
@ -34,29 +37,76 @@ namespace NLGUI
class CSSBorderRenderer
{
private:
enum EBorderSide
{
BORDER_TOP_LEFT = 0,
BORDER_TOP_RIGHT,
BORDER_BOTTOM_LEFT,
BORDER_BOTTOM_RIGHT,
BORDER_LEFT_TOP,
BORDER_RIGHT_TOP,
BORDER_LEFT_BOTTOM,
BORDER_RIGHT_BOTTOM,
BORDER_TOP,
BORDER_RIGHT,
BORDER_BOTTOM,
BORDER_LEFT,
BORDER_INVALID
};
// parent element screen coordinates
sint32 _XReal, _YReal;
sint32 _WReal, _HReal;
sint32 m_XReal, m_YReal;
sint32 m_WReal, m_HReal;
NLMISC::CQuadUV _QuadT;
NLMISC::CQuadUV _QuadR;
NLMISC::CQuadUV _QuadB;
NLMISC::CQuadUV _QuadL;
struct SDrawBorder
{
NLMISC::CQuadUV Quad;
NLMISC::CRGBA Color;
};
std::vector<SDrawBorder> m_DrawBorders;
uint8 _RenderLayer;
bool _ModulateGlobalColor;
sint8 m_RenderLayer;
bool m_ModulateGlobalColor;
// if true, then updateCoords() is called from draw()
bool _Dirty;
// if true, then at least one border is set
bool _Border;
bool _BorderTop, _BorderRight, _BorderBottom, _BorderLeft;
bool m_Dirty;
// UI scale, used to calculate number of segments to draw for circle
float m_Scale;
public:
uint32 TopWidth, RightWidth, BottomWidth, LeftWidth;
NLMISC::CRGBA TopColor, RightColor, BottomColor, LeftColor;
CSSLineStyle TopStyle, RightStyle, BottomStyle, LeftStyle;
CSSRect<CSSBorder> m_Border;
CSSRect<sint32> m_Computed;
// font size for 'rem'
float m_RootFontSize;
// font size for 'em'
float m_FontSize;
// if true, then CSSLength values are recomputed
bool m_MustComputeValues;
// viewport element for vw,wh,vmin,vmax
CInterfaceElement* m_Viewport;
// update CSSLength values
void computeValues();
void getAdjacentBorders(EBorderSide side, EBorderSide &adjBorderL, EBorderSide &adjBorderR) const;
void getAdjacentBorderWidth(EBorderSide side, sint32 &adjWidthL, sint32 &adjWidthR) const;
// dot
void buildDotCornerStart(EBorderSide side, SDrawBorder shape, float x1, float y1, float radius);
void buildDotCornerEnd(EBorderSide side, SDrawBorder shape, float x1, float y1, float radius);
void buildDotCorner(SDrawBorder shape, float x, float y, float r, const NLMISC::CLine &line);
// draw circle, angle is CCW between 0..1 (3'o'clock being 0deg).
void buildDotSegments(SDrawBorder shape, float x, float y, float radius, float fromAngle=0.f, float toAngle=1.f);
// dash
void makeBorderQuad(EBorderSide side, SDrawBorder &shape, float x, float y, float width, float thickness) const;
void makeCornerQuad(EBorderSide side, SDrawBorder &shape) const;
void buildDashedBorder(EBorderSide side);
void buildSolidBorder(EBorderSide side);
bool hasInnerShape(CSSLineStyle style) const;
public:
// alpha value from parent
uint8 CurrentAlpha;
@ -68,21 +118,67 @@ namespace NLGUI
void setRect(sint32 x, sint32 y, sint32 w, sint32 h);
void setWidth(uint32 top, uint32 right, uint32 bottom, uint32 left);
void setStyle(CSSLineStyle top, CSSLineStyle right, CSSLineStyle bottom, CSSLineStyle left);
void setColor(const NLMISC::CRGBA &top, const NLMISC::CRGBA &right, const NLMISC::CRGBA &bottom, const NLMISC::CRGBA &left);
void setBorder(const CSSRect<CSSBorder> &b) { m_Dirty = true; m_Border = b; }
void updateCoords();
void invalidateCoords() { _Dirty = _Border = true; }
void invalidateContent() { _Dirty = _Border = true; };
void invalidateCoords() { m_Dirty = true; }
void invalidateContent() { m_Dirty = true; }
bool isEmpty() const {
return (m_Border.Top.Width.getFloat() +
m_Border.Right.Width.getFloat() +
m_Border.Bottom.Width.getFloat() +
m_Border.Left.Width.getFloat()) == 0;
}
uint32 getTopWidth() { if (m_MustComputeValues) computeValues(); return m_Computed.Top; }
uint32 getRightWidth() { if (m_MustComputeValues) computeValues(); return m_Computed.Right; }
uint32 getBottomWidth() { if (m_MustComputeValues) computeValues(); return m_Computed.Bottom; }
uint32 getLeftWidth() { if (m_MustComputeValues) computeValues(); return m_Computed.Left; }
uint32 getLeftRightWidth() { if (m_MustComputeValues) computeValues(); return m_Computed.Left + m_Computed.Right; }
uint32 getTopBottomWidth() { if (m_MustComputeValues) computeValues(); return m_Computed.Top + m_Computed.Bottom; }
NLMISC::CRGBA getTopColor() const { return m_Border.Top.Color; }
NLMISC::CRGBA getRightColor() const { return m_Border.Right.Color; }
NLMISC::CRGBA getBottomColor() const { return m_Border.Bottom.Color; }
NLMISC::CRGBA getLeftColor() const { return m_Border.Left.Color; }
uint32 getTopWidth() const;
uint32 getRightWidth() const;
uint32 getBottomWidth() const;
uint32 getLeftWidth() const;
uint32 getLeftRightWidth() const;
uint32 getTopBottomWidth() const;
void setWidth(uint width)
{
m_Dirty = true;
m_MustComputeValues = true;
m_Border.Top.Width.setFloatValue(width, "px");
m_Border.Right.Width.setFloatValue(width, "px");
m_Border.Bottom.Width.setFloatValue(width, "px");
m_Border.Left.Width.setFloatValue(width, "px");
}
void setColor(const NLMISC::CRGBA &color)
{
m_Dirty = true;
m_Border.Top.Color = color;
m_Border.Right.Color = color;
m_Border.Bottom.Color = color;
m_Border.Left.Color = color;
}
// sizes for em, rem units
void setFontSize(float rootFontSize, float fontSize)
{
m_Dirty = true;
m_MustComputeValues = true;
m_RootFontSize = rootFontSize;
m_FontSize = fontSize;
}
void setViewport(CInterfaceElement *root)
{
m_Dirty = true;
m_MustComputeValues = true;
m_Viewport = root;
}
void draw();
}; // CSSBorderRenderer

@ -0,0 +1,76 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CL_CSS_LENGTH_H
#define CL_CSS_LENGTH_H
#include "nel/misc/types_nl.h"
#include "nel/gui/css_types.h"
namespace NLGUI
{
/**
* \brief CSS types used in GUI classes
* \date 2021-07-02 11:36 GMT
* \author Meelis Mägi (Nimetu)
*/
class CSSLength
{
public:
enum Kind {
Auto, Relative, Fixed
};
CSSLength(float value = 0, CSSUnitType unit = CSS_UNIT_NONE, Kind kind = Auto)
: m_Value(value), m_Unit(unit), m_Kind(Auto)
{}
void setAuto() { m_Kind = Auto; }
bool parseValue(const std::string &value, bool allowPercent = true, bool allowNegative = false);
void setFloatValue(float f, const std::string &unit);
float getValue() const;
float getFloat() const { return m_Value; }
bool isPercent() const { return m_Unit == CSS_UNIT_PERCENT; }
bool isAuto() const { return m_Kind == Auto; }
bool isRelative() const { return m_Kind == Relative; }
// % uses relValue
// em uses emSize
// rem uses remSize
// vw,vh,vi,vb,vmin,vmax uses vwSize/vhSize
float calculate(uint32 relValue, uint32 emSize, uint32 remSize, uint32 vwSize, uint32 whSize) const;
CSSUnitType getUnit() const { return m_Unit; }
std::string toString() const;
private:
void setUnit(const std::string &unit);
float m_Value;
CSSUnitType m_Unit;
Kind m_Kind;
};
}//namespace
#endif // CL_CSS_LENGTH_H

@ -1,5 +1,8 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -38,7 +41,7 @@ namespace NLGUI
private:
// stylesheet currently parsed
ucstring _Style;
std::string _Style;
// keep track of current position in _Style
size_t _Position;
@ -70,49 +73,49 @@ namespace NLGUI
void preprocess();
// parse selectors + combinators
std::vector<CCssSelector> parse_selector(const ucstring &sel, std::string &pseudoElement) const;
std::vector<CCssSelector> parse_selector(const std::string &sel, std::string &pseudoElement, std::string::size_type &pos) const;
// parse selector and style
void parseRule(const ucstring &selectorString, const ucstring &styleString);
void parseRule(const std::string &selectorString, const std::string &styleString);
inline bool is_eof() const
{
return _Position >= _Style.size();
}
inline bool is_whitespace(ucchar ch) const
inline bool is_whitespace(char ch) const
{
return (ch == (ucchar)' ' || ch == (ucchar)'\t' || ch == (ucchar)'\n');
return (ch == ' ' || ch == '\t' || ch == '\n');
}
inline bool is_hex(ucchar ch) const
inline bool is_hex(char ch) const
{
return ((ch >= (ucchar)'0' && ch <= (ucchar)'9') ||
(ch >= (ucchar)'a' && ch <= (ucchar)'f') ||
(ch >= (ucchar)'A' && ch <= (ucchar)'F'));
return ((ch >= '0' && ch <= '9') ||
(ch >= 'a' && ch <= 'f') ||
(ch >= 'A' && ch <= 'F'));
}
inline bool maybe_escape() const
{
// escaping newline (\n) only allowed inside strings
return (_Style.size() - _Position) >= 1 && _Style[_Position] == (ucchar)'\\' && _Style[_Position+1] != '\n';
return (_Style.size() - _Position) >= 1 && _Style[_Position] == '\\' && _Style[_Position+1] != '\n';
}
inline bool is_quote(ucchar ch) const
inline bool is_quote(char ch) const
{
return ch== (ucchar)'"' || ch == (ucchar)'\'';
return ch== '"' || ch == '\'';
}
inline bool is_block_open(ucchar ch) const
inline bool is_block_open(char ch) const
{
return ch == (ucchar)'{' || ch == (ucchar)'[' || ch == (ucchar)'(';
return ch == (char)'{' || ch == (char)'[' || ch == (char)'(';
}
inline bool is_block_close(ucchar ch, ucchar open) const
inline bool is_block_close(char ch, char open) const
{
return ((open == '{' && ch == (ucchar)'}') ||
(open == '[' && ch == (ucchar)']') ||
(open == '(' && ch == (ucchar)')'));
return ((open == '{' && ch == (char)'}') ||
(open == '[' && ch == (char)']') ||
(open == '(' && ch == (char)')'));
}
inline bool is_comment_open() const
@ -120,25 +123,25 @@ namespace NLGUI
if (_Position+1 > _Style.size())
return false;
return _Style[_Position] == (ucchar)'/' && _Style[_Position+1] == (ucchar)'*';
return _Style[_Position] == (char)'/' && _Style[_Position+1] == (char)'*';
}
inline bool is_nonascii(ucchar ch) const
inline bool is_nonascii(char ch) const
{
return ch >= 0x80 /*&& ch <= 255*/;
}
inline bool is_alpha(ucchar ch) const
inline bool is_alpha(char ch) const
{
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
}
inline bool is_digit(ucchar ch) const
inline bool is_digit(char ch) const
{
return ch >= '0' && ch <= '9';
}
inline bool is_nmchar(ucchar ch) const
inline bool is_nmchar(char ch) const
{
// checking escape here does not check if next char is '\n' or not
return ch == '_' || ch == '-' || is_alpha(ch) || is_digit(ch) || is_nonascii(ch) || ch == '\\'/*is_escape(ch)*/;

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -96,6 +96,8 @@ namespace NLGUI
// match An+B rule to child index (1 based)
bool matchNth(sint childNr, sint a, sint b) const;
// match :lang(xx)
bool matchLang(const CHtmlElement &elm, const std::string &pseudo) const;
// parse nth-child string to 'a' and 'b' components
// :nth-child(odd)

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -21,6 +21,9 @@
#include "nel/misc/rgba.h"
#include "nel/gui/css_selector.h"
#include "nel/gui/css_types.h"
#include "nel/gui/css_length.h"
#include "nel/gui/css_background.h"
#include "nel/gui/css_border.h"
namespace NLGUI
{
@ -60,18 +63,15 @@ namespace NLGUI
Underlined=false;
StrikeThrough=false;
GlobalColor=false;
GlobalColorText=false;
DisplayBlock=false;
Width=-1;
Height=-1;
MaxWidth=-1;
MaxHeight=-1;
// border style
BorderTopWidth = BorderRightWidth = BorderBottomWidth = BorderLeftWidth = CSS_LINE_WIDTH_MEDIUM;
BorderTopStyle = BorderRightStyle = BorderBottomStyle = BorderLeftStyle = CSS_LINE_STYLE_NONE;
BorderTopColor = BorderRightColor = BorderBottomColor = BorderLeftColor = NLMISC::CRGBA::Transparent;
// background
BackgroundColor=NLMISC::CRGBA::Black;
BackgroundColorOver=NLMISC::CRGBA::Black;
MarginTop = MarginRight = MarginBottom = MarginLeft = 0;
PaddingTop = PaddingRight = PaddingBottom = PaddingLeft = 0;
}
@ -94,6 +94,7 @@ namespace NLGUI
NLMISC::CRGBA TextColor;
STextShadow TextShadow;
bool GlobalColor;
bool GlobalColorText;
bool Underlined;
bool StrikeThrough;
bool DisplayBlock;
@ -101,11 +102,10 @@ namespace NLGUI
sint32 Height;
sint32 MaxWidth;
sint32 MaxHeight;
uint32 BorderTopWidth, BorderRightWidth, BorderBottomWidth, BorderLeftWidth;
CSSLineStyle BorderTopStyle, BorderRightStyle, BorderBottomStyle, BorderLeftStyle;
NLMISC::CRGBA BorderTopColor, BorderRightColor, BorderBottomColor, BorderLeftColor;
NLMISC::CRGBA BackgroundColor;
CSSRect<CSSBorder> Border;
CSSBackground Background;
NLMISC::CRGBA BackgroundColorOver;
uint32 MarginTop, MarginRight, MarginBottom, MarginLeft;
uint32 PaddingTop, PaddingRight, PaddingBottom, PaddingLeft;
std::string WhiteSpace;
@ -177,16 +177,24 @@ namespace NLGUI
// parse 'padding' into 'padding-top', 'padding-left', etc
void expandPaddingShorthand(const std::string &value, TStyle &style) const;
void expandMarginShorthand(const std::string &value, TStyle &style) const;
// expand shorthand rule, ie "border", into longhand names, ie "border-top-width"
// if shorthand is present in style, then its removed
void expandShorthand(const std::string &prop, const std::string &value, TStyle &style) const;
// parse string value into corresponding value
void applyBorderWidth(const std::string &value, uint32 *dest, const uint32 currentWidth, const uint32 fontSize) const;
void applyBorderWidth(const std::string &value, CSSLength *dest, const CSSLength &currentWidth) const;
void applyBorderColor(const std::string &value, NLMISC::CRGBA *dest, const NLMISC::CRGBA &currentColor, const NLMISC::CRGBA &textColor) const;
void applyLineStyle(const std::string &value, CSSLineStyle *dest, const CSSLineStyle &currentStyle) const;
void applyPaddingWidth(const std::string &value, uint32 *dest, const uint32 currentPadding, uint32 fontSize) const;
void applyMarginWidth(const std::string &value, uint32 *dest, const uint32 current, uint32 fontSize) const;
// parse and replace var(--name, fallback) function
// return false if property should be ignored
bool cssFuncVar(std::string &func, const TStyle &styleRules, const std::set<std::string> &seenProperties) const;
// return false if property was not defined
bool lookupPropertyValue(const std::string &name, std::string &value, const TStyle &styleRules) const;
public:
void reset();
@ -209,15 +217,22 @@ namespace NLGUI
_StyleStack.push_back(Current);
Current.GlobalColor = false;
// inherit GlobalColorText
Current.DisplayBlock = false;
Current.Width=-1;
Current.Height=-1;
Current.MaxWidth=-1;
Current.MaxHeight=-1;
Current.BorderTopWidth = Current.BorderRightWidth = Current.BorderBottomWidth = Current.BorderLeftWidth = CSS_LINE_WIDTH_MEDIUM;
Current.BorderTopStyle = Current.BorderRightStyle = Current.BorderBottomStyle = Current.BorderLeftStyle = CSS_LINE_STYLE_NONE;
Current.BorderTopColor = Current.BorderRightColor = Current.BorderBottomColor = Current.BorderLeftColor = Current.TextColor;
Current.Border.Top.reset();
Current.Border.Right.reset();
Current.Border.Bottom.reset();
Current.Border.Left.reset();
Current.Background = CSSBackground();
Current.BackgroundColorOver = NLMISC::CRGBA::Transparent;
Current.MarginTop = Current.MarginRight = Current.MarginBottom = Current.MarginLeft = 0;
Current.PaddingTop = Current.PaddingRight = Current.PaddingBottom = Current.PaddingLeft = 0;
Current.StyleRules.clear();

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -30,7 +30,12 @@ namespace NLGUI
enum CSSLineStyle {
CSS_LINE_STYLE_NONE = 0,
CSS_LINE_STYLE_HIDDEN,
CSS_LINE_STYLE_DOTTED,
CSS_LINE_STYLE_DASHED,
CSS_LINE_STYLE_SOLID,
CSS_LINE_STYLE_DOUBLE,
CSS_LINE_STYLE_GROOVE,
CSS_LINE_STYLE_RIDGE,
CSS_LINE_STYLE_INSET,
CSS_LINE_STYLE_OUTSET
};
@ -42,6 +47,53 @@ namespace NLGUI
CSS_LINE_WIDTH_THICK = 5
};
enum CSSUnitType {
CSS_UNIT_NONE = 0,
CSS_UNIT_EM,
CSS_UNIT_REM,
CSS_UNIT_PERCENT,
CSS_UNIT_PX,
CSS_UNIT_PT,
CSS_UNIT_VW,
CSS_UNIT_VH,
CSS_UNIT_VI,
CSS_UNIT_VB,
CSS_UNIT_VMIN,
CSS_UNIT_VMAX
};
enum CSSValueType {
CSS_VALUE_NONE = 0,
CSS_VALUE_REPEAT,
CSS_VALUE_SPACE,
CSS_VALUE_ROUND,
CSS_VALUE_NOREPEAT,
CSS_VALUE_FIXED,
CSS_VALUE_LOCAL,
CSS_VALUE_SCROLL,
CSS_VALUE_LEFT,
CSS_VALUE_CENTER,
CSS_VALUE_RIGHT,
CSS_VALUE_TOP,
CSS_VALUE_BOTTOM,
CSS_VALUE_BORDER_BOX,
CSS_VALUE_PADDING_BOX,
CSS_VALUE_CONTENT_BOX,
CSS_VALUE_LENGTH,
CSS_VALUE_AUTO,
CSS_VALUE_COVER,
CSS_VALUE_CONTAIN
};
template<typename T>
struct CSSRect
{
T Top;
T Right;
T Bottom;
T Left;
};
}//namespace
#endif // CL_CSS_TYPES_H

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2015 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -85,9 +86,12 @@ namespace NLGUI
/// Get the ContextHelp for this control. Default is to return _ContextHelp
virtual void getContextHelp(ucstring &help) const {help= _ContextHelp;}
virtual void getContextHelp(std::string &help) const {help= _ContextHelp;}
#ifdef RYZOM_LUA_UCSTRING
virtual void getContextHelpAsUtf16(ucstring &help) const {help.fromUtf8(_ContextHelp);} // Compatibility
#endif
/// Get the ContextHelp for this control, with tooltip specific code. Default behaviour is identical to getContextHelp.
virtual void getContextHelpToolTip(ucstring &help) const { getContextHelp(help); }
virtual void getContextHelpToolTip(std::string &help) const { getContextHelp(help); }
// Get the name of the context help window. Default to "context_help"
virtual std::string getContextHelpWindowName() const;
/// Get the ContextHelp ActionHandler. If "", noop
@ -123,8 +127,12 @@ namespace NLGUI
void setToolTipPosRef(THotSpot pos) { _ToolTipPosRef = pos;}
/// replace the default contextHelp
ucstring getDefaultContextHelp() const {return _ContextHelp;}
void setDefaultContextHelp(const ucstring &help) {_ContextHelp= help;}
std::string getDefaultContextHelp() const {return _ContextHelp;}
void setDefaultContextHelp(const std::string &help) {_ContextHelp= help;}
#ifdef RYZOM_LUA_UCSTRING
ucstring getDefaultContextHelpAsUtf16() const {return ucstring::makeFromUtf8(_ContextHelp);} // Compatibility
void setDefaultContextHelpAsUtf16(const ucstring &help) {_ContextHelp= help.toUtf8();} // Compatibility
#endif
void setOnContextHelp(const std::string &help) {_OnContextHelp= help;}
void setOnContextHelpAHParams(const std::string &p) {_OnContextHelpParams= p;}
@ -154,12 +162,18 @@ namespace NLGUI
// called when keyboard capture has been lost
virtual void onKeyboardCaptureLost() {}
#ifdef RYZOM_LUA_UCSTRING
// 'tooltip' property expects string to be ucstring or latin1 which is not possible from html page
int luaSetTooltipUtf8(CLuaState &ls);
int luaSetTooltipUtf8(CLuaState &ls); // Compatibility
#endif
REFLECT_EXPORT_START(CCtrlBase, CViewBase)
REFLECT_UCSTRING("tooltip", getDefaultContextHelp, setDefaultContextHelp);
REFLECT_LUA_METHOD("setTooltipUtf8", luaSetTooltipUtf8);
#ifdef RYZOM_LUA_UCSTRING
REFLECT_UCSTRING("tooltip", getDefaultContextHelpAsUtf16, setDefaultContextHelpAsUtf16); // Compatibility
REFLECT_LUA_METHOD("setTooltipUtf8", luaSetTooltipUtf8); // Compatibility
#else
REFLECT_STRING("tooltip", getDefaultContextHelp, setDefaultContextHelp);
#endif
REFLECT_EXPORT_END
// special for mouse over : return true and fill the name of the cursor to display
@ -171,7 +185,7 @@ namespace NLGUI
protected:
// This is the ContextHelp filled by default in parse()
ucstring _ContextHelp;
std::string _ContextHelp;
CStringShared _OnContextHelp;
CStringShared _OnContextHelpParams;
CStringShared _ToolTipSpecialParent;

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -96,8 +97,14 @@ namespace NLGUI
bool getTextModulateGlobalColorOver() const {return _TextModulateGlobalColorOver;}
void setTextModulateGlobalColorOver(bool v) {_TextModulateGlobalColorOver= v;}
// Set text (noop if text id)
void setText (const ucstring &text);
ucstring getText () const;
void setText (const std::string &text);
std::string getText () const;
#ifdef RYZOM_LUA_UCSTRING
void setTextAsUtf16 (const ucstring &text); // Compatibility
ucstring getTextAsUtf16 () const; // Compatibility
#endif
void setLocalize (bool localize);
bool isLocalized () const;
void setHardText (const std::string &text);
std::string getHardText () const;
@ -140,8 +147,12 @@ namespace NLGUI
int luaGetViewText(CLuaState &ls);
REFLECT_EXPORT_START(CCtrlTextButton, CCtrlBaseButton)
REFLECT_UCSTRING("uc_hardtext", getText, setText);
#ifdef RYZOM_LUA_UCSTRING
REFLECT_UCSTRING("uc_hardtext", getTextAsUtf16, setTextAsUtf16); // Compatibility
#endif
REFLECT_BOOL("localize", isLocalized, setLocalize);
REFLECT_STRING("hardtext", getHardText, setHardText);
REFLECT_STRING("text", getText, setText);
REFLECT_SINT32("text_x", getTextX, setTextX)
REFLECT_SINT32("wmargin", getWMargin, setWMargin)
REFLECT_SINT32("wmin", getWMin, setWMin)

@ -1,9 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2015-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -60,13 +60,19 @@ namespace NLGUI
// Combo Texts
void resetTexts();
void addText(const ucstring &text);
void setText(uint i, const ucstring &text);
void insertText(uint i, const ucstring &text);
const ucstring &getText(uint i) const;
void addText(const std::string &text);
void setText(uint i, const std::string &text);
void insertText(uint i, const std::string &text);
const std::string &getText(uint i) const;
#ifdef RYZOM_LUA_UCSTRING
ucstring getTextAsUtf16(uint i) const; // Compatibility
#endif
uint getTextId(uint i) const;
uint getTextPos(uint nId) const;
const ucstring &getTexture(uint i) const;
const std::string &getTexture(uint i) const;
#ifdef RYZOM_LUA_UCSTRING
ucstring getTextureAsUtf16(uint i) const; // Compatibility
#endif
void setGrayed(uint i, bool g);
bool getGrayed(uint i) const;
void removeText(uint nPos);
@ -87,11 +93,15 @@ namespace NLGUI
std::string getSelectionText() const;
// view text
void setViewText(const ucstring & text);
ucstring getViewText() const;
void setViewText(const std::string & text);
std::string getViewText() const;
#ifdef RYZOM_LUA_UCSTRING
void setViewTextAsUtf16(const ucstring &text) { setViewText(text.toUtf8()); } // Compatibility
ucstring getViewTextAsUtf16() const; // Compatibility
#endif
CViewText *getViewText();
void setTexture(uint i, const ucstring &texture);
void setTexture(uint i, const std::string &texture);
sint32 evalContentWidth() const;
@ -122,7 +132,11 @@ namespace NLGUI
REFLECT_LUA_METHOD("resetTexts", luaResetTexts)
REFLECT_SINT32 ("selectionNb", getSelectionNb, setSelectionNb)
REFLECT_STRING ("selection_text", getSelectionText, setSelectionText)
REFLECT_UCSTRING ("view_text", getViewText, setViewText)
#ifdef RYZOM_LUA_UCSTRING
REFLECT_UCSTRING ("view_text", getViewTextAsUtf16, setViewTextAsUtf16) // Compatibility
#else
REFLECT_STRING ("view_text", getViewText, setViewText)
#endif
REFLECT_EXPORT_END
@ -137,8 +151,8 @@ namespace NLGUI
// sint32
CInterfaceProperty _Selection;
sint32 _NotLinkedToDBSelection;
std::vector<std::pair<uint, ucstring> > _Texts;
std::vector<ucstring> _Textures;
std::vector<std::pair<uint, std::string> > _Texts;
std::vector<std::string> _Textures;
std::vector<bool> _Grayed;
// Action Handler called on combo click
@ -155,7 +169,7 @@ namespace NLGUI
CCtrlBaseButton *_SelectButton;
bool _IsExternViewText;
ucstring _ExternViewText;
std::string _ExternViewText;
private:

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -57,7 +58,7 @@ namespace NLGUI
CInterfaceProperty _NumberMax;
sint32 _Cache;
sint32 _CacheMax;
ucstring _EmptyText;
std::string _EmptyText;
void buildTextFromCache();
};

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2020 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -60,7 +61,7 @@ public:
keydown = 0, // a key has been press down. The key value is stored as a TKey
keyup, // a key has been released. The key value is stored as a TKey
keychar, // a key has been stroke. The key is a ucchar
keystring, // a string has been sent. The string is a ucstring
keystring, // a string has been sent. The string is a utf-8 string
unknown, // uninitialized event
};
CEventDescriptorKey() : _KeyEvent(unknown), _CtrlState(false), _ShiftState(false), _AltState(false), _Char(0)
@ -82,13 +83,13 @@ public:
return _Key;
}
// return the char that has been pressed. The key event type MUST be 'keychar', else => assert
ucchar getChar() const
u32char getChar() const
{
nlassert(_KeyEvent == keychar);
return _Char;
}
// return the string that has been sent. The key event type MUST be 'keystring', else => assert
ucstring getString() const
std::string getString() const
{
nlassert(_KeyEvent == keystring);
return _String;
@ -141,9 +142,9 @@ private:
union
{
NLMISC::TKey _Key;
ucchar _Char;
u32char _Char;
};
ucstring _String;
std::string _String;
};
// ----------------------------------------------------------------------------

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -248,12 +249,14 @@ namespace NLGUI
// Get the header color draw. NB: depends if grayed, and if active.
NLMISC::CRGBA getDrawnHeaderColor () const;
ucstring getUCTitleOpened () const;
void setUCTitleOpened (const ucstring &title);
ucstring getUCTitleClosed () const;
void setUCTitleClosed (const ucstring &title);
ucstring getUCTitle () const;
void setUCTitle (const ucstring &title);
#ifdef RYZOM_LUA_UCSTRING
ucstring getUCTitleOpened () const; // Compatibility
void setUCTitleOpened (const ucstring &title); // Compatibility
ucstring getUCTitleClosed () const; // Compatibility
void setUCTitleClosed (const ucstring &title); // Compatibility
ucstring getUCTitle () const; // Compatibility
void setUCTitle (const ucstring &title); // Compatibility
#endif
void setPopable(bool popable) { _Popable = popable; }
bool isPopable() const { return _Popable; }
@ -287,9 +290,13 @@ namespace NLGUI
REFLECT_STRING("title", getTitle, setTitle);
REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened);
REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed);
REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened);
REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed);
REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle);
#ifdef RYZOM_LUA_UCSTRING
REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened); // Compatibility
REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); // Compatibility
REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); // Compatibility
#endif
REFLECT_STRING("title_color", getTitleColorAsString, setTitleColorAsString);
REFLECT_SINT32("pop_min_h", getPopupMinH, setPopupMinH);
REFLECT_SINT32("pop_max_h", getPopupMaxH, setPopupMaxH);
@ -302,6 +309,8 @@ namespace NLGUI
REFLECT_BOOL("lockable", isLockable, setLockable);
REFLECT_BOOL("locked", isLocked, setLocked);
REFLECT_BOOL("localize", isLocalize, setLocalize);
REFLECT_BOOL("header_active", getHeaderActive, setHeaderActive);
REFLECT_BOOL("right_button_enabled", getRightButtonEnabled, setRightButtonEnabled);
REFLECT_EXPORT_END
@ -364,7 +373,7 @@ namespace NLGUI
bool isActiveSavable() const { return _ActiveSavable; }
bool isLocalize() const { return _Localize; }
void setLocalize(bool localize) { _Localize = localize; }
void setLocalize(bool localize);
void setPopupX(sint32 x) { _PopupX = x; }
void setPopupY(sint32 y) { _PopupY = y; }
@ -477,8 +486,8 @@ namespace NLGUI
float _CurrentRolloverAlphaContainer;
float _CurrentRolloverAlphaContent;
sint32 _LayerSetup;
ucstring _TitleTextOpened;
ucstring _TitleTextClosed;
std::string _TitleTextOpened;
std::string _TitleTextClosed;
CViewText *_TitleOpened;
CViewText *_TitleClosed;
sint32 _TitleDeltaMaxW;
@ -636,6 +645,9 @@ namespace NLGUI
TTileClass convertTitleClass(const char *ptr);
void setTitledOpenedViewText();
void setTitledClosedViewText();
static COptionsContainerMove *getMoveOptions();
COptionsLayer *getContainerOptions(sint32 ls=-1); // Depends if overload by OptionsName or default used

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2014 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2017 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -63,26 +64,29 @@ namespace NLGUI
virtual bool handleEvent (const NLGUI::CEventDescriptor& eventDesc);
/// Accessors
ucstring getInputString() const { return _InputString; }
const ucstring &getInputStringRef() const { return _InputString; }
const ucstring &getPrompt() const { return _Prompt; }
std::string getInputString() const;
std::string getPrompt() const;
const ::u32string &getInputStringRef() const { return _InputString; }
const ::u32string &getPromptRef() const { return _Prompt; }
/** Set the prompt
* NB : line returns are encoded as '\n', not '\r\n'
*/
void setPrompt(const ucstring &s) { _Prompt = s; }
void setInputString(const ucstring &str);
void setInputStringRef(const ucstring &str) {_InputString = str; };
void setPrompt(const std::string &s);
void setInputString(const std::string &str);
void setInputStringRef(const ::u32string &str);
void setInputStringAsInt(sint32 val);
sint32 getInputStringAsInt() const;
void setInputStringAsInt64(sint64 val);
sint64 getInputStringAsInt64() const;
void setInputStringAsFloat(float val);
float getInputStringAsFloat() const;
void setInputStringAsStdString(const std::string &str);
std::string getInputStringAsStdString() const;
void setInputStringAsUtf8(const std::string &str);
std::string getInputStringAsUtf8() const;
#ifdef RYZOM_LUA_UCSTRING
void setInputStringAsUtf16(const ucstring &str); // Compatibility
ucstring getInputStringAsUtf16() const; // Compatibility
void setInputStringAsUtf32(const ::u32string &str) { setInputStringRef(str); } // Compatibility
::u32string getInputStringAsUtf32() const { return _InputString; } // Compatibility
#endif
void setColor(NLMISC::CRGBA col);
@ -97,7 +101,7 @@ namespace NLGUI
static CGroupEditBox *getMenuFather() { return _MenuFather; }
void setCommand(const ucstring &command, bool execute);
void setCommand(const std::string &command, bool execute);
// Stop parent from blinking
void stopParentBlink() { if (_Parent) _Parent->disableBlink(); }
@ -121,7 +125,7 @@ namespace NLGUI
sint32 getMaxHistoric() const {return _MaxHistoric;}
sint32 getCurrentHistoricIndex () const {return _CurrentHistoricIndex;}
void setCurrentHistoricIndex (sint32 index) {_CurrentHistoricIndex=index;}
const ucstring &getHistoric(uint32 index) const {return _Historic[index];}
const ::u32string &getHistoric(uint32 index) const {return _Historic[index];}
uint32 getNumHistoric() const {return (uint32)_Historic.size ();}
// Get on change action handler
@ -139,7 +143,7 @@ namespace NLGUI
// Paste the selection into buffer
void paste();
// Write the string into buffer
void writeString(const ucstring &str, bool replace = true, bool atEnd = true);
void writeString(const std::string &str, bool replace = true, bool atEnd = true);
// Expand the expression (true if there was a '/' at the start of the line)
bool expand();
@ -170,7 +174,7 @@ namespace NLGUI
virtual void onKeyboardCaptureLost();
// set the input string as "default". will be reseted at first click (used for user information)
void setDefaultInputString(const ucstring &str);
void setDefaultInputString(const std::string &str);
// For Interger and PositiveInteger, can specify min and max values
void setIntegerMinValue(sint32 minValue) {_IntegerMinValue=minValue;}
@ -189,8 +193,10 @@ namespace NLGUI
REFLECT_LUA_METHOD("setSelectionAll", luaSetSelectionAll);
REFLECT_LUA_METHOD("setFocusOnText", luaSetFocusOnText);
REFLECT_LUA_METHOD("cancelFocusOnText", luaCancelFocusOnText);
REFLECT_STRING("input_string", getInputStringAsStdString, setInputStringAsStdString);
REFLECT_UCSTRING("uc_input_string", getInputString, setInputString);
REFLECT_STRING("input_string", getInputString, setInputString);
#ifdef RYZOM_LUA_UCSTRING
REFLECT_UCSTRING("uc_input_string", getInputStringAsUtf16, setInputStringAsUtf16); // Compatibility
#endif
REFLECT_EXPORT_END
/** Restore the original value of the edit box.
@ -215,6 +221,7 @@ namespace NLGUI
float _BlinkTime;
sint32 _CursorPos;
uint32 _MaxNumChar;
uint32 _MaxNumBytes;
uint32 _MaxNumReturn;
uint32 _MaxFloatPrec; // used in setInputStringAsFloat() only
sint32 _MaxCharsSize;
@ -228,17 +235,17 @@ namespace NLGUI
NLMISC::CRGBA _BackSelectColor;
// Text info
ucstring _Prompt;
ucstring _InputString;
::u32string _Prompt;
::u32string _InputString;
CViewText *_ViewText;
// undo / redo
ucstring _StartInputString; // value of the input string when focus was acuired first
ucstring _ModifiedInputString;
::u32string _StartInputString; // value of the input string when focus was acuired first
::u32string _ModifiedInputString;
// Historic info
typedef std::deque<ucstring> THistoric;
typedef std::deque<::u32string> THistoric;
THistoric _Historic;
uint32 _MaxHistoric;
sint32 _CurrentHistoricIndex;
@ -275,7 +282,7 @@ namespace NLGUI
bool _CanRedo : 1;
bool _CanUndo : 1;
std::vector<char> _NegativeFilter;
std::vector<u32char> _NegativeFilter;
sint _CursorTexID;
sint32 _CursorWidth;
@ -298,13 +305,13 @@ namespace NLGUI
void handleEventString(const NLGUI::CEventDescriptorKey &event);
void setup();
void triggerOnChangeAH();
void appendStringFromClipboard(const ucstring &str);
void appendStringFromClipboard(const std::string &str);
ucstring getSelection();
std::string getSelection();
static CGroupEditBox *_MenuFather;
static bool isValidAlphaNumSpace(ucchar c)
static bool isValidAlphaNumSpace(u32char c)
{
if (c > 255) return false;
char ac = (char) c;
@ -314,7 +321,7 @@ namespace NLGUI
ac==' ';
}
static bool isValidAlphaNum(ucchar c)
static bool isValidAlphaNum(u32char c)
{
if (c > 255) return false;
char ac = (char) c;
@ -323,7 +330,7 @@ namespace NLGUI
(ac >= 'A' && ac <= 'Z');
}
static bool isValidAlpha(ucchar c)
static bool isValidAlpha(u32char c)
{
if (c > 255) return false;
char ac = (char) c;
@ -331,13 +338,13 @@ namespace NLGUI
(ac >= 'A' && ac <= 'Z');
}
static bool isValidPlayerNameChar(ucchar c)
static bool isValidPlayerNameChar(u32char c)
{
// valid player name (with possible shard prefix / suffix format
return isValidAlpha(c) || c=='.' || c=='(' || c==')';
}
static bool isValidFilenameChar(ucchar c)
static bool isValidFilenameChar(u32char c)
{
if (c == '\\' ||
c == '/' ||
@ -351,12 +358,12 @@ namespace NLGUI
return true;
}
//
bool isFiltered(ucchar c)
bool isFiltered(u32char c)
{
uint length = (uint)_NegativeFilter.size();
for (uint k = 0; k < length; ++k)
ptrdiff_t length = _NegativeFilter.size();
for (ptrdiff_t k = 0; k < length; ++k)
{
if ((ucchar) _NegativeFilter[k] == c) return true;
if (_NegativeFilter[k] == c) return true;
}
return false;
}

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010-2019 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2019-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -29,12 +30,14 @@
#include "nel/gui/html_element.h"
#include "nel/gui/html_parser.h"
#include "nel/gui/css_style.h"
#include "nel/gui/css_background_renderer.h"
// forward declaration
typedef void CURLM;
namespace NLGUI
{
class CViewLink;
class CCtrlButton;
class CCtrlTextButton;
class CCtrlScroll;
@ -45,6 +48,20 @@ namespace NLGUI
extern std::string CurrentCookie;
class ICurlDownloadCB
{
public:
ICurlDownloadCB(const std::string &url)
: url(url)
{}
virtual ~ICurlDownloadCB() {};
virtual void finish() = 0;
std::string url;
};
// HTML group
/**
* Widget to have a resizable scrolltext and its scrollbar
@ -131,9 +148,9 @@ namespace NLGUI
void endParagraph();
// add image download (used by view_bitmap.cpp to load web images)
void addImageDownload(const std::string &url, CViewBase *img, const CStyleParams &style = CStyleParams(), const TImageType type = NormalImage, const std::string &placeholder = "web_del.tga");
// remove image from download list if present
void removeImageDownload(CViewBase *img);
ICurlDownloadCB *addImageDownload(const std::string &url, CViewBase *img, const CStyleParams &style = CStyleParams(), const TImageType type = NormalImage, const std::string &placeholder = "web_del.tga");
ICurlDownloadCB *addTextureDownload(const std::string &url, sint32 &texId, CViewBase *view);
void removeImageDownload(ICurlDownloadCB *handle, CViewBase *img);
std::string localImageName(const std::string &url);
// Timeout
@ -141,37 +158,15 @@ namespace NLGUI
float getTimeout() const {return (float)_TimeoutValue;}
// Some constants
NLMISC::CRGBA BgColor;
NLMISC::CRGBA ErrorColor;
NLMISC::CRGBA LinkColor;
NLMISC::CRGBA TextColor;
NLMISC::CRGBA H1Color;
NLMISC::CRGBA H2Color;
NLMISC::CRGBA H3Color;
NLMISC::CRGBA H4Color;
NLMISC::CRGBA H5Color;
NLMISC::CRGBA H6Color;
bool ErrorColorGlobalColor;
bool LinkColorGlobalColor;
bool TextColorGlobalColor;
bool H1ColorGlobalColor;
bool H2ColorGlobalColor;
bool H3ColorGlobalColor;
bool H4ColorGlobalColor;
bool H5ColorGlobalColor;
bool H6ColorGlobalColor;
uint TextFontSize;
uint H1FontSize;
uint H2FontSize;
uint H3FontSize;
uint H4FontSize;
uint H5FontSize;
uint H6FontSize;
uint TDBeginSpace;
uint PBeginSpace;
uint LIBeginSpace;
uint ULBeginSpace;
uint LIIndent;
uint ULIndent;
float LineSpaceFontFactor;
std::string DefaultButtonGroup;
@ -185,8 +180,8 @@ namespace NLGUI
std::string DefaultRadioButtonBitmapNormal;
std::string DefaultRadioButtonBitmapPushed;
std::string DefaultRadioButtonBitmapOver;
// TODO: remove from interface xml and code
std::string DefaultBackgroundBitmapView;
std::string CurrentLinkTitle;
struct TFormField {
public:
@ -324,16 +319,22 @@ namespace NLGUI
void clearContext();
// Translate a char
bool translateChar(ucchar &output, ucchar input, ucchar lastChar) const;
bool translateChar(u32char &output, u32char input, u32char lastChar) const;
// return true if text has same style
bool isSameStyle(CViewLink *text, const CStyleParams &style) const;
// add text link using template
void newTextButton(const std::string &text, const std::string &tpl);
void newTextLink(const std::string &text);
// Add a string in the current paragraph
void addString(const ucstring &str);
void addString(const std::string &str);
// Add an image in the current paragraph
void addImage(const std::string &id, const std::string &img, bool reloadImg=false, const CStyleParams &style = CStyleParams());
// Add a text area in the current paragraph
CInterfaceGroup *addTextArea (const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const ucstring &content, uint maxlength);
CInterfaceGroup *addTextArea (const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const std::string &content, uint maxlength);
// Add a combo box in the current paragraph
CDBGroupComboBox *addComboBox(const std::string &templateName, const char *name);
@ -344,6 +345,9 @@ namespace NLGUI
const std::string &overBitmap, const char *actionHandler, const char *actionHandlerParams, const std::string &tooltip,
const CStyleParams &style = CStyleParams());
// Set the background color
void setupBackground(CSSBackgroundRenderer *bg);
// Set the background color
void setBackgroundColor (const NLMISC::CRGBA &bgcolor);
@ -354,9 +358,9 @@ namespace NLGUI
void flushString();
// Set the title
void setTitle (const ucstring &title);
void setTitle (const std::string &title);
std::string getTitle() const;
void setContainerTitle (const std::string &title);
// Lookup a url in local file system
bool lookupLocalFile (std::string &result, const char *url, bool isUrl);
@ -383,6 +387,13 @@ namespace NLGUI
// <style> and downloaded <link rel=stylesheet> elements
std::vector<std::string> _HtmlStyles;
// background from <html> or <body> element
CSSBackgroundRenderer m_HtmlBackground;
CSSBackgroundRenderer m_BodyBackground;
// active table.tr background color from css or from bgcolor attribute
std::vector<NLMISC::CRGBA> m_TableRowBackgroundColor;
// Valid base href was found
bool _IgnoreBaseUrlTag;
// Fragment from loading url
@ -398,10 +409,10 @@ namespace NLGUI
bool _TrustedDomain;
// Title prefix
ucstring _TitlePrefix;
std::string _TitlePrefix;
// Title string
ucstring _TitleString;
std::string _TitleString;
// Need to browse next update coords..
bool _BrowseNextTime;
@ -650,7 +661,7 @@ namespace NLGUI
std::string Name;
// Variable value
ucstring Value;
std::string Value;
// Text area group
CInterfaceGroup *TextArea;
@ -751,9 +762,7 @@ namespace NLGUI
bool _Localize;
// Current node is a text area
bool _TextArea;
std::string _TextAreaTemplate;
ucstring _TextAreaContent;
std::string _TextAreaName;
uint _TextAreaRow;
uint _TextAreaCols;
@ -761,7 +770,7 @@ namespace NLGUI
// current mode is in select option
bool _SelectOption;
ucstring _SelectOptionStr;
std::string _SelectOptionStr;
// Current node is a object
std::string _ObjectType;
@ -771,7 +780,7 @@ namespace NLGUI
std::string _TextAreaScript;
// Get last char
ucchar getLastChar() const;
u32char getLastChar() const;
// Current link view
class CViewLink *_CurrentViewLink;
@ -832,50 +841,110 @@ namespace NLGUI
void spliceFragment(std::list<CHtmlElement>::iterator src);
// decode all HTML entities
static ucstring decodeHTMLEntities(const ucstring &str);
static std::string decodeHTMLEntities(const std::string &str);
struct CDataImageDownload
class CDataDownload : public ICurlDownloadCB
{
public:
CDataImageDownload(CViewBase *img, CStyleParams style, TImageType type): Image(img), Style(style), Type(type)
CDataDownload(const std::string &u, const std::string &d)
: ICurlDownloadCB(u), data(NULL), fp(NULL), dest(d), redirects(0), ConnectionTimeout(60)
{}
virtual ~CDataDownload();
public:
CCurlWWWData *data;
std::string dest;
std::string tmpdest;
uint32 redirects;
FILE *fp;
uint32 ConnectionTimeout;
};
class StylesheetDownloadCB : public CDataDownload
{
}
public:
StylesheetDownloadCB(const std::string &url, const std::string &dest, CGroupHTML *parent)
: CDataDownload(url, dest), Parent(parent)
{}
virtual void finish() NL_OVERRIDE;
private:
CGroupHTML *Parent;
};
class ImageDownloadCB : public CDataDownload
{
public:
struct SImageInfo
{
SImageInfo(CViewBase *img, const CStyleParams &style, TImageType type)
: Image(img), Style(style), Type(type)
{}
CViewBase *Image;
CStyleParams Style;
TImageType Type;
};
struct CDataDownload
ImageDownloadCB(const std::string &url, const std::string &dest, CViewBase *img, const CStyleParams &style, TImageType type, CGroupHTML *parent)
: CDataDownload(url, dest), Parent(parent)
{
addImage(img, style, type);
}
virtual void finish() NL_OVERRIDE;
void addImage(CViewBase *img, const CStyleParams &style, TImageType type);
void removeImage(CViewBase *img);
private:
std::vector<SImageInfo> Images;
CGroupHTML *Parent;
CStyleParams Style;
TImageType Type;
};
class TextureDownloadCB : public CDataDownload
{
public:
CDataDownload(const std::string &u, const std::string &d, TDataType t, CViewBase *i, const std::string &s, const std::string &m, const CStyleParams &style = CStyleParams(), const TImageType imagetype = NormalImage)
: data(NULL), fp(NULL), url(u), dest(d), type(t), luaScript(s), md5sum(m), redirects(0), ConnectionTimeout(60)
TextureDownloadCB(const std::string &url, const std::string &dest, sint32 texId, CViewBase *view)
: CDataDownload(url, dest)
{
if (t == ImgType) imgs.push_back(CDataImageDownload(i, style, imagetype));
addTexture(texId, view);
}
virtual void finish() NL_OVERRIDE;
void addTexture(sint32 texId, CViewBase *view) {
TextureIds.push_back(std::make_pair(texId, view));
}
~CDataDownload();
private:
std::vector<std::pair<sint32, CViewBase *> > TextureIds;
};
class BnpDownloadCB : public CDataDownload
{
public:
CCurlWWWData *data;
std::string url;
std::string dest;
std::string tmpdest;
std::string luaScript;
std::string md5sum;
TDataType type;
uint32 redirects;
FILE *fp;
std::vector<CDataImageDownload> imgs;
uint32 ConnectionTimeout;
BnpDownloadCB(const std::string &url, const std::string &dest, const std::string md5sum, const std::string lua, CGroupHTML *parent)
: CDataDownload(url, dest), Parent(parent), m_md5sum(md5sum), m_lua(lua)
{}
virtual void finish() NL_OVERRIDE;
private:
CGroupHTML *Parent;
std::string m_md5sum;
std::string m_lua;
};
std::list<CDataDownload> Curls;
std::list<CDataDownload*> Curls;
CURLM *MultiCurl;
int RunningCurls;
bool startCurlDownload(CDataDownload &download);
void finishCurlDownload(const CDataDownload &download);
bool startCurlDownload(CDataDownload *download);
void finishCurlDownload(CDataDownload *download);
void pumpCurlQueue();
void initImageDownload();
@ -905,7 +974,7 @@ namespace NLGUI
// _CurlWWW download finished
void htmlDownloadFinished(bool success, const std::string &error);
// images, stylesheets, etc finished downloading
void dataDownloadFinished(bool success, const std::string &error, CDataDownload &data);
void dataDownloadFinished(bool success, const std::string &error, CDataDownload *data);
// HtmlType download finished
void htmlDownloadFinished(const std::string &content, const std::string &type, long code);
@ -922,9 +991,6 @@ namespace NLGUI
// :before, :after rendering
void renderPseudoElement(const std::string &pseudo, const CHtmlElement &elm);
// apply background from current style (for html, body)
void applyBackground(const CHtmlElement &elm);
void insertFormImageButton(const std::string &name,
const std::string &tooltip,
const std::string &src,
@ -1004,11 +1070,9 @@ namespace NLGUI
void htmlTD(const CHtmlElement &elm);
void htmlTDend(const CHtmlElement &elm);
void htmlTEXTAREA(const CHtmlElement &elm);
void htmlTEXTAREAend(const CHtmlElement &elm);
void htmlTH(const CHtmlElement &elm);
void htmlTHend(const CHtmlElement &elm);
void htmlTITLE(const CHtmlElement &elm);
void htmlTITLEend(const CHtmlElement &elm);
void htmlTR(const CHtmlElement &elm);
void htmlTRend(const CHtmlElement &elm);
//void htmlU(const CHtmlElement &elm);

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -67,13 +68,13 @@ namespace NLGUI
* \param line : text to be added
* \param color : text color
*/
void addTextChild (const ucstring& line,const NLMISC::CRGBA &textColor, bool multiLine = true);
void addTextChild (const std::string& line,const NLMISC::CRGBA &textColor, bool multiLine = true);
/**
* add a text child element to the group, using the text template
* \param line : text to be added
*/
void addTextChild (const ucstring& line, bool multiLine = true);
void addTextChild (const std::string& line, bool multiLine = true);
/// Same as adding a text child but the text will be taken from the string manager
void addTextChildID (uint32 id, bool multiLine = true);

@ -3,7 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -122,12 +122,12 @@ namespace NLGUI
// retrieve the index of a line from its id (-1 if not found)
sint getLineFromId(const std::string &id);
CViewTextMenu* addLine (const ucstring &name, const std::string &ah,
CViewTextMenu* addLine (const std::string &name, const std::string &ah,
const std::string &params, const std::string &id="",
const std::string &cond = std::string(), const std::string &texture="",
bool checkable = false, bool checked = false, bool formatted = false
);
CViewTextMenu* addLineAtIndex(uint index, const ucstring &name, const std::string &ah,
CViewTextMenu* addLineAtIndex(uint index, const std::string &name, const std::string &ah,
const std::string &params, const std::string &id="",
const std::string &cond = std::string(), const std::string &texture="",
bool checkable = false, bool checked = false, bool formatted = false
@ -333,11 +333,6 @@ namespace NLGUI
virtual bool isWindowUnder (sint32 x, sint32 y);
// add line with a string, for backward compatibility
void addLine (const std::string &name, const std::string &ah, const std::string &params,
const std::string &id = std::string(),
const std::string &cond = std::string(), const std::string &texture="",
bool checkable = false, bool checked = false);
uint getNumLine() const;
void deleteLine(uint index);
const std::string getActionHandler(uint lineIndex) const;
@ -350,12 +345,12 @@ namespace NLGUI
void setRightClickHandler(uint lineIndex, const std::string &ah = "");
void setRightClickHandlerParam(uint lineIndex, const std::string &params = "");
void addLine (const ucstring &name, const std::string &ah = "", const std::string &params = "",
void addLine (const std::string &name, const std::string &ah = "", const std::string &params = "",
const std::string &id = std::string(),
const std::string &cond = std::string(), const std::string &texture="",
bool checkable = false, bool checked = false
);
void addLineAtIndex (uint index, const ucstring &name, const std::string &ah = "", const std::string &params = "",
void addLineAtIndex (uint index, const std::string &name, const std::string &ah = "", const std::string &params = "",
const std::string &id = std::string(),
const std::string &cond = std::string(), const std::string &texture="",
bool checkable = false, bool checked = false

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -86,13 +87,13 @@ namespace NLGUI
* \param line : text to be added
* \param color : text color
*/
void addTextChild (const ucstring& line,const NLMISC::CRGBA &textColor, bool multiLine = true);
void addTextChild (const std::string& line,const NLMISC::CRGBA &textColor, bool multiLine = true);
/**
* add a text child element to the group, using the text template
* \param line : text to be added
*/
void addTextChild (const ucstring& line, bool multiLine = true);
void addTextChild (const std::string& line, bool multiLine = true);
/// Same as adding a text child but the text will be taken from the string manager
void addTextChildID (uint32 id, bool multiLine = true);

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2015 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
@ -31,6 +31,7 @@
namespace NLGUI
{
class CSSBorderRenderer;
class CSSBackgroundRenderer;
/**
* This group is used to simulate HTML cells.
@ -94,22 +95,10 @@ namespace NLGUI
// Memorize max width
sint32 WidthMax;
// The cell color
NLMISC::CRGBA BgColor;
CSSBorderRenderer* Border;
CSSBackgroundRenderer *Background;
uint32 PaddingTop, PaddingRight, PaddingBottom, PaddingLeft;
// Texture
CViewRenderer::CTextureId _TextureId;
bool _TextureTiled;
bool _TextureScaled;
// cached absolute coords for background texture
sint32 _TextureXReal;
sint32 _TextureYReal;
sint32 _TextureWReal;
sint32 _TextureHReal;
// Alignment
TAlign Align;
TVAlign VAlign;
@ -121,6 +110,7 @@ namespace NLGUI
// The cell is nowrap
bool NoWrap;
// deprecated background image
void setTexture(const std::string & TxName);
void setTextureTile(bool tiled);
void setTextureScale(bool scaled);
@ -134,8 +124,6 @@ namespace NLGUI
static bool getDebugUICell(){ return DebugUICell; }
private:
void updateTextureCoords();
void setEnclosedGroupDefaultParams();
static bool DebugUICell;
};
@ -164,18 +152,18 @@ namespace NLGUI
sint32 ForceWidthMin;
CSSBorderRenderer* Border;
CSSBackgroundRenderer *Background;
// Cell has 1px solid border when <table> has 'border' attribute with width > 0
bool CellBorder;
sint32 CellPadding;
sint32 CellSpacing;
// The table color
NLMISC::CRGBA BgColor;
uint8 CurrentAlpha;
bool ContinuousUpdate;
// deprecated background image
void setTexture(const std::string & TxName);
void setTextureTile(bool tiled);
void setTextureScale(bool scaled);
@ -201,18 +189,6 @@ namespace NLGUI
virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup);
// Texture
CViewRenderer::CTextureId _TextureId;
bool _TextureTiled;
bool _TextureScaled;
// cached absolute coords for background texture
sint32 _TextureXReal;
sint32 _TextureYReal;
sint32 _TextureWReal;
sint32 _TextureHReal;
void updateTextureCoords();
// Content validated
bool _ContentValidated;

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2017 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -60,7 +61,7 @@ namespace NLGUI
bool Show; // If false, the node is not displayed (true default, Root ignored)
sint32 YDecal;
// Text
ucstring Text; // Internationalized displayed text
std::string Text; // Internationalized displayed text
sint32 FontSize; // If -1 (default), then take the groupTree one
NLMISC::CRGBA Color;
// Template
@ -112,8 +113,12 @@ namespace NLGUI
std::string getBitmap() const { return Bitmap; }
void setOpened(bool opened) { Opened = opened; }
bool getOpened() const { return Opened; }
void setText(const ucstring &text) { Text = text; }
const ucstring& getText() const { return Text; }
void setText(const std::string &text) { Text = text; }
const std::string& getText() const { return Text; }
#ifdef RYZOM_LUA_UCSTRING
void setTextAsUtf16(const ucstring &text) { Text = text.toUtf8(); } // Compatibility
ucstring getTextAsUtf16() const { return ucstring::makeFromUtf8(Text); } // Compatibility
#endif
sint32 getFontSize() const { return FontSize; }
void setFontSize(sint32 value) { FontSize = value; }
sint32 getYDecal() const { return YDecal; }
@ -181,7 +186,11 @@ namespace NLGUI
REFLECT_STRING("AHParamsClose", getAHParamsClose, setAHParamsClose);
REFLECT_BOOL("Opened", getOpened, setOpened);
REFLECT_BOOL("Show", getShow, setShow);
REFLECT_UCSTRING_REF("Text", getText, setText);
#ifdef RYZOM_LUA_UCSTRING
REFLECT_UCSTRING("Text", getTextAsUtf16, setTextAsUtf16); // Compatibility
#else
REFLECT_STRING_REF("Text", getText, setText);
#endif
// lua
REFLECT_LUA_METHOD("getNumChildren", luaGetNumChildren);
REFLECT_LUA_METHOD("getChild", luaGetChild);

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -75,6 +75,18 @@ namespace NLGUI
// update Children index/parent/next/prevSibling pointers
void reindexChilds();
// escape text tag or attribute value
std::string htmlEscape(std::string val, bool isAttribute = false) const;
// serialize element attributes as string
std::string serializeAttributes() const;
// serialize child elements as html string
std::string serializeChilds() const;
// serialize itself and children as html string
std::string serialize() const;
// debug
std::string toString(bool tree = false, uint depth = 0) const;
@ -84,6 +96,9 @@ namespace NLGUI
TStyle getPseudo(const std::string &key) const;
void setPseudo(const std::string &key, const TStyle &style);
// return lang property for css :lang() pseudo class
std::string getInheritedLanguage() const;
private:
// pseudo elements like ":before" and ":after"
std::map<std::string, TStyle> _Pseudo;

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2021 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -19,6 +19,9 @@
#include "nel/misc/types_nl.h"
// Forward declarations for libxml2
typedef struct _xmlNode xmlNode;
namespace NLGUI
{
class CHtmlElement;

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2017 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2017 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2018 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>

@ -1,8 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2018 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -59,16 +60,15 @@ namespace NLGUI
bool getBool() const;
sint64 getInteger() const;
double getDouble() const;
std::string getString() const;
const std::string &getString() const;
NLMISC::CRGBA getRGBA() const;
const ucstring &getUCString() const;
CInterfaceExprUserType *getUserType() const;
// set
void setBool(bool value) { clean(); _Type = Boolean; _BoolValue = value; }
void setInteger(sint64 value) { clean(); _Type = Integer; _IntegerValue = value; }
void setDouble(double value) { clean(); _Type = Double; _DoubleValue = value; }
void setString(const std::string &value) { clean(); _Type = String; _StringValue = value; }
void setUCString(const ucstring &value) { clean(); _Type = String; _StringValue = value; }
void setString(const char *value) { clean(); _Type = String; _StringValue = value; }
void setRGBA(NLMISC::CRGBA value) { clean(); _Type = RGBA; _RGBAValue = (uint32)(value.R+(value.G<<8)+(value.B<<16)+(value.A<<24)); }
void setUserType(CInterfaceExprUserType *value);
// reset this object to initial state (no type)
@ -99,7 +99,7 @@ namespace NLGUI
CInterfaceExprUserType *_UserTypeValue;
uint32 _RGBAValue;
};
ucstring _StringValue; // well, can't fit in union, unless we do some horrible hack..
std::string _StringValue; // well, can't fit in union, unless we do some horrible hack..
private:
const char *evalBoolean(const char *expr);
const char *evalNumber(const char *expr);

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2015 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
@ -184,7 +184,7 @@ namespace NLGUI
// ***************************************************************************
// Read a CSS length value, return true if one of supported units '%, rem, em, px, pt'
// On failure: 'value' and 'unit' values are undefined
bool getCssLength (float &value, std::string &unit, const std::string &str);
bool getCssLength (float &value, std::string &unit, const std::string &str, bool neg = false);
// Read a width HTML parameter. "100" or "100%". Returns true if percent (0 ~ 1) else false
bool getPercentage (sint32 &width, float &percent, const char *str);

@ -2,8 +2,8 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -379,6 +379,10 @@ namespace NLGUI
TSmallScriptCache _SmallScriptCache;
static const char * _NELSmallScriptTableName;
#ifdef _WIN32
HMODULE m_LuaSocket;
#endif
private:
// this object isn't intended to be copied
CLuaState(const CLuaState &/* other */):NLMISC::CRefCount() { nlassert(0); }

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -263,8 +263,8 @@ inline lua_Integer CLuaState::toInteger(int index)
if (!isnum)
{
lua_Number d = lua_tonumber(_State, index);
nlwarning("Lua: Unable to convert Lua number %lf to integer", d);
res = (lua_Integer)d;
nlwarning("Lua: Converting lua_Number %lf to lua_Integer %i", d, (int)res);
}
return res;
#else

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -86,10 +87,12 @@ namespace NLGUI
// ucstring
#ifdef RYZOM_LUA_UCSTRING
static bool pop(CLuaState &ls, ucstring &dest);
static void push(CLuaState &ls, const ucstring &value);
static bool isUCStringOnStack(CLuaState &ls, sint index);
static bool getUCStringOnStack(CLuaState &ls, sint index, ucstring &dest);
#endif
// RGBA
@ -108,7 +111,9 @@ namespace NLGUI
static void check(CLuaState &ls, bool ok, const std::string &failReason);
static void checkArgType(CLuaState &ls, const char *funcName, uint index, int argType);
static void checkArgTypeRGBA(CLuaState &ls, const char *funcName, uint index);
#ifdef RYZOM_LUA_UCSTRING
static void checkArgTypeUCString(CLuaState &ls, const char *funcName, uint index);
#endif
/** throw a lua expection (inside a C function called from lua) with the given reason, and the current call stack
* The various check... function call this function when their test fails
*/
@ -154,10 +159,12 @@ namespace NLGUI
static uint32 getLocalTime();
static double getPreciseLocalTime();
static std::string findReplaceAll(const std::string &str, const std::string &search, const std::string &replace);
#ifdef RYZOM_LUA_UCSTRING
static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const ucstring &replace);
static ucstring findReplaceAll(const ucstring &str, const std::string &search, const std::string &replace);
static ucstring findReplaceAll(const ucstring &str, const std::string &search, const ucstring &replace);
static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const std::string &replace);
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -183,8 +190,10 @@ namespace NLGUI
static int runExpr(CLuaState &ls); // params: "expr". return: any of: nil,bool,string,number, RGBA, UCString
static int runFct(CLuaState &ls); // params: "expr", param1, param2.... return: any of: nil,bool,string,number, RGBA, UCString
static int runCommand(CLuaState &ls); // params: "command name", param1, param2 ... return true or false
#ifdef RYZOM_LUA_UCSTRING
static int isUCString(CLuaState &ls);
static int concatUCString(CLuaState &ls); // workaround for + operator that don't work in luabind for ucstrings ...
#endif
static int concatString(CLuaState &ls); // speedup concatenation of several strings
static int tableToString(CLuaState &ls); // concat element of a table to build a string
static int getPathContent(CLuaState &ls);

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2019-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -41,9 +42,13 @@ namespace NLGUI
UInt32,
Float,
String,
#ifdef RYZOM_LUA_UCSTRING
UCString,
#endif
StringRef,
#ifdef RYZOM_LUA_UCSTRING
UCStringRef,
#endif
RGBA,
LuaMethod
}; // other types will be added when needed
@ -78,9 +83,13 @@ namespace NLGUI
TGetUInt32 GetUInt32;
TGetFloat GetFloat;
TGetString GetString;
#ifdef RYZOM_LUA_UCSTRING
TGetUCString GetUCString;
#endif
TGetStringRef GetStringRef;
#ifdef RYZOM_LUA_UCSTRING
TGetUCStringRef GetUCStringRef;
#endif
TGetRGBA GetRGBA;
TLuaMethod GetLuaMethod; // lua method can only be obtained, not written ...
} GetMethod;
@ -91,7 +100,9 @@ namespace NLGUI
TSetUInt32 SetUInt32;
TSetFloat SetFloat;
TSetString SetString;
#ifdef RYZOM_LUA_UCSTRING
TSetUCString SetUCString;
#endif
TSetRGBA SetRGBA;
} SetMethod;
// name of the property
@ -297,6 +308,7 @@ namespace NLGUI
props.push_back(prop); \
}
#ifdef RYZOM_LUA_UCSTRING
// export a unicode string value, by giving the name of the get and the set method
#define REFLECT_UCSTRING(exportName, getMethod, setMethod) \
{ \
@ -307,6 +319,7 @@ namespace NLGUI
prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast<TSetUCStringa>(&A::setMethod); \
props.push_back(prop); \
}
#endif
// export a string value, by giving the name of the get and the set method
#define REFLECT_STRING_REF(exportName, getMethod, setMethod) \
@ -319,6 +332,7 @@ namespace NLGUI
props.push_back(prop); \
}
#ifdef RYZOM_LUA_UCSTRING
// export a unicode string value, by giving the name of the get and the set method
#define REFLECT_UCSTRING_REF(exportName, getMethod, setMethod) \
{ \
@ -329,7 +343,7 @@ namespace NLGUI
prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast<TSetUCStringa>(&A::setMethod); \
props.push_back(prop); \
}
#endif
// export a color value, by giving the name of the get and the set method
#define REFLECT_RGBA(exportName, getMethod, setMethod) \

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -21,11 +22,9 @@
#define STRING_CASE_H
#include "nel/misc/types_nl.h"
#include "nel/misc/ucstring.h"
namespace NLGUI
{
enum TCaseMode
{
CaseNormal = 0, // Nothing done
@ -37,10 +36,7 @@ namespace NLGUI
CaseCount
};
void setCase( ucstring &str, TCaseMode mode );
void setCase( std::string &str, TCaseMode mode );
}
#endif

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2016 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
@ -28,6 +28,7 @@
namespace NLGUI
{
class ICurlDownloadCB;
/**
* class implementing a bitmap view
@ -61,7 +62,7 @@ namespace NLGUI
_TxtHeight = -1;
// Support for https://.. textures
_HtmlDownload = false;
_HtmlDownload = NULL;
}
/// Destructor
@ -141,7 +142,9 @@ namespace NLGUI
bool _Flip : 1;
bool _Tile : 1;
bool _InheritGCAlpha : 1;
bool _HtmlDownload : 1;
// pointer to active curl download object
ICurlDownloadCB *_HtmlDownload;
// For single texture

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2017 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -55,14 +56,17 @@ namespace NLGUI
bool getStringMode() const {return _StringMode;}
// Set cursor string
void setString (const ucstring &str);
void setString (const std::string &str);
// TEMP PATCH
void setCursor (const std::string &name)
{
if (_TxDefault != name)
{
_TxDefault = name;
_TxIdDefault = -2;
}
}
// TEMP PATCH
/// Show or hide the pointer. Please, use SetMouseMode (bool freelook) instead.
@ -126,14 +130,14 @@ namespace NLGUI
bool _ForceStringMode;
CInterfaceGroup *_StringCursor;
CInterfaceGroup *_StringCursorHardware;
ucstring _ContextString;
std::string _ContextString;
// draw current cursor with the given texture, or, if in hardware mode, change the hardware cursor shape
void drawCursor(sint32 texId, NLMISC::CRGBA col, uint8 rot);
private:
// set the string into frame for software or hardware version
void setString (const ucstring &str, CInterfaceGroup *target);
void setString(const std::string &str, CInterfaceGroup *target);
static bool hwMouse;

@ -1,5 +1,5 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2020 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
@ -252,6 +252,19 @@ namespace NLGUI
*/
bool loadTextures (const std::string &textureFileName, const std::string &uvFileName, bool uploadDXTC);
/*
* newTextureId : Return new placeholder texture id.
* You should call deleteTexture when the texture is not used anymore.
*/
sint32 newTextureId (const std::string &name);
/*
* reloadTexture : Replace existing global texture with new.
* If previous was texture atlas and still used by 2+ textures,
* then create new global texture.
*/
void reloadTexture (sint32 texId, const std::string &name, bool uploadDXTC=true, bool bReleasable=true);
/*
* createTexture : create a texture for the interface, possibly from an externally created texture
* If no external texture is given, then 'sGlobalTextureName' is the filename of the big texture
@ -312,6 +325,9 @@ namespace NLGUI
/**
* get a texture file pointer from a string name. O(logN)
*
* FIXME: only works with textures in atlas loaded with loadTextures()
*
* \param id : the id of the texture
* \return a texture file pointer. -1 if not found or if sName is empty()
*/
@ -479,6 +495,9 @@ namespace NLGUI
// \name Texture management
// ***************************************************************************
bool loadTextureFromString(SGlobalTexture *gt, const std::string &data);
bool loadTextureFromFile(SGlobalTexture *gt, const std::string &filename);
// SImage accessors
SImage *getSImage(sint32 textureId)
{

@ -1,9 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -84,7 +84,12 @@ namespace NLGUI
/// Set
void setText (const ucstring &text);
void setText(const std::string &text);
void setTextLocalized(const std::string &text, bool localized);
#ifdef RYZOM_LUA_UCSTRING
void setTextAsUtf16 (const ucstring &text); // Compatibility
#endif
void setLocalized(bool localized);
void setFontName (const std::string &name);
void setFontSize (sint nFontSize, bool coef = true);
void setEmbolden (bool nEmbolden);
@ -95,7 +100,10 @@ namespace NLGUI
void setShadowColor (const NLMISC::CRGBA &color);
void setShadowOffset (sint x, sint y);
void setLineMaxW (sint nMaxW, bool invalidate=true);
void setOverflowText(const ucstring &text) { _OverflowText = text; }
void setOverflowText(const std::string &text) { _OverflowText = text; }
#ifdef RYZOM_LUA_UCSTRING
void setOverflowTextAsUtf16(const ucstring &text) { _OverflowText = text.toUtf8(); } // Compatibility
#endif
void setMultiLine (bool bMultiLine);
void setMultiLineSpace (sint nMultiLineSpace);
void setMultiLineMaxWOnly (bool state);
@ -112,8 +120,12 @@ namespace NLGUI
void disableStringSelection();
/// Get
ucstring getText() const { return _Text; }
std::string getText() const { return _HardText.empty() ? _Text : _HardText; }
#ifdef RYZOM_LUA_UCSTRING
ucstring getTextAsUtf16() const; // Compatibility
ucstring getHardTextAsUtf16() const; // Compatibility
#endif
bool isLocalized() const { return _Localized; }
sint getFontSize() const;
std::string getFontName() const { return _FontName; }
bool getEmbolden() { return _Embolden; }
@ -124,7 +136,9 @@ namespace NLGUI
NLMISC::CRGBA getShadowColor() { return _ShadowColor; }
void getShadowOffset(sint &x, sint &y) { x = _ShadowX; y = _ShadowY; }
sint getLineMaxW() const { return _LineMaxW; }
ucstring getOverflowText() const { return _OverflowText; }
#ifdef RYZOM_LUA_UCSTRING
ucstring getOverflowTextAsUtf16() const { return _OverflowText; } // Compatibility
#endif
bool getMultiLine() const { return _MultiLine; }
sint getMultiLineSpace() const { return _MultiLineSpace; }
bool getMultiLineMaxWOnly() const { return _MultiLineMaxWOnly; }
@ -174,8 +188,11 @@ namespace NLGUI
/// From a line number, get the character at which it ends (not including any '\n' ), or -1 if invalid
void getLineEndIndex(uint line, sint &index, bool &endOfPreviousLine) const;
std::string getHardText() const { std::string result; _Text.toString (result); return result; }
void setHardText (const std::string &ht);
std::string getHardText() const { return _HardText.empty() ? _Text : _HardText; }
void setHardText (const std::string &ht); //< Localizes strings starting with "ui"
#ifdef RYZOM_LUA_UCSTRING
void setHardTextAsUtf16(const ucstring &ht); // Compatibility
#endif
std::string getColorAsString() const;
void setColorAsString(const std::string &ht);
@ -188,9 +205,15 @@ namespace NLGUI
/** Setup a Text with Format Tags. Text is store without color/format tags, and special array is allocated for Format association
*/
void setTextFormatTaged(const ucstring &text);
void setTextFormatTaged(const std::string &text);
#ifdef RYZOM_LUA_UCSTRING
void setTextFormatTagedAsUtf16(const ucstring &text); // Compatibility
#endif
void setSingleLineTextFormatTaged(const ucstring &text);
void setSingleLineTextFormatTaged(const std::string &text);
#ifdef RYZOM_LUA_UCSTRING
void setSingleLineTextFormatTagedAsUtf16(const ucstring &text); // Compatibility
#endif
// Remove end space
void removeEndSpaces();
@ -216,10 +239,17 @@ namespace NLGUI
int luaSetLineMaxW(CLuaState &ls);
REFLECT_EXPORT_START(CViewText, CViewBase)
REFLECT_STRING("hardtext", getHardText, setHardText);
REFLECT_UCSTRING("uc_hardtext", getText, setText);
REFLECT_UCSTRING("uc_hardtext_format", getText, setTextFormatTaged);
REFLECT_UCSTRING("uc_hardtext_single_line_format", getText, setSingleLineTextFormatTaged);
REFLECT_BOOL("localize", isLocalized, setLocalized);
REFLECT_STRING("hardtext", getHardText, setHardText); // Same as text, but localize is implicitly set true
REFLECT_STRING("text", getText, setText);
REFLECT_STRING("text_format", getText, setTextFormatTaged);
REFLECT_STRING("text_single_line_format", getText, setSingleLineTextFormatTaged);
#ifdef RYZOM_LUA_UCSTRING
// REFLECT_UCSTRING("uc_text", getTextAsUtf16, setTextAsUtf16); // Deprecate uc_ functions
REFLECT_UCSTRING("uc_hardtext", getHardTextAsUtf16, setHardTextAsUtf16); // Compatibility
REFLECT_UCSTRING("uc_hardtext_format", getTextAsUtf16, setTextFormatTagedAsUtf16); // Compatibility
REFLECT_UCSTRING("uc_hardtext_single_line_format", getTextAsUtf16, setSingleLineTextFormatTagedAsUtf16); // Compatibility
#endif
REFLECT_STRING ("color", getColorAsString, setColorAsString);
REFLECT_RGBA ("color_rgba", getColorRGBA, setColorRGBA);
REFLECT_SINT32 ("alpha", getAlpha, setAlpha);
@ -228,7 +258,6 @@ namespace NLGUI
REFLECT_LUA_METHOD("setLineMaxW", luaSetLineMaxW);
REFLECT_EXPORT_END
virtual void serial(NLMISC::IStream &f);
// Sets the parent element
@ -236,9 +265,12 @@ namespace NLGUI
void setParentElm( CInterfaceElement *parent ){ _ParentElm = parent; }
protected:
std::string _HardtextFormat;
/// Text to display.
ucstring _Text;
std::string _HardTextFormat;
std::string _HardText;
std::string _Text;
mutable sint _TextLength;
bool _Localized;
/// index of the computed String associated to this text control
uint _Index;
/// info on the computed String associated to this text control
@ -253,8 +285,8 @@ namespace NLGUI
// width of the font in pixel. Just a Hint for tabing format (computed with '_')
float _FontWidth;
// strings to use when computing font size
ucstring _FontSizingChars;
ucstring _FontSizingFallback;
std::string _FontSizingChars;
std::string _FontSizingFallback;
// height of the font in pixel.
// use getFontHeight
float _FontHeight;
@ -278,7 +310,7 @@ namespace NLGUI
sint32 _LineMaxW;
/// For single line, true if the text is clamped (ie displayed with "...")
bool _SingleLineTextClamped;
ucstring _OverflowText;
std::string _OverflowText;
/// Multiple lines handling
bool _MultiLine;
@ -339,7 +371,7 @@ namespace NLGUI
public:
// default ctor
CWord(uint numSpaces = 0) : Index(0), NumSpaces(numSpaces) {}
ucstring Text;
std::string Text;
uint Index; // index of the info for this word
NL3D::UTextContext::CStringInfo Info;
uint NumSpaces; // number of spaces before this word
@ -347,7 +379,7 @@ namespace NLGUI
CFormatInfo Format;
public:
// build from a string, using the current text context
void build(const ucstring &text, NL3D::UTextContext &textContext, uint numSpaces= 0);
void build(const std::string &text, NL3D::UTextContext &textContext, uint numSpaces= 0);
};
typedef std::vector<CWord> TWordVect;
@ -360,7 +392,7 @@ namespace NLGUI
// Clear the line & remove text contexts
void clear(NL3D::UTextContext &textContext);
// Add a new word (and its context) in the line + a number of spaces to append at the end of the line
void addWord(const ucstring &word, uint numSpaces, const CFormatInfo &wordFormat, float fontWidth, NL3D::UTextContext &textContext);
void addWord(const std::string &word, uint numSpaces, const CFormatInfo &wordFormat, float fontWidth, NL3D::UTextContext &textContext);
void addWord(const CWord &word, float fontWidth);
uint getNumWords() const { return (uint)_Words.size(); }
CWord &getWord(uint index) { return _Words[index]; }
@ -434,15 +466,17 @@ namespace NLGUI
void setup ();
void setupDefault ();
void setStringSelectionSkipingSpace(uint stringId, const ucstring &text, sint charStart, sint charEnd);
void setTextLocalized(const std::string &text);
void setStringSelectionSkipingSpace(uint stringId, const std::string &text, sint charStart, sint charEnd);
// void pushString(const ucstring &str, bool deleteSpaceAtStart = false);
// void pushString(const ucstring &str, bool deleteSpaceAtStart = false); // OLD
/// \from CInterfaceElement
void onInvalidateContent();
// may append a new line, and append a word to the last line (no spaces)
void flushWordInLine(ucstring &ucCurrentWord, bool &linePushed, const CFormatInfo &wordFormat);
void flushWordInLine(std::string &ucCurrentWord, bool &linePushed, const CFormatInfo &wordFormat);
// Clear all the lines and free their datas
void clearLines();
// Update in the case of a multiline text
@ -456,7 +490,7 @@ namespace NLGUI
void addDontClipWordLine(std::vector<CWord> &currLine);
// FormatTag build.
static void buildFormatTagText(const ucstring &text, ucstring &textBuild, std::vector<CFormatTag> &formatTags, std::vector<ucstring> &tooltips);
static void buildFormatTagText(const std::string &text, std::string &textBuild, std::vector<CFormatTag> &formatTags, std::vector<std::string> &tooltips);
// FormatTag parsing.
bool isFormatTagChange(uint textIndex, uint ctIndex) const;
void getFormatTagChange(uint textIndex, uint &ctIndex, CFormatInfo &wordFormat) const;

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -45,7 +46,7 @@ namespace NLGUI
{
public:
virtual ~IViewTextFormatter(){}
virtual ucstring formatString( const ucstring &inputString, const ucstring &paramString ) = 0;
virtual std::string formatString( const std::string &inputString, const std::string &paramString ) = 0;
};
CViewTextFormated (const TCtorParam &param) : CViewText(param)
@ -55,15 +56,15 @@ namespace NLGUI
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup);
virtual void checkCoords();
const ucstring &getFormatString() const { return _FormatString; }
void setFormatString(const ucstring &format);
const std::string &getFormatString() const { return _FormatString; }
void setFormatString(const std::string &format);
static ucstring formatString(const ucstring &inputString, const ucstring &paramString);
static std::string formatString(const std::string &inputString, const std::string &paramString);
static void setFormatter( IViewTextFormatter *formatter ){ textFormatter = formatter; }
private:
ucstring _FormatString;
std::string _FormatString;
static IViewTextFormatter *textFormatter;
};

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -38,7 +39,7 @@ namespace NLGUI
public:
virtual ~IOnReceiveTextId() {}
// the deriver may change the input text
virtual void onReceiveTextId(ucstring &str) =0;
virtual void onReceiveTextId(std::string &str) =0;
};
// ***************************************************************************
@ -58,8 +59,8 @@ namespace NLGUI
{
public:
virtual ~IViewTextProvider(){}
virtual bool getString( uint32 stringId, ucstring &result ) = 0;
virtual bool getDynString( uint32 dynStringId, ucstring &result ) = 0;
virtual bool getString(uint32 stringId, std::string &result) = 0;
virtual bool getDynString(uint32 dynStringId, std::string &result) = 0;
};
CViewTextID(const TCtorParam &param) : CViewText(param)
@ -144,7 +145,7 @@ namespace NLGUI
// If true, setTextFormatted() is used instead of setText()
bool _IsTextFormatTaged;
// Optional ucstring modifier
// Optional utf-8 string modifier
IOnReceiveTextId *_StringModifier;
std::string _DBPath;
static IViewTextProvider* getTextProvider(){ return textProvider; }

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -49,10 +50,10 @@ namespace NLGUI
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup);
virtual void checkCoords();
const ucstring &getFormatString() const { return _FormatString; }
void setFormatString(const ucstring &format);
const std::string &getFormatString() const { return _FormatString; }
void setFormatString(const std::string &format);
private:
ucstring _FormatString;
std::string _FormatString;
};
}

@ -1,9 +1,9 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2020 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -333,8 +333,8 @@ namespace NLGUI
void updateTooltipCoords(CCtrlBase *newCtrl);
/// for ContextHelp action handler only: set the result name
void setContextHelpText( const ucstring &text ){ _ContextHelpText = text; }
ucstring& getContextHelpText(){ return _ContextHelpText; }
void setContextHelpText( const std::string &text ){ _ContextHelpText = text; }
std::string& getContextHelpText(){ return _ContextHelpText; }
/// force disable the context help
void disableContextHelp();
@ -626,7 +626,7 @@ namespace NLGUI
SInterfaceTimes interfaceTimes;
ucstring _ContextHelpText;
std::string _ContextHelpText;
bool _ContextHelpActive;
bool inGame;

@ -1,5 +1,5 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2020 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -1,5 +1,5 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2015 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2016 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>

@ -1,10 +1,10 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010-2018 Winch Gate Property Limited
// Copyright (C) 2010-2020 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
// Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
// Copyright (C) 2015-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2015-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -227,18 +227,62 @@ inline double isValidDouble (double v)
* \param str a string to transform to lower case
*/
std::string toLower ( const char *str );
std::string toLower ( const std::string &str );
void toLower ( char *str );
std::string toLower ( const char *str ); // UTF-8
std::string toLower ( const std::string &str ); // UTF-8
void toLower ( char *str ); // Ascii only
char toLower ( const char ch ); // convert only one character
/** Convert a string in upper case.
* \param a string to transform to upper case
*/
std::string toUpper ( const std::string &str);
void toUpper ( char *str);
std::string toUpper ( const char *str ); // UTF-8
std::string toUpper ( const std::string &str); // UTF-8
void toUpper ( char *str); // Ascii only
/** Convert a single character in UTF-8 to upper or lowercase.
* \param res Character is appended in UTF-8 into this string.
* \param src Character is sourced from this UTF-8 string.
* \param i Index in `str`, incremented by the number of bytes read.
*/
void appendToLower(std::string &res, const char *str, ptrdiff_t &i);
void appendToLower(std::string &res, const std::string &str, ptrdiff_t &i);
void appendToUpper(std::string &res, const char *str, ptrdiff_t &i);
void appendToUpper(std::string &res, const std::string &str, ptrdiff_t &i);
void appendToTitle(std::string &res, const char *str, ptrdiff_t &i);
void appendToTitle(std::string &res, const std::string &str, ptrdiff_t &i);
/** UTF-8 case insensitive compare */
int compareCaseInsensitive(const char *a, const char *b);
int compareCaseInsensitive(const char *a, size_t lenA, const char *b, size_t lenB);
inline int compareCaseInsensitive(const std::string &a, const std::string &b) { return compareCaseInsensitive(&a[0], a.size(), &b[0], b.size()); }
inline bool ltCaseInsensitive(const std::string &a, const std::string &b) { return compareCaseInsensitive(&a[0], a.size(), &b[0], b.size()) < 0; }
std::string toCaseInsensitive(const char *str); // UTF-8, case-insensitive toLower
std::string toCaseInsensitive(const std::string &str); // UTF-8, case-insensitive toLower
/** ASCII to lowercase. Useful for internal identifiers.
* Characters outside of the 7-bit ASCII space, and control characters, are replaced.
*/
std::string toLowerAscii(const std::string &str, char replacement);
void toLowerAscii(char *str, char replacement);
/** ASCII to uppercase. Useful for internal identifiers.
* Characters outside of the 7-bit ASCII space, and control characters, are replaced.
*/
std::string toUpperAscii(const std::string &str, char replacement);
void toUpperAscii(char *str, char replacement);
/** ASCII to lowercase. Useful for internal identifiers.
* Characters outside of the 7-bit ASCII space are not affected.
*/
std::string toLowerAscii(const std::string &str);
void toLowerAscii(char *str);
/** ASCII to uppercase. Useful for internal identifiers.
* Characters outside of the 7-bit ASCII space are not affected.
*/
std::string toUpperAscii(const std::string &str);
void toUpperAscii(char *str);
/**
* Convert to an hexadecimal std::string

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2015-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -0,0 +1,83 @@
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NLMISC_DEEP_PTR_H
#define NLMISC_DEEP_PTR_H
#include <nel/misc/types_nl.h>
namespace NLMISC {
/// Pointer template with deep copy and move semantics
template<class T>
class CDeepPtr
{
public:
NL_FORCE_INLINE CDeepPtr() : m(NULL) { } //< Null
NL_FORCE_INLINE ~CDeepPtr() { delete m; }
NL_FORCE_INLINE CDeepPtr(const CDeepPtr &p) : m(p.m ? new T(*p) : NULL) { } //< Copy operator
NL_FORCE_INLINE CDeepPtr &operator=(const CDeepPtr &p) { if (p.m) { if (!m) m = new T(*p); else *m = *p; } else { delete m; m = NULL; } return *this; } //< Copy operator
#ifdef NL_CPP14
NL_FORCE_INLINE CDeepPtr(CDeepPtr &&p) noexcept : m(p.m) { p.m = NULL; } //< Move operator
NL_FORCE_INLINE CDeepPtr &operator=(CDeepPtr &&p) noexcept { delete m; m = p.m; p.m = NULL; return *this; } //< Move operator
#endif
NL_FORCE_INLINE CDeepPtr(T *p) : m(p) { } //< Initializer
NL_FORCE_INLINE CDeepPtr &operator=(T *p) { delete m; m = p; return *this; } //< Initializer
NL_FORCE_INLINE bool operator==(const CDeepPtr &p) const { return /* (m == p.m) || */ (m && p.m && *m == *p); }
NL_FORCE_INLINE bool operator!=(const CDeepPtr &p) const { return !(*this == p); }
NL_FORCE_INLINE bool operator==(const T *p) const { return (m == p) || (m && p && *m == *p); }
NL_FORCE_INLINE bool operator!=(const T *p) const { return !(*this == p); }
NL_FORCE_INLINE bool operator==(const T &p) const { return (m == &p) || (m && *m == p); }
NL_FORCE_INLINE bool operator!=(const T &p) const { return !(*this == p); }
NL_FORCE_INLINE bool operator==(long int p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == NULL
NL_FORCE_INLINE bool operator!=(long int p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != NULL
NL_FORCE_INLINE bool operator==(int p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == 0
NL_FORCE_INLINE bool operator!=(int p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != 0
#ifdef NL_CPP14
NL_FORCE_INLINE bool operator==(nullptr_t p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == nullptr
NL_FORCE_INLINE bool operator!=(nullptr_t p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != nullptr
#endif
NL_FORCE_INLINE T &operator*() { return *m; }
NL_FORCE_INLINE const T &operator*() const { return *m; }
NL_FORCE_INLINE T *operator->() { return m; }
NL_FORCE_INLINE const T *operator->() const { return m; }
NL_FORCE_INLINE operator bool() const { return m; }
NL_FORCE_INLINE bool operator!() const { return !m; }
NL_FORCE_INLINE T *ptr() { return m; }
NL_FORCE_INLINE const T *ptr() const { return m; }
private:
T *m;
};
} /* namespace NLMISC */
#endif /* #ifndef NLMISC_DEEP_PTR_H */
/* end of file */

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
@ -48,8 +51,8 @@ public:
/// From IEventEmitter. This call submitEvents on all the emitters
virtual void submitEvents(CEventServer &server, bool allWindows);
virtual bool copyTextToClipboard(const ucstring &text);
virtual bool pasteTextFromClipboard(ucstring &text);
virtual bool copyTextToClipboard(const std::string &text);
virtual bool pasteTextFromClipboard(std::string &text);
private:
typedef std::vector<std::pair<IEventEmitter *, bool> > TEmitterCont;

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
@ -320,11 +323,11 @@ public:
class CEventChar : public CEventKey
{
public:
CEventChar (ucchar c, TKeyButton button, IEventEmitter* emitter) : CEventKey (button, emitter, EventCharId), _Raw(true)
CEventChar (u32char c, TKeyButton button, IEventEmitter* emitter) : CEventKey (button, emitter, EventCharId), _Raw(true)
{
Char=c;
}
ucchar Char;
u32char Char;
virtual CEvent *clone() const {return new CEventChar(*this);}
void setRaw( bool raw ) { _Raw = raw; }
@ -341,11 +344,11 @@ private:
class CEventString : public CEventKey
{
public:
CEventString (const ucstring &str, IEventEmitter* emitter) : CEventKey (noKeyButton, emitter, EventStringId)
CEventString (const std::string &str, IEventEmitter* emitter) : CEventKey (noKeyButton, emitter, EventStringId)
{
String = str;
}
ucstring String;
std::string String;
virtual CEvent *clone() const {return new CEventString(*this);}
};

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
@ -58,12 +61,8 @@ public:
static CFactory &instance()
{
// Singleton instance pointer.
static CFactory *instance = NULL;
if (!instance)
{
instance = new CFactory();
}
return *instance;
static CFactory instance;
return instance;
}
/** Register a factorable object in the factory.
@ -185,12 +184,8 @@ public:
/// Get the singleton instance reference.
static CFactoryIndirect &instance()
{
static CFactoryIndirect *instance = NULL;
if (!instance)
{
instance = new CFactoryIndirect();
}
return *instance;
static CFactoryIndirect instance;
return instance;
}
void registerClass(const KeyType &key, IFactoryIndirectRegister<BaseFactoryClass> *factoryRegister)

@ -1,5 +1,8 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -107,6 +107,7 @@ private:
uint _NumBlockPerChunk;
//
uint _NumAlloc;
uint8 *_SpareMem;
};
} // NLMISC

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2012 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -99,7 +100,7 @@ public:
/// Return a vector with all language available. The vector contains the name of the language.
/// The index in the vector is used in \c load() function
static const std::vector<ucstring> &getLanguageNames();
static const std::vector<std::string> &getLanguageNames();
/** Return a vector with all language code available.
* Code are ISO 639-2 compliant.
@ -122,7 +123,7 @@ public:
static void loadFromFilename (const std::string &filename, bool reload);
/// Returns the name of the language in the language name (English, Francais, ...)
static ucstring getCurrentLanguageName ();
static std::string getCurrentLanguageName ();
/// Returns the code of the language ("fr", "en", ...)
static std::string getCurrentLanguageCode ();
@ -134,7 +135,10 @@ public:
static bool setSystemLanguageCode (const std::string &languageCode);
/// Find a string in the selected language and return his association.
static const ucstring &get (const std::string &label);
static const ucstring &getAsUtf16 (const std::string &label);
/// Find a string in the selected language and return his association.
static const std::string &get (const std::string &label);
// Test if a string has a translation in the selected language.
// NB : The empty string is considered to have a translation
@ -219,24 +223,28 @@ public:
private:
typedef std::map<std::string, ucstring> StrMapContainer;
typedef std::map<std::string, std::string> StrMapContainer;
typedef std::map<std::string, ucstring> StrMapContainer16;
static ILoadProxy *_LoadProxy;
static StrMapContainer _StrMap;
static StrMapContainer16 _StrMap16;
static bool _StrMapLoaded;
// the alternative language that will be used if the sentence is not found in the original language
static StrMapContainer _StrMapFallback;
static StrMapContainer16 _StrMapFallback16;
static std::vector<std::string> _LanguageCodes;
static std::vector<ucstring> _LanguageNames;
static std::vector<std::string> _LanguageNames;
static std::string _SystemLanguageCode;
static bool _LanguagesNamesLoaded;
static std::string _SelectedLanguageCode;
static const ucstring _NotTranslatedValue;
static const ucstring _NotTranslatedValue16;
static const std::string _NotTranslatedValue;
/** Structure to hold contextual info during
* read of preprocessed file
@ -256,7 +264,7 @@ private:
/// Init _LanguageCodes and _LanguageNames
static void initLanguages();
static bool loadFileIntoMap(const std::string &filename, StrMapContainer &dest);
static bool loadFileIntoMap(const std::string &filename, StrMapContainer &dest, StrMapContainer16 &dest16);
/// The internal read function, it does the real job of readTextFile
static void _readTextFile(const std::string &filename,

@ -1,5 +1,5 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2020 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014-2015 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
@ -731,11 +731,18 @@ struct CFile
static bool createDirectoryTree(const std::string &dirname);
/** Try to set the file access to read/write if not already set.
* On linux/macOS also set +x on directory.
* return true if the file doesn't exist or if the file already have RW access.
* \return true if RW access is granted
*/
static bool setRWAccess(const std::string &filename);
/** Try to set +x bit on linux/macOS to make file executable. no-op on Windows
* On Windows, always returns true, even if file does not exist.
* \return true if file exists and +x was set, false if operation failed.
*/
static bool setExecutable(const std::string &filename);
/** Delete a file if possible (change the write access if possible)
* \return true if the delete occurs.
*/

@ -1,5 +1,5 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2019-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2012-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2014-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This source file has been modified by the following contributors:
// Copyright (C) 2021 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
@ -32,7 +35,7 @@ public:
uint32 Size;
uint32 LastModified;
void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
void serial(NLMISC::IStream &f);
};
@ -40,7 +43,7 @@ public:
CStreamedPackage();
~CStreamedPackage();
void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
void serial(NLMISC::IStream &f);
/// result: [out] ex. /00/00/000000000..
/// hash: [in]

@ -3,7 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2012 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
// Copyright (C) 2016-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2016-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -193,6 +193,10 @@ inline std::string toString(const sint32 &val) { return toString("%d", val); }
inline std::string toString(const uint64 &val) { return toString("%" NL_I64 "u", val); }
inline std::string toString(const sint64 &val) { return toString("%" NL_I64 "d", val); }
#ifdef NL_OS_WINDOWS
inline std::string toString(const wchar_t &val) { return toString(reinterpret_cast<const uint16 &>(val)); }
#endif
#ifdef NL_COMP_GCC
# if GCC_VERSION == 40102
@ -246,9 +250,14 @@ inline bool fromString(const std::string &str, sint64 &val) { bool ret = sscanf(
inline bool fromString(const std::string &str, float &val) { bool ret = sscanf(str.c_str(), "%f", &val) == 1; if (!ret) val = 0.0f; return ret; }
inline bool fromString(const std::string &str, double &val) { bool ret = sscanf(str.c_str(), "%lf", &val) == 1; if (!ret) val = 0.0; return ret; }
// Fast string to bool, reliably defined for strings starting with 0, 1, t, T, f, F, y, Y, n, N, anything else is undefined.
// (str[0] == '1' || (str[0] & 0xD2) == 0x50)
// - Kaetemi
#ifdef NL_OS_WINDOWS
inline bool fromString(const std::string &str, wchar_t &val) { return fromString(str, reinterpret_cast<uint16 &>(val)); }
#endif
/// Fast string to bool, reliably defined for strings starting with 0, 1, t, T, f, F, y, Y, n, N, and empty strings, anything else is undefined.
/// - Kaetemi
inline bool toBool(const char *str) { return str[0] == '1' || (str[0] & 0xD2) == 0x50; }
inline bool toBool(const std::string &str) { return toBool(str.c_str()); } // Safe because first byte may be null
bool fromString(const std::string &str, bool &val);

@ -0,0 +1,131 @@
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NLMISC_STRING_VIEW_H
#define NLMISC_STRING_VIEW_H
#include <nel/misc/types_nl.h>
#include <string>
#ifdef NL_CPP14
using namespace std::string_literals;
#ifdef NL_CPP17
#include <string_view>
using namespace std::string_view_literals;
#endif
#endif
#ifdef NL_CPP14
/// Obtain an std::string from a string literal.
#define nlstr(strLit) (strLit##s)
#else
/// Obtain an std::string from a string literal.
#define nlstr(strLit) (std::string(strLit))
#endif
#ifdef NL_CPP17
/// Obtain a string view from a string literal.
#define nlsv(strLit) (strLit##sv)
/// Obtain an std::string from a string view.
#define nlsvs(strView) (std::string(strView))
#else
/// Obtain a string view from a string literal.
#define nlsv(strLit) (CStringView(strLit, ::strlen(strLit)))
/// Obtain an std::string from a string view.
#define nlsvs(strView) (std::string(strView.data(), strView.size()))
#endif
/// Obtain a temporary C-string from a string view. Use directly in argument, do not store.
#define nlsvc(strView) ((strView.data()[strView.size()]) ? nlsvs(strView).c_str() : strView.data())
namespace NLMISC {
/// String view literals allow bypassing allocation and strlen calls.
/// CStringView is a 100% drop-in replacement for (const char *str, size_t len) tuples. It's a non-owning reference.
/// Always use `CStringView` where previously `const std::string &` would have been used. It avoids accidental copy.
/// Gotcha: CStringView doesn't need to end with \0, so there's no guarantee with functions that expect \0 terminated strings,
/// use the `nlsvc` macro to get a temporary C-string from a CStringView.
/// Use the `nlsv` macro to get a CStringView from a string literal.
/// Use the `nlstr` macro to get an std::string from a string literal.
/// Use the `nlsvs` macro to get an std::string from a CStringView.
#ifdef NL_CPP17
typedef std::string_view CStringView;
#else
class CStringView
{
public:
CStringView(const std::string &str) : m_Str(&str[0]), m_Len(str.size()) {}
CStringView(const char *const str, const size_t len) : m_Str(str), m_Len(len) {}
CStringView(const char *const str) : m_Str(str), m_Len(sizeof(str)) {}
inline const char *data() const { return m_Str; }
inline size_t length() const { return m_Len; }
inline size_t size() const { return m_Len; }
inline CStringView substr(const size_t offset, const size_t count = -1) { return CStringView(m_Str + offset, std::min(m_Len - offset, count)); }
inline bool operator==(const CStringView o) { if (m_Len != o.m_Len) return false; return memcmp(m_Str, o.m_Str, m_Len) == 0; }
inline bool operator!=(const CStringView o) { if (m_Len != o.m_Len) return true; return memcmp(m_Str, o.m_Str, m_Len) != 0; }
struct const_iterator
{
public:
const_iterator() : m_Addr(NULL) { }
inline void operator++()
{
++m_Addr;
}
inline void operator+=(ptrdiff_t v)
{
m_Addr += v;
}
inline void operator--()
{
--m_Addr;
}
inline void operator-=(ptrdiff_t v)
{
m_Addr -= v;
}
inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; }
inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; }
inline const char &operator*() const { return *m_Addr; }
private:
friend class CStringView;
inline const_iterator(const char *addr) : m_Addr(addr) {}
const char *m_Addr;
};
typedef const_iterator iterator;
iterator begin() const { return iterator(m_Str); }
inline iterator end() const { return iterator(m_Str + m_Len); }
private:
const char *m_Str;
size_t m_Len;
};
#endif
}
#endif /* #ifndef NLMISC_STRING_VIEW_H */
/* end of file */

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2015-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2015-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -49,10 +49,10 @@ public:
static bool updateProgressBar(uint value, uint total);
/// Copy a string to system clipboard.
static bool copyTextToClipboard(const ucstring &text);
static bool copyTextToClipboard(const std::string &text);
/// Paste a string from system clipboard.
static bool pasteTextFromClipboard(ucstring &text);
static bool pasteTextFromClipboard(std::string &text);
/// Check if system supports unicode.
static bool supportUnicode();

@ -2,7 +2,7 @@
// Copyright (C) 2010-2011 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2014-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -548,6 +548,14 @@ template<> struct hash<uint64>
*/
typedef uint16 ucchar;
#ifdef NL_CPP14
typedef char32_t u32char;
typedef std::u32string u32string;
#else
typedef uint32 u32char;
typedef std::basic_string<uint32> u32string;
#endif
#ifndef NL_OVERRIDE
#define NL_OVERRIDE override
#endif

@ -2,7 +2,7 @@
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
// Copyright (C) 2015-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -20,6 +20,8 @@
#ifndef NL_UCSTRING_H
#define NL_UCSTRING_H
#define RYZOM_LUA_UCSTRING
#include "types_nl.h"
#include "debug.h"
@ -35,14 +37,22 @@ typedef std::basic_string<ucchar> ucstringbase;
class ucstring : public ucstringbase
{
public:
ucstring() { }
ucstring (const ucstringbase &str) : ucstringbase (str) {}
ucstring(const ucstringbase &str)
: ucstringbase(str)
{
}
ucstring(const ucchar *begin, const ucchar *end)
: ucstringbase(begin, end)
{
}
ucstring (const std::string &str) : ucstringbase ()
ucstring(const std::string &str)
: ucstringbase()
{
rawCopy(str);
fromUtf8(str);
}
~ucstring() { }
@ -128,17 +138,7 @@ public:
}
/// Converts the controlled ucstring to a string str
void toString (std::string &str) const
{
str.resize (size ());
for (uint i = 0; i < str.size (); i++)
{
if (operator[](i) > 255)
str[i] = '?';
else
str[i] = (char) operator[](i);
}
}
void toString(std::string &str) const;
/// Converts the controlled ucstring and returns the resulting string
std::string toString() const
@ -149,43 +149,7 @@ public:
}
/// Convert this ucstring (16bits char) into a utf8 string
std::string toUtf8() const
{
std::string res;
ucstring::const_iterator first(begin()), last(end());
for (; first != last; ++first)
{
//ucchar c = *first;
uint nbLoop = 0;
if (*first < 0x80)
res += char(*first);
else if (*first < 0x800)
{
ucchar c = *first;
c = c >> 6;
c = c & 0x1F;
res += char(c) | 0xC0;
nbLoop = 1;
}
else /*if (*first < 0x10000)*/
{
ucchar c = *first;
c = c >> 12;
c = c & 0x0F;
res += char(c) | 0xE0;
nbLoop = 2;
}
for (uint i=0; i<nbLoop; ++i)
{
ucchar c = *first;
c = c >> ((nbLoop - i - 1) * 6);
c = c & 0x3F;
res += char(c) | 0x80;
}
}
return res;
}
std::string toUtf8() const;
ucstring substr(size_type pos = 0, size_type n = npos) const
{
@ -199,86 +163,7 @@ public:
}
/// Convert the utf8 string into this ucstring (16 bits char)
void fromUtf8(const std::string &stringUtf8)
{
// clear the string
erase();
uint8 c;
ucchar code;
sint iterations = 0;
std::string::const_iterator first(stringUtf8.begin()), last(stringUtf8.end());
for (; first != last; )
{
c = *first++;
code = c;
if ((code & 0xFE) == 0xFC)
{
code &= 0x01;
iterations = 5;
}
else if ((code & 0xFC) == 0xF8)
{
code &= 0x03;
iterations = 4;
}
else if ((code & 0xF8) == 0xF0)
{
code &= 0x07;
iterations = 3;
}
else if ((code & 0xF0) == 0xE0)
{
code &= 0x0F;
iterations = 2;
}
else if ((code & 0xE0) == 0xC0)
{
code &= 0x1F;
iterations = 1;
}
else if ((code & 0x80) == 0x80)
{
// If it's not a valid UTF8 string, just copy the line without utf8 conversion
rawCopy(stringUtf8);
return;
}
else
{
push_back(code);
iterations = 0;
}
if (iterations)
{
for (sint i = 0; i < iterations; i++)
{
if (first == last)
{
// If it's not a valid UTF8 string, just copy the line without utf8 conversion
rawCopy(stringUtf8);
return;
}
uint8 ch;
ch = *first ++;
if ((ch & 0xC0) != 0x80)
{
// If it's not a valid UTF8 string, just copy the line without utf8 conversion
rawCopy(stringUtf8);
return;
}
code <<= 6;
code |= (ucchar)(ch & 0x3F);
}
push_back(code);
}
}
}
void fromUtf8(const std::string &stringUtf8);
static ucstring makeFromUtf8(const std::string &stringUtf8)
{
@ -288,20 +173,6 @@ public:
return ret;
}
private:
void rawCopy(const std::string &str)
{
// We need to convert the char into 8bits unsigned int before promotion to 16 bits
// otherwise, as char are signed on some compiler (MSCV for ex), the sign bit is extended to 16 bits.
resize(str.size());
std::string::const_iterator first(str.begin()), last(str.end());
iterator dest(begin());
for (;first != last; ++first, ++dest)
{
*dest = uint8(*first);
}
}
};
inline ucstring operator+(const ucstringbase &ucstr, ucchar c)
@ -352,13 +223,16 @@ inline ucstring operator+(const std::string &c, const ucstringbase &ucstr)
return ret;
}
namespace NLMISC
{
namespace NLMISC {
// Traits for hash_map using CEntityId
struct CUCStringHashMapTraits
{
enum { bucket_size = 4, min_buckets = 8 };
enum
{
bucket_size = 4,
min_buckets = 8
};
CUCStringHashMapTraits() { }
size_t operator()(const ucstring &id) const
{

@ -0,0 +1,178 @@
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NLMISC_UTF_STRING_VIEW_H
#define NLMISC_UTF_STRING_VIEW_H
#include <nel/misc/types_nl.h>
#include <string>
#include <nel/misc/string_view.h>
#include <nel/misc/ucstring.h>
namespace NLMISC {
class IStream;
/// String view for UTF-8 and UTF-32 iteration as 32-bit codepoints.
/// This string view keeps the string as a reference, it does not make a copy.
/// Only use this for iterating a string's codepoints.
/// String must be NUL terminated, but its size may specify a substring.
class CUtfStringView
{
public:
inline CUtfStringView() : m_Str(NULL), m_Size(0), m_Iterator(utf32Iterator) {}
inline CUtfStringView(const std::string &utf8Str) : m_Str(utf8Str.c_str()), m_Size(utf8Str.size()), m_Iterator(utf8Iterator) {}
inline CUtfStringView(const char *utf8Str) : m_Str(utf8Str), m_Size(strlen(utf8Str)), m_Iterator(utf8Iterator) {}
inline CUtfStringView(const char *utf8Str, size_t len): m_Str(utf8Str), m_Size(len), m_Iterator(utf8Iterator)
{
nlassert(len <= strlen(utf8Str));
}
inline CUtfStringView(CStringView utf8Str) : m_Str(utf8Str.data()), m_Size(utf8Str.size()), m_Iterator(utf8Iterator) {}
#if defined(NL_OS_WINDOWS)
inline CUtfStringView(const wchar_t *utf16Str) : m_Str(utf16Str), m_Size(wcslen(utf16Str)), m_Iterator(utf16Iterator) {}
inline CUtfStringView(const wchar_t *utf16Str, size_t len): m_Str(utf16Str), m_Size(len), m_Iterator(utf16Iterator)
{
nlassert(len <= wcslen(utf16Str));
}
#else
inline CUtfStringView(const wchar_t *utf32Str) : m_Str(utf32Str), m_Size(wcslen(utf32Str)), m_Iterator(utf32Iterator) {}
inline CUtfStringView(const wchar_t *utf32Str, size_t len): m_Str(utf32Str), m_Size(len), m_Iterator(utf32Iterator)
{
nlassert(len <= wcslen(utf32Str));
}
#endif
inline CUtfStringView(const ucstring &utf16Str) : m_Str(utf16Str.c_str()), m_Size(utf16Str.size() << 1), m_Iterator(utf16Iterator) {}
inline CUtfStringView(const ucchar *utf16Str) : m_Str(utf16Str), m_Size(strlen((const char *)utf16Str) & (ptrdiff_t)(-2)), m_Iterator(utf16Iterator) {}
inline CUtfStringView(const ::u32string &utf32Str) : m_Str(utf32Str.c_str()), m_Size(utf32Str.size() << 2), m_Iterator(utf32Iterator) {}
std::string toUtf8(bool reEncode = false) const; // Makes a copy
ucstring toUtf16(bool reEncode = false) const; // Makes a copy
::u32string toUtf32() const; // Makes a copy
std::wstring toWide() const; // Platform dependent, UTF-16 or UTF-32. Makes a copy.
std::string toAscii() const; // Returns only values 0-127, 7-bit ASCII. Makes a copy.
inline bool isUtf8() const { return m_Iterator == utf8Iterator; }
inline bool isUtf16() const { return m_Iterator == utf16Iterator; }
inline bool isUtf32() const { return m_Iterator == utf32Iterator; }
struct const_iterator
{
public:
inline void operator++()
{
if ((ptrdiff_t)m_Next > ((ptrdiff_t)m_View.m_Str + m_View.m_Size))
m_Next = (void *)((ptrdiff_t)m_View.m_Str + m_View.m_Size);
m_Addr = m_Next;
m_Char = m_View.m_Iterator(&m_Next);
}
inline void operator+=(ptrdiff_t a)
{
while ((ptrdiff_t)m_Addr < ((ptrdiff_t)m_View.m_Str + m_View.m_Size))
{
++(*this);
}
}
inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; }
inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; }
inline const u32char &operator*() const { return m_Char; }
const_iterator() : m_View(*(CUtfStringView *)NULL), m_Addr(NULL), m_Char(0) { }
const_iterator &operator=(const const_iterator &other)
{
if (this == &other) return *this;
this->~const_iterator();
return *new(this) const_iterator(other);
}
const void *ptr() const { return m_Addr; }
private:
friend class CUtfStringView;
inline const_iterator(const CUtfStringView &view, const void *addr) : m_View(view), m_Addr(addr), m_Next(addr), m_Char(view.m_Iterator(&m_Next))
{
if ((ptrdiff_t)m_Next > ((ptrdiff_t)m_View.m_Str + m_View.m_Size))
m_Next = (void *)((ptrdiff_t)m_View.m_Str + m_View.m_Size);
}
inline const_iterator(const CUtfStringView &view) : m_View(view), m_Addr((char *)view.m_Str + view.m_Size), m_Next((char *)view.m_Str + view.m_Size + 1), m_Char(0) { }
const CUtfStringView &m_View;
const void *m_Addr; // Current address
const void *m_Next; // Next address
u32char m_Char;
};
typedef const_iterator iterator;
iterator begin() const { return iterator(*this, m_Str); }
inline iterator end() const { return iterator(*this); }
/// Largest possible number of characters in this string.
/// Number of actual characters may be less or equal.
inline size_t largestSize() const { return m_Size; }
inline bool empty() const { return !m_Size; }
const void *ptr() const { return m_Str; }
size_t count() const; //< Slow count of UTF-32 codepoints
ptrdiff_t offset(ptrdiff_t i); const //< Get byte offset by utf-32 codepoint index
inline CUtfStringView substr(const iterator &begin, const iterator &end) const
{
return CUtfStringView(begin.m_Addr, (ptrdiff_t)end.m_Addr - (ptrdiff_t)begin.m_Addr, m_Iterator);
}
inline bool endsWith(char c) { nlassert(c < 0x80); return *((char *)m_Str + m_Size - 1) == c; }
CUtfStringView &operator=(const CUtfStringView &other)
{
if(this == &other) return *this;
this->~CUtfStringView();
return *new(this) CUtfStringView(other);
}
static void append(std::string &str, u32char c);
/// Encode or decode a single UTF-8 character in a stream (also useful for packing unsigned 20-bit integers)
static void append(IStream &s, u32char c);
static u32char get(IStream &s);
/// Get an UTF-8 string from an undefined ASCII-based codepage, without attempting to convert non-7-bit characters
static std::string fromAscii(const std::string &str);
private:
typedef u32char (*TIterator)(const void **addr);
static u32char utf8Iterator(const void **addr);
static u32char utf16Iterator(const void **addr);
static u32char utf32Iterator(const void **addr);
inline CUtfStringView(const void *str, size_t len, TIterator it) : m_Str(str), m_Size(len), m_Iterator(it) { }
const void *const m_Str; // String
const size_t m_Size; // Size in bytes
const TIterator m_Iterator;
}; /* class CUtfStringView */
} /* namespace NLMISC */
#endif /* #ifndef NLMISC_UTF_STRING_VIEW_H */
/* end of file */

@ -3,6 +3,7 @@
//
// This source file has been modified by the following contributors:
// Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -36,7 +37,7 @@ namespace NLMISC {
class CWinEventEmitter : public IEventEmitter
{
public:
CWinEventEmitter () : _MouseEventsEnabled(true), _KeyboardEventsEnabled(true), _IMEEventsEnabled(true)
CWinEventEmitter () : _Utf16Pair(0), _MouseEventsEnabled(true), _KeyboardEventsEnabled(true), _IMEEventsEnabled(true)
{
_HWnd=NULL;
resetButtonFlagState ();
@ -106,6 +107,7 @@ public:
private:
CWinEventServer _InternalServer;
HWND _HWnd;
wchar_t _Utf16Pair;
public:
// private: may need to be in sync with direct input flags however...
bool _CtrlButton;

@ -1,74 +0,0 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef XML_MACROS_H
#define XML_MACROS_H
//
// xmlNodePtr cur;
// CXMLAutoPtr prop;
//
// sint i;
// XML_READ_SINT(cur, "prop_name", i, -1);
//
#define XML_READ_UINT(node, name, var, def) { \
uint tmp; \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop && fromString((const char*)prop, tmp)) \
var = tmp; \
else \
var = def; \
}
#define XML_READ_SINT(node, name, var, def) { \
sint tmp; \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop && fromString((const char*)prop, tmp)) \
var = tmp; \
else \
var = def; \
}
#define XML_READ_BOOL(node, name, var, def) { \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop) \
var = NLMISC::toBool((const char*)prop); \
else \
var = def; \
}
#define XML_READ_COLOR(node, name, var, def) { \
NLMISC::CRGBA tmp; \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop && fromString((const char*)prop, tmp)) \
var = tmp; \
else \
var = def; \
}
#define XML_READ_STRING(node, name, var, def) { \
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
if (prop) \
var = (const char*)prop; \
else \
var = def; \
}
#endif // XML_MACROS_H

@ -56,6 +56,10 @@ extern uint32 NbNetworkTask;
enum TPipeWay { PipeRead, PipeWrite };
#endif
#ifdef NL_OS_WINDOWS
typedef void *HANDLE;
#endif
/**
* Layer 1
@ -78,7 +82,7 @@ public:
/// Destructor
virtual ~CBufNetBase();
#ifdef NL_OS_UNIX
#if defined(NL_OS_UNIX)
/** Init the pipe for data available with an external pipe.
* Call it only if you set initPipeForDataAvailable to false in the constructor.
* Then don't call sleepUntilDataAvailable() but use select() on the pipe.
@ -89,6 +93,11 @@ public:
_DataAvailablePipeHandle[PipeRead] = twoPipeHandles[PipeRead];
_DataAvailablePipeHandle[PipeWrite] = twoPipeHandles[PipeWrite];
}
#elif defined(NL_OS_WINDOWS)
void setExternalPipeForDataAvailable(HANDLE eventHandle)
{
_DataAvailableHandle = eventHandle;
}
#endif
/// Sets callback for detecting a disconnection (or NULL to disable callback)
@ -201,9 +210,11 @@ protected:
/// Return _DataAvailable
bool dataAvailableFlag() const { return _DataAvailable; }
#ifdef NL_OS_UNIX
#if defined(NL_OS_UNIX)
/// Pipe to select() on data available
int _DataAvailablePipeHandle [2];
#elif defined(NL_OS_WINDOWS)
HANDLE _DataAvailableHandle;
#endif
private:

@ -1,6 +1,9 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
@ -635,7 +638,7 @@ protected:
/// Auto-reconnect
void autoReconnect( CUnifiedConnection &uc, uint connectionIndex );
#ifdef NL_OS_UNIX
#if defined(NL_OS_UNIX) || defined(NL_OS_WINDOWS)
/// Sleep (implemented by select())
void sleepUntilDataAvailable( NLMISC::TTime msecMax );
#endif
@ -662,6 +665,7 @@ private:
std::vector<TCallbackArgItem> _UpUniCallback;
TNameMappedCallback _DownCallbacks;
std::vector<TCallbackArgItem> _DownUniCallback;
std::set<std::pair<std::string, TServiceId>> _NotifiedUpCallbacks;
/// Recording state
CCallbackNetBase::TRecordingState _RecordingState;
@ -696,9 +700,11 @@ private:
/// for each services, which network to take
std::vector<std::string> _DefaultNetwork;
#ifdef NL_OS_UNIX
#if defined(NL_OS_UNIX)
/// Pipe to select() on data available (shared among all connections)
int _MainDataAvailablePipe [2];
#elif defined(NL_OS_WINDOWS)
HANDLE _MainDataAvailableHandle;
#endif
/// Service id of the running service

@ -9,6 +9,9 @@
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
// Copyright (C) 2008-2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This source file has been modified by the following contributors:
// Copyright (C) 2016 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the

@ -1,5 +1,5 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2018 Winch Gate Property Limited
// Copyright (C) 2018-2019 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>

@ -10,6 +10,9 @@
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
// Copyright (C) 2008-2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
//
// This source file has been modified by the following contributors:
// Copyright (C) 2016 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the

@ -1,5 +1,5 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2016 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>

@ -1,5 +1,5 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2010-2020 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save