Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
- Create a folder called "files" in your www folder and paste init.lua, modules, data, and exe files
- Uncomment and change this line (https://github.com/mehah/otclient/blob/main/init.lua#L6)
- Colored text [@conde2](https://github.com/conde2)
- ex: widget:setColoredText("{Colored text, #ff00ff} normal text")
- widget:setColoredText("{Colored text, #ff00ff} normal text")
- QR Code support, with auto generate it from string [@conde2]
- qr-code-border: 2
- qr-code: Hail OTClient Redemption - Conde2 Dev

##### [OTClient V8](https://github.com/OTCv8) (Features)
- Lighting System
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ set(SOURCE_FILES
framework/stdext/string.cpp
framework/stdext/time.cpp
framework/stdext/uri.cpp
framework/stdext/qrcodegen.cpp
framework/ui/uianchorlayout.cpp
framework/ui/uiboxlayout.cpp
framework/ui/uigridlayout.cpp
Expand Down
28 changes: 27 additions & 1 deletion src/framework/graphics/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <framework/graphics/apngloader.h>

#include "framework/stdext/math.h"
#include "framework/stdext/qrcodegen.h"

using namespace qrcodegen;

Image::Image(const Size& size, int bpp, uint8_t* pixels) : m_size(size), m_bpp(bpp)
{
Expand Down Expand Up @@ -242,4 +245,27 @@ void Image::reverseChannels()
for (uint8_t* itr = pixelData; itr < pixelData + m_pixels.size(); itr += m_bpp) {
std::swap(*(itr + 0), *(itr + 2));
}
}
}

ImagePtr Image::fromQRCode(const std::string& code, int border)
{
try
{
QrCode qrCode = QrCode::encodeText(code.c_str(), QrCode::Ecc::MEDIUM);

const auto size = qrCode.getSize();
ImagePtr image(new Image(Size(size + border * 2, size + border * 2)));

for (int x = 0; x < size + border * 2; ++x) {
for (int y = 0; y < size + border * 2; ++y) {
image->setPixel(x, y, qrCode.getModule(x - border, y - border) ? Color::black : Color::white);
}
}

return image;
} catch (const std::exception& e) {
g_logger.error(stdext::format("Failed to encode qr-code: '%s': %s", code, e.what()));
}

return {};
}
1 change: 1 addition & 0 deletions src/framework/graphics/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Image

static ImagePtr load(const std::string& file);
static ImagePtr loadPNG(const std::string& file);
static ImagePtr fromQRCode(const std::string& code, int border);

void savePNG(const std::string& fileName);

Expand Down
1 change: 1 addition & 0 deletions src/framework/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getFont", &UIWidget::getFont);
g_lua.bindClassMemberFunction<UIWidget>("getTextSize", &UIWidget::getTextSize);
g_lua.bindClassMemberFunction<UIWidget>("hasShader", &UIWidget::hasShader);
g_lua.bindClassMemberFunction<UIWidget>("setQRCode", &UIWidget::setQRCode);

// UILayout
g_lua.registerClass<UILayout>();
Expand Down
Loading