Skip to content

Commit 4e27179

Browse files
committed
Squash commits
1 parent 689619c commit 4e27179

539 files changed

Lines changed: 39331 additions & 44814 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3rdparty/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ if((WINDOWS AND NOT WINRT) OR MACOSX OR LINUX)
354354
list(APPEND _glfw_options "GLFW_BUILD_X11 ON")
355355
if(AX_ENABLE_WAYLAND)
356356
list(APPEND _glfw_options "GLFW_BUILD_WAYLAND ON")
357+
else()
358+
list(APPEND _glfw_options "GLFW_BUILD_WAYLAND OFF")
357359
endif()
358360
endif()
359361
ax_add_3rd(glfw OPTIONS ${_glfw_options})

CMakeOptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- AX_ENABLE_3D: whether to enable 3D support, default: `TRUE`
1212
- AX_ENABLE_PHYSICS_3D: whether to enable physics3d support, default: `TRUE`
1313
- AX_ENABLE_NAVMESH: whether to enable NavMesh support default: `TRUE`
14-
- AX_ENABLE_MEDIA: whether to enable media support, default: `TRUE`
14+
- AX_ENABLE_VIDEO: whether to enable video player, default: `TRUE`
1515
- AX_ENABLE_AUDIO: whether to enable audio support, default: `TRUE`
1616
- AX_ENABLE_CONSOLE: whether to enable debug tool console support, default: `TRUE`
1717
- AX_ENABLE_OPUS: whether to enable audio engine play .opus files support, default: `TRUE`

INFRA.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Microsoft.Windows.CppWinRT
44

55
- [![nuget](https://img.shields.io/nuget/v/Microsoft.Windows.CppWinRT?label=Upstream)](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT)
6-
- Version: 2.0.250303.1
6+
- Version: 3.0.260520.1
77
- License: MIT
88
- Platform: WinRT/WinUWP
99
- Manged by: `cmake/Modules/AXConfigDefine.cmake`

axmol/2d/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ set(_AX_2D_HEADER
2929
2d/ClippingRectangleNode.h
3030
2d/ActionEase.h
3131
2d/ProtectedNode.h
32-
2d/TextFieldTTF.h
3332
2d/AnimationCache.h
3433
2d/FastTMXLayer.h
3534
2d/FontAtlasCache.h
@@ -116,7 +115,6 @@ set(_AX_2D_SRC
116115
2d/SpriteFrameCache.cpp
117116
2d/SpriteFrame.cpp
118117
2d/AutoPolygon.cpp
119-
2d/TextFieldTTF.cpp
120118
2d/TileMapAtlas.cpp
121119

122120
# 2d/TMXLayer.cpp

axmol/2d/ClippingRectangleNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void ClippingRectangleNode::onBeforeVisitScissor()
7979
}
8080

8181
const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y));
82-
RenderView* renderView = _director->getRenderView();
82+
auto renderView = _director->getRenderView();
8383
renderView->setScissorInPoints(pos.x, pos.y, _clippingRegion.size.width * scaleX,
8484
_clippingRegion.size.height * scaleY);
8585
}

axmol/2d/Label.cpp

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "axmol/renderer/Shaders.h"
5151
#include "axmol/rhi/ProgramState.h"
5252
#include "axmol/renderer/ProgramStateRegistry.h"
53+
#include "yasio/tlx/string_view.hpp"
5354

5455
namespace ax
5556
{
@@ -227,11 +228,31 @@ std::array<CustomCommand*, 3> Label::BatchCommand::getCommandArray()
227228

228229
Label* Label::create()
229230
{
230-
auto ret = new Label;
231+
auto ret = new Label();
231232
ret->autorelease();
232233
return ret;
233234
}
234235

236+
Label* Label::create(std::string_view text, std::string_view fontName, float fontSize)
237+
{
238+
if (FileUtils::getInstance()->isFileExist(fontName))
239+
{
240+
if (tlx::ic::ends_with(fontName, ".fnt"))
241+
{
242+
return Label::createWithBMFont(fontName, text);
243+
}
244+
else
245+
{
246+
TTFConfig config(fontName, fontSize);
247+
return Label::createWithTTF(config, text);
248+
}
249+
}
250+
else
251+
{
252+
return Label::createWithSystemFont(text, fontName, fontSize);
253+
}
254+
}
255+
235256
Label* Label::createWithSystemFont(std::string_view text,
236257
std::string_view font,
237258
float fontSize,
@@ -392,6 +413,31 @@ Label* Label::createWithCharMap(std::string_view charMapFile, int itemWidth, int
392413
return nullptr;
393414
}
394415

416+
void Label::setFontInfo(std::string_view fontName, float fontSize)
417+
{
418+
auto prevLableType = _currentLabelType;
419+
if (FileUtils::getInstance()->isFileExist(fontName))
420+
{
421+
if (tlx::ic::ends_with(fontName, ".fnt"sv))
422+
{
423+
setBMFontFilePath(fontName);
424+
}
425+
else
426+
{
427+
TTFConfig ttfConfig(fontName, fontSize, GlyphCollection::DYNAMIC);
428+
setTTFConfig(ttfConfig);
429+
}
430+
}
431+
else
432+
{
433+
setSystemFontName(fontName);
434+
setSystemFontSize(fontSize);
435+
436+
if (prevLableType == LabelType::STRING_TEXTURE)
437+
requestSystemFontRefresh();
438+
}
439+
}
440+
395441
bool Label::setCharMap(std::string_view plistFile)
396442
{
397443
auto newAtlas = FontAtlasCache::getFontAtlasCharMap(plistFile);
@@ -569,7 +615,6 @@ void Label::reset()
569615
_currLabelEffect = LabelEffect::NORMAL;
570616
_contentDirty = false;
571617
_numberOfLines = 0;
572-
_lengthOfString = 0;
573618
_utf32Text.clear();
574619
_utf8Text.clear();
575620

@@ -907,15 +952,19 @@ bool Label::setBMFontFilePath(std::string_view bmfontFilePath, std::string_view
907952

908953
void Label::setString(std::string_view text)
909954
{
910-
if (text.compare(_utf8Text))
955+
if (text != _utf8Text)
911956
{
912-
_utf8Text = text;
913-
_contentDirty = true;
914-
915957
std::u32string utf32String;
916-
if (text_utils::UTF8ToUTF32(_utf8Text, utf32String))
958+
if (text_utils::UTF8ToUTF32(text, utf32String))
917959
{
960+
_utf8Text = text;
918961
_utf32Text = utf32String;
962+
963+
_contentDirty = true;
964+
}
965+
else
966+
{
967+
AXLOGE("Label: setString() - Invalid utf8 text: {}", text);
919968
}
920969
}
921970
}
@@ -1006,7 +1055,7 @@ void Label::updateLabelLetters()
10061055
letterIndex = it->first;
10071056
letterSprite = (LabelLetter*)it->second;
10081057

1009-
if (letterIndex >= _lengthOfString)
1058+
if (letterIndex >= getCharCount())
10101059
{
10111060
Node::removeChild(letterSprite, true);
10121061
it = _letters.erase(it);
@@ -1102,7 +1151,6 @@ void Label::alignText()
11021151

11031152
bool Label::tryTextPlacement(float fontSize)
11041153
{
1105-
_lengthOfString = 0;
11061154
_textDesiredHeight = 0.f;
11071155
_linesWidth.clear();
11081156

@@ -1212,7 +1260,7 @@ bool Label::updateQuads()
12121260
batchNode->getTextureAtlas()->removeAllQuads();
12131261
}
12141262

1215-
for (int ctr = 0; ctr < _lengthOfString; ++ctr)
1263+
for (int ctr = 0; ctr < getCharCount(); ++ctr)
12161264
{
12171265
auto& letterInfo = _lettersInfo[ctr];
12181266
if (letterInfo.valid)
@@ -2066,7 +2114,7 @@ void Label::updateEffectUniforms(BatchCommand& batch,
20662114

20672115
void Label::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
20682116
{
2069-
if (_batchNodes.empty() || _lengthOfString <= 0)
2117+
if (_batchNodes.empty() || _utf32Text.empty())
20702118
{
20712119
return;
20722120
}
@@ -2297,7 +2345,7 @@ Sprite* Label::getLetter(int letterIndex)
22972345
updateContent();
22982346
}
22992347

2300-
if (_textSprite == nullptr && letterIndex < _lengthOfString)
2348+
if (_textSprite == nullptr && letterIndex < getCharCount())
23012349
{
23022350
const auto& letterInfo = _lettersInfo[letterIndex];
23032351
if (!letterInfo.valid || letterInfo.atlasIndex < 0)
@@ -2424,25 +2472,24 @@ void Label::computeStringNumLines()
24242472
_numberOfLines = quantityOfLines;
24252473
}
24262474

2427-
int Label::getStringNumLines()
2475+
int Label::getLineCount() const
24282476
{
24292477
if (_contentDirty)
24302478
{
2431-
updateContent();
2479+
const_cast<Label*>(this)->updateContent();
24322480
}
24332481

24342482
if (_currentLabelType == LabelType::STRING_TEXTURE)
24352483
{
2436-
computeStringNumLines();
2484+
const_cast<Label*>(this)->computeStringNumLines();
24372485
}
24382486

24392487
return _numberOfLines;
24402488
}
24412489

2442-
int Label::getStringLength()
2490+
int Label::getCharCount() const
24432491
{
2444-
_lengthOfString = static_cast<int>(_utf32Text.length());
2445-
return _lengthOfString;
2492+
return static_cast<int>(_utf32Text.length());
24462493
}
24472494

24482495
// RGBA protocol
@@ -2901,7 +2948,7 @@ void Label::updateFontScale()
29012948

29022949
bool Label::multilineTextWrap(bool breakOnChar, bool ignoreOverflow)
29032950
{
2904-
int textLen = getStringLength();
2951+
int textLen = getCharCount();
29052952
int lineIndex = 0;
29062953
float nextTokenX = 0.f;
29072954
float nextTokenY = 0.f;
@@ -3119,7 +3166,7 @@ bool Label::isHorizontalClamp()
31193166
{
31203167
bool letterClamp = false;
31213168

3122-
for (int ctr = 0; ctr < _lengthOfString; ++ctr)
3169+
for (int ctr = 0; ctr < getCharCount(); ++ctr)
31233170
{
31243171
if (_lettersInfo[ctr].valid)
31253172
{

axmol/2d/Label.h

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol
148148
*/
149149
static Label* create();
150150

151+
/**
152+
* @brief Create a Label with automatic font type detection.
153+
*
154+
* This unified factory method creates a Label using the given text and font name.
155+
* The fontName parameter can be:
156+
* - A TTF font file path (e.g. "fonts/arial.ttf")
157+
* - A system font name (e.g. "Arial", "Helvetica")
158+
* - A BMFont file path (e.g. "fonts/myfont.fnt")
159+
*
160+
* Internally, the method will:
161+
* - Use createWithBMFont() if fontName ends with ".fnt"
162+
* - Use createWithTTF() if fontName exists as a TTF file
163+
* - Otherwise, fall back to createWithSystemFont()
164+
*
165+
* @param text The text string to render.
166+
* @param fontName The font resource identifier (TTF path, system font name, or BMFont path).
167+
* @param fontSize The font size in points.
168+
* @return A new Label instance, or nullptr if creation fails.
169+
*
170+
* @note This method simplifies font handling by providing a single entry point.
171+
* Specific createWithTTF(), createWithSystemFont(), and createWithBMFont()
172+
* methods remain available for explicit control.
173+
*/
174+
static Label* create(std::string_view text, std::string_view fontName, float fontSize);
175+
151176
/**
152177
* Allocates and initializes a Label, base on platform-dependent API.
153178
*
@@ -297,6 +322,25 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol
297322
/// @{
298323
/// @name Font methods
299324

325+
/**
326+
* @brief Set font information for the Label.
327+
*
328+
* This method updates the Label's font using the given fontName and fontSize.
329+
* The fontName parameter can be:
330+
* - A TTF font file path (e.g. "fonts/arial.ttf")
331+
* - A system font name (e.g. "Arial", "Helvetica")
332+
* - A BMFont file path (e.g. "fonts/myfont.fnt")
333+
*
334+
* Internally, the method will:
335+
* - Use BMFont if fontName ends with ".fnt"
336+
* - Use TTF if fontName exists as a TTF file
337+
* - Otherwise, fall back to system font
338+
*
339+
* @param fontName The font resource identifier (TTF path, system font name, or BMFont path).
340+
* @param fontSize The font size in points.
341+
*/
342+
void setFontInfo(std::string_view fontName, float fontSize);
343+
300344
/**
301345
* Sets a new TTF configuration to Label.
302346
* @see `TTFConfig`
@@ -376,15 +420,26 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol
376420
/** Return the text the Label is currently displaying.*/
377421
std::string_view getString() const override { return _utf8Text; }
378422

423+
[[internal]] std::u32string_view getUTF32String() const { return _utf32Text; }
424+
379425
/**
380426
* Return the number of lines of text.
381427
*/
382-
int getStringNumLines();
428+
int getLineCount() const;
429+
AX_DEPRECATED(3.0) int getStringNumLines() { return getLineCount(); }
430+
431+
/**
432+
* @brief Returns the number of UTF-32 characters.
433+
*
434+
* @return int UTF-32 character count
435+
*/
436+
int getCharCount() const;
437+
AX_DEPRECATED(3.0) int getStringLength() { return getCharCount(); }
383438

384439
/**
385-
* Return length of string.
440+
* Return whether the text is empty.
386441
*/
387-
int getStringLength();
442+
bool isEmpty() const { return _utf32Text.empty(); }
388443

389444
/**
390445
* Sets the text color of Label.
@@ -835,7 +890,6 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol
835890
float _glowRadius;
836891
float _systemFontSize;
837892

838-
int _lengthOfString;
839893
int _uniformEffectColor;
840894
int _uniformEffectType; // 0: None, 1: Outline, 2: Shadow; Only used when outline is enabled.
841895
int _uniformTextColor;

axmol/2d/Layer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ THE SOFTWARE.
3535
#include "axmol/renderer/Renderer.h"
3636
#include "axmol/base/Director.h"
3737
#include "axmol/base/EventDispatcher.h"
38-
#include "axmol/base/EventListenerTouch.h"
39-
#include "axmol/base/EventTouch.h"
40-
#include "axmol/base/EventKeyboard.h"
41-
#include "axmol/base/EventListenerKeyboard.h"
38+
#include "axmol/base/PointerEventListener.h"
39+
#include "axmol/base/PointerEvent.h"
40+
#include "axmol/base/KeyboardEvent.h"
41+
#include "axmol/base/KeyboardEventListener.h"
4242
#include "axmol/base/EventAcceleration.h"
4343
#include "axmol/base/EventListenerAcceleration.h"
4444
#include "axmol/base/text_utils.h"

0 commit comments

Comments
 (0)