Files @ r28486:aff297ed5a05
Branch filter:

Location: cpp/openttd-patchpack/source/src/strings_func.h - annotation

Peter Nelson
Codechange: Allow constexpr NWidgetPart construction.
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r8114:866ed489ed98
r8114:866ed489ed98
r8114:866ed489ed98
r8114:866ed489ed98
r8114:866ed489ed98
r8114:866ed489ed98
r16701:b670a606abe0
r18413:e892ae4942df
r22547:90170a724532
r27678:af4858e871bd
r27788:71137956fe15
r27050:d85c65824c1e
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r28410:d9c73d685bbc
r22547:90170a724532
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r28410:d9c73d685bbc
r22547:90170a724532
r22551:c6bc232b7c99
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r22547:90170a724532
r28410:d9c73d685bbc
r22547:90170a724532
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22551:c6bc232b7c99
r22547:90170a724532
r8114:866ed489ed98
r25486:ca7a2cc7b166
r8445:07810e0b20bf
r8114:866ed489ed98
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r28410:d9c73d685bbc
r27050:d85c65824c1e
r27050:d85c65824c1e
r27050:d85c65824c1e
r27737:728d55b97775
r27050:d85c65824c1e
r19077:678a82402d65
r27599:5759b29a5967
r27599:5759b29a5967
r27599:5759b29a5967
r19846:75a27628493b
r27788:71137956fe15
r27788:71137956fe15
r27788:71137956fe15
r28112:bca7556a6bb6
r27788:71137956fe15
r27788:71137956fe15
r27788:71137956fe15
r27788:71137956fe15
r27788:71137956fe15
r28112:bca7556a6bb6
r27788:71137956fe15
r27788:71137956fe15
r27599:5759b29a5967
r27599:5759b29a5967
r27688:633ba893f16d
r8114:866ed489ed98
r27678:af4858e871bd
r27678:af4858e871bd
r27683:d2610a2b21c8
r27678:af4858e871bd
r27599:5759b29a5967
r8114:866ed489ed98
r16431:ec558deca9d7
r8114:866ed489ed98
r8114:866ed489ed98
r13271:4bcd60b30aeb
r8114:866ed489ed98
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r27372:06d384d76bd2
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r27295:4dfa0d5adc00
r18413:e892ae4942df
r27295:4dfa0d5adc00
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18413:e892ae4942df
r18415:6464fa585e60
r18424:91195beac0ac
r18424:91195beac0ac
r18424:91195beac0ac
r18424:91195beac0ac
r18424:91195beac0ac
r18424:91195beac0ac
r18415:6464fa585e60
r18415:6464fa585e60
r18415:6464fa585e60
r23737:64ab3885eee6
r18415:6464fa585e60
r26399:db15b808f86d
r18415:6464fa585e60
r24651:d256fd14817f
r18413:e892ae4942df
r18413:e892ae4942df
r23607:36c15679007d
r8114:866ed489ed98
r16849:d593358b4346
/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD 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 General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file strings_func.h Functions related to OTTD's strings. */

#ifndef STRINGS_FUNC_H
#define STRINGS_FUNC_H

#include "strings_type.h"
#include "string_type.h"
#include "gfx_type.h"
#include "core/bitmath_func.hpp"
#include "core/span_type.hpp"
#include "core/strong_typedef_type.hpp"
#include "vehicle_type.h"

/**
 * Extract the StringTab from a StringID.
 * @param str String identifier
 * @return StringTab from \a str
 */
inline StringTab GetStringTab(StringID str)
{
	StringTab result = (StringTab)(str >> TAB_SIZE_BITS);
	if (result >= TEXT_TAB_NEWGRF_START) return TEXT_TAB_NEWGRF_START;
	if (result >= TEXT_TAB_GAMESCRIPT_START) return TEXT_TAB_GAMESCRIPT_START;
	return result;
}

/**
 * Extract the StringIndex from a StringID.
 * @param str String identifier
 * @return StringIndex from \a str
 */
inline uint GetStringIndex(StringID str)
{
	return str - (GetStringTab(str) << TAB_SIZE_BITS);
}

/**
 * Create a StringID
 * @param tab StringTab
 * @param index StringIndex
 * @return StringID composed from \a tab and \a index
 */
inline StringID MakeStringID(StringTab tab, uint index)
{
	if (tab == TEXT_TAB_NEWGRF_START) {
		assert(index < TAB_SIZE_NEWGRF);
	} else if (tab == TEXT_TAB_GAMESCRIPT_START) {
		assert(index < TAB_SIZE_GAMESCRIPT);
	} else {
		assert(tab < TEXT_TAB_END);
		assert(index < TAB_SIZE);
	}
	return (tab << TAB_SIZE_BITS) + index;
}

std::string GetString(StringID string);
const char *GetStringPtr(StringID string);

uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type);
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type);

/**
 * Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
 * @param speed Display speed for parameter.
 * @param type Type of vehicle for parameter.
 * @return Bit-packed velocity and vehicle type, for use with SetDParam().
 */
inline int64_t PackVelocity(uint speed, VehicleType type)
{
	/* Vehicle type is a byte, so packed into the top 8 bits of the 64-bit
	 * parameter, although only values from 0-3 are relevant. */
	return speed | (static_cast<uint64_t>(type) << 56);
}

void SetDParam(size_t n, uint64_t v);
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL);
void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL);

template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void SetDParam(size_t n, T v)
{
	SetDParam(n, v.base());
}

template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void SetDParamMaxValue(size_t n, T max_value, uint min_count = 0, FontSize size = FS_NORMAL)
{
	SetDParamMaxValue(n, max_value.base(), min_count, size);
}

void SetDParamStr(size_t n, const char *str);
void SetDParamStr(size_t n, const std::string &str);
void SetDParamStr(size_t n, std::string &&str);

void CopyInDParam(const span<const StringParameterBackup> backup);
void CopyOutDParam(std::vector<StringParameterBackup> &backup, size_t num);
bool HaveDParamChanged(const std::vector<StringParameterBackup> &backup);

uint64_t GetDParam(size_t n);

extern TextDirection _current_text_dir; ///< Text direction of the currently selected language

void InitializeLanguagePacks();
const char *GetCurrentLanguageIsoCode();

/**
 * A searcher for missing glyphs.
 */
class MissingGlyphSearcher {
public:
	/** Make sure everything gets destructed right. */
	virtual ~MissingGlyphSearcher() = default;

	/**
	 * Get the next string to search through.
	 * @return The next string or nullopt if there is none.
	 */
	virtual std::optional<std::string_view> NextString() = 0;

	/**
	 * Get the default (font) size of the string.
	 * @return The font size.
	 */
	virtual FontSize DefaultSize() = 0;

	/**
	 * Reset the search, i.e. begin from the beginning again.
	 */
	virtual void Reset() = 0;

	/**
	 * Whether to search for a monospace font or not.
	 * @return True if searching for monospace.
	 */
	virtual bool Monospace() = 0;

	/**
	 * Set the right font names.
	 * @param settings  The settings to modify.
	 * @param font_name The new font name.
	 * @param os_data Opaque pointer to OS-specific data.
	 */
	virtual void SetFontNames(struct FontCacheSettings *settings, const char *font_name, const void *os_data = nullptr) = 0;

	bool FindMissingGlyphs();
};

void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = nullptr);

#endif /* STRINGS_FUNC_H */