Skip to content

Instantly share code, notes, and snippets.

@mik30s
Created June 14, 2019 01:42
Show Gist options
  • Save mik30s/e4bcc56d5e64b3c8f91f32e5a2cf9f9c to your computer and use it in GitHub Desktop.
Save mik30s/e4bcc56d5e64b3c8f91f32e5a2cf9f9c to your computer and use it in GitHub Desktop.
#include <AppCore/App.h>
#include <AppCore/Window.h>
#include <AppCore/Overlay.h>
#include <AppCore/JSHelpers.h>
#include <iostream>
#include <Ultralight/Ultralight.h>
#include <spdlog/spdlog.h>
#include <SFML/Window/VideoMode.hpp>
#include "ui_def.hpp"
#include "util.hpp"
using namespace ultralight;
using ultralight::JSObject;
using ultralight::JSArgs;
using ultralight::JSFunction;
class FiltApp : public WindowListener, public LoadListener {
RefPtr<App> app_;
RefPtr<Window> window_;
RefPtr<Overlay> overlay_;
public:
FiltApp() {
ultralight::DefaultFontLoader();
///
/// Create our main App instance.
///
app_ = App::Create();
///
/// Create our Window with the Resizable window flag.
///
window_ = Window::Create(app_->main_monitor(), 1240, 768, false,
kWindowFlags_Titled | kWindowFlags_Resizable );
///
/// Set our window title.
///
window_->SetTitle("Filt");
///
/// Bind our App's main window.
///
/// @note This MUST be done before creating any overlays or calling App::Run
///
app_->set_window(*window_.get());
///
/// Create our Overlay, use the same dimensions as our Window.
///
overlay_ = Overlay::Create(*window_.get(), window_->width(), window_->height(), 0, 0);
///
/// Load a string of HTML into our overlay's View
///
overlay_->view()->LoadHTML(String((const char*)ui_string, ui_string_len));
///
/// Register our MyApp instance as a WindowListener so we can handle the
/// Window's OnResize event below.
///
window_->set_listener(this);
overlay_->view()->set_load_listener(this);
///
/// Export global functions to js
///
// Set the context for all subsequent JS* calls
SetJSContext(overlay_->view()->js_context());
JSObject global = JSGlobalObject();
/// export error loggin function
global["FiltLogError"] = BindJSCallback(&FiltApp::logError);
}
virtual ~FiltApp() {}
void logError(const JSObject& obj, const JSArgs& args) {
ultralight::String argString = JSArgsToString(args);
std::cout << "here\n";
spdlog::error("[js_log] {}", argString.utf8().data());
}
void OnDOMReady(ultralight::View* caller) override {
}
///
/// Inherited from WindowListener, not used.
///
virtual void OnClose() override {}
///
/// Inherited from WindowListener, called when the Window is resized.
///
virtual void OnResize(uint32_t width, uint32_t height) override {
///
/// Resize our Overlay to match the new Window dimensions.
///
spdlog::info("{}x{}",width,height);
overlay_->Resize(width, height);
}
void Run() {
app_->Run();
}
};
int main() {
FiltApp app;
app.Run();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment