Files
Toolbox/main.cpp
OSK\schmidt eb2e13ee08 Add icons and highlight.js to project
This commit includes the addition of a new toolbox icon in both .ico and .png formats, updating the resource file to reference the new icon. In addition, numerous highlight.js files and styles have been integrated into the project, enhancing syntax highlighting capabilities. Existing file references in 'out_embed/all.hpp' have been updated accordingly.
2024-12-05 14:39:16 +01:00

102 lines
3.0 KiB
C++

#include <iostream>
#include <saucer/smartview.hpp>
#include <saucer/webview.hpp>
#include <windows.h>
#include "modules/hwnd_module.h"
#include "all.hpp"
#include <sol/sol.hpp>
int main(int argc, char** argv)
{
// Initialisiere die Saucer-Anwendung
auto app = saucer::application::acquire({
.id = "toolbox",
});
saucer::smartview<saucer::default_serializer, hwnd_module> webview({
.application = app,
});
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
// Berechne die relativen Fenstermaße
int windowWidth = static_cast<int>(screenWidth * (400.0 / 1920.0));
int windowHeight = static_cast<int>(screenHeight * (600.0 / 1080.0));
webview.set_size(windowWidth, windowHeight);
webview.set_force_dark_mode(true);
int xPos = screenWidth - windowWidth; // 400 ist die Fensterbreite
int yPos = screenHeight - 42 - windowHeight; // 600 ist die Fensterhöhe
// Zugriff auf das native Fenster-Handle
HWND hwnd = webview.module<hwnd_module>().get_hwnd();
if (hwnd) {
// Setze die Fensterposition auf (x: 100, y: 100)
SetWindowPos(hwnd, nullptr, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
// Erstelle ein WebView-Fenster
webview.expose(
"add_random",
[&](float number)
{
auto random = webview.evaluate<float>("Math.random()").get();
return number + random;
},
saucer::launch::async);
// Lade die eingebettete "index.html" aus den Ressourcen
auto resources = saucer::embedded::all();
if (resources.find("html/card.html") == resources.end()) {
std::cerr << "Fehler: 'card.html' wurde nicht gefunden!" << std::endl;
return 1;
}
// Überprüfen, ob die "index.html"-Ressource verfügbar ist
auto it = resources.find("html/index.html");
if (it == resources.end())
{
std::cerr << "Fehler: 'index.html' wurde nicht gefunden!" << std::endl;
return 1;
}
webview.embed(resources); // Bindet alle eingebetteten Ressourcen ein
webview.serve("html/index.html"); // Stellt "index.html" bereit
webview.set_context_menu(false);
if (resources.find("ico/toolbox.png")== resources.end())
{
std::cerr << "Fehler: 'toolbox.png' wurde nicht gefunden!" << std::endl;
return 1;
}
// Erstellen eines saucer::icon-Objekts aus den eingebetteten Bilddaten
saucer::icon window_icon;
window_icon = window_icon.from(resources.find("ico/toolbox.png")->second.content).value();
// Setzen des Fenster-Icons mit dem erstellten saucer::icon-Objekt
webview.set_icon(window_icon);
webview.set_title("Toolbox");
webview.register_scheme("Toolbox");
// Zeige das Fenster an
webview.show();
// Lua-Umgebung erstellen
sol::state lua;
// Standardbibliotheken öffnen
lua.open_libraries(sol::lib::base);
// Weitere Implementierung folgt...
// Lua-Code ausführen
lua.script("print('Hallo von Lua!')");
// Starte die Saucer-Anwendung
app->run();
}