Skip to content

Commit

Permalink
Merging in new 1.3 branch changes (API breaking changes!), adds multi…
Browse files Browse the repository at this point in the history
…-window support (see Sample 9) and allows each View to have their own DPI scale among other changes (see ViewConfig). Shader code and GPU driver implementations have also undergone some changes-- we no longer blend in linear gamma space, all fonts are now composited in sRGB with a custom alpha-correction ramp.
  • Loading branch information
adamjs committed Mar 11, 2021
1 parent adcae14 commit 705f20a
Show file tree
Hide file tree
Showing 435 changed files with 3,840 additions and 176 deletions.
8 changes: 4 additions & 4 deletions Deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ elseif (PORT MATCHES "UltralightWin")
endif ()
endif ()

set(ULTRALIGHTCORE_REV "96fdb30c")
set(WEBCORE_REV "88630b80")
set(ULTRALIGHT_REV "193592e1")
set(APPCORE_REV "b4326cd")
set(ULTRALIGHTCORE_REV "a4c802a6")
set(WEBCORE_REV "64ab2718")
set(ULTRALIGHT_REV "3b5156ba")
set(APPCORE_REV "78e8f10")

set(ULTRALIGHTCORE_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps/UltralightCore/")
set(WEBCORE_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps/WebCore/")
Expand Down
2 changes: 2 additions & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ add_subdirectory("Sample 5 - File Loading")
add_subdirectory("Sample 6 - Intro to C API")
add_subdirectory("Sample 7 - OpenGL Integration")
add_subdirectory("Sample 8 - Web Browser")
add_subdirectory("Sample 9 - Multi Window")

if (${IN_SOURCE_BUILD})
add_custom_target(
Expand Down Expand Up @@ -93,4 +94,5 @@ if (${IN_SOURCE_BUILD})
add_dependencies(Sample6 CopySDK)
add_dependencies(Sample7 CopySDK)
add_dependencies(Sample8 CopySDK)
add_dependencies(Sample9 CopySDK)
endif ()
37 changes: 19 additions & 18 deletions samples/Sample 1 - Render to PNG/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,17 @@ class MyApp : public LoadListener,
public:
MyApp() {
///
/// Setup our config. The config can be used to customize various
/// options within the renderer and WebCore module.
///
/// Our config uses 2x DPI scale and "Arial" as the default font.
///
Config config;
config.device_scale = 2.0;
config.font_family_standard = "Arial";

///
/// Setup our config.
///
/// We need to tell config where our resources are so it can load our
/// bundled certificate chain and make HTTPS requests.
/// bundled certificate chain to make HTTPS requests and perform text layout
/// using the ICU unicode data library.
///
/// *NOTE* Failure to load the ICU library may cause the library to crash
/// during certain text layout operations. Check the log for warnings.
///
Config config;
config.resource_path = "./resources/";

///
/// Make sure the GPU renderer is disabled so we can render to an offscreen
/// pixel buffer surface.
///
config.use_gpu_renderer = false;

///
/// Pass our configuration to the Platform singleton so that the library
Expand Down Expand Up @@ -97,8 +88,18 @@ class MyApp : public LoadListener,
/// Create our View.
///
/// Views are sized containers for loading and displaying web content.
///
/// Our view config uses 2x DPI scale and "Arial" as the default font.
///
/// We make sure GPU acceleration is disabled so we can render to an
/// offscreen pixel buffer surface.
///
view_ = renderer_->CreateView(1600, 1600, false, nullptr);
ViewConfig view_config;
view_config.initial_device_scale = 2.0;
view_config.font_family_standard = "Arial";
view_config.is_accelerated = false;

view_ = renderer_->CreateView(1600, 1600, view_config, nullptr);

///
/// Register our MyApp instance as a load listener so we can handle the
Expand Down
132 changes: 84 additions & 48 deletions samples/Sample 2 - Basic App/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,101 @@ const char* htmlString();
///
/// We will create the simplest possible AppCore application in this sample.
///
int main() {
///
/// Create our main App instance.
///
/// The App class is responsible for the lifetime of the application
/// and is required to create any windows.
///
Ref<App> app = App::Create();

///
/// Create our Window.
///
/// This command creates a native platform window and shows it immediately.
///
/// The window's size (400 by 400) is in virtual device coordinates, the
/// actual size in pixels is automatically determined by the monitor's DPI.
///
Ref<Window> window = Window::Create(app->main_monitor(), 900, 600, false,
kWindowFlags_Titled);

///
/// Set the title of our window.
///
window->SetTitle("Ultralight Sample 2 - Basic App");
class MyApp : public WindowListener,
public ViewListener {
RefPtr<App> app_;
RefPtr<Window> window_;
RefPtr<Overlay> overlay_;
public:
MyApp() {
///
/// Create our main App instance.
///
/// The App class is responsible for the lifetime of the application
/// and is required to create any windows.
///
app_ = App::Create();

///
/// Tell our app to use 'window' as our main window.
///
/// This call is required before creating any overlays or calling App::Run
///
/// **Note**:
/// As of v1.1, AppCore only supports one window per application which is
/// why this call is required. This API method will be deprecated once
/// multi-monitor and multi-window support is added in v1.2.
///
app->set_window(window);
///
/// Create our Window.
///
/// This command creates a native platform window and shows it immediately.
///
/// The window's size (900 by 600) is in virtual device coordinates, the
/// actual size in pixels is automatically determined by the monitor's DPI.
///
window_ = Window::Create(app_->main_monitor(), 900, 600, false,
kWindowFlags_Titled);

///
/// Set the title of our window.
///
window_->SetTitle("Ultralight Sample 2 - Basic App");

///
/// Create a web-content overlay that spans the entire window.
///
/// You can create multiple overlays per window, each overlay has its own
/// View which can be used to load and display web-content.
///
/// AppCore automatically manages focus, keyboard/mouse input, and GPU
/// painting for each active overlay. Destroying the overlay will remove
/// it from the window.
///
overlay_ = Overlay::Create(*window_, window_->width(), window_->height(), 0, 0);

///
/// Load a string of HTML into our overlay's View
///
overlay_->view()->LoadHTML(htmlString());

///
/// Register our MyApp instance as a WindowListener so we can handle the
/// Window's OnClose event below.
///
window_->set_listener(this);

///
/// Register our MyApp instance as a ViewListener so we can handle the
/// View's OnChangeCursor event below.
///
overlay_->view()->set_view_listener(this);
}

virtual ~MyApp() {}

///
/// Create a web-content overlay that spans the entire window.
///
/// You can create multiple overlays per window, each overlay has its own
/// View which can be used to load and display web-content.
///
/// AppCore automatically manages focus, keyboard/mouse input, and GPU
/// painting for each active overlay. Destroying the overlay will remove
/// it from the window.
/// Inherited from WindowListener, called when the Window is closed.
///
/// We exit the application when the window is closed.
///
Ref<Overlay> overlay = Overlay::Create(window, window->width(),
window->height(), 0, 0);
virtual void OnClose(ultralight::Window* window) override {
app_->Quit();
}

///
/// Load a string of HTML into our overlay's View
/// Inherited from WindowListener, called when the Window is resized.
///
/// (Not used in this sample)
///
overlay->view()->LoadHTML(htmlString());
virtual void OnResize(ultralight::Window* window, uint32_t width, uint32_t height) override {}

///
/// Run our main loop.
/// Inherited from ViewListener, called when the Cursor changes.
///
app->Run();
virtual void OnChangeCursor(ultralight::View* caller, ultralight::Cursor cursor) override {
window_->SetCursor(cursor);
}

void Run() {
app_->Run();
}
};

int main() {
MyApp app;
app.Run();

return 0;
}
Expand Down
28 changes: 12 additions & 16 deletions samples/Sample 3 - Resizable App/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,19 @@ class MyApp : public WindowListener,
///
window_->SetTitle("Ultralight Sample 3 - Resize Me!");

///
/// Tell our app to use 'window' as our main window.
///
/// This call is required before creating any overlays or calling App::Run
///
app_->set_window(*window_.get());

///
/// Create the overlays for our left and right panes-- we don't care about
/// their initial size and position because they'll be set when we call
/// OnResize() below.
///
left_pane_ = Overlay::Create(*window_.get(), 1, 1, 0, 0);
right_pane_ = Overlay::Create(*window_.get(), 1, 1, 0, 0);
left_pane_ = Overlay::Create(*window_.get(), 100, 100, 0, 0);
right_pane_ = Overlay::Create(*window_.get(), 100, 100, 0, 0);

///
/// Force a call to OnResize to perform initial layout and sizing of our
/// left and right overlays.
///
OnResize(window_->width(), window_->height());
OnResize(window_.get(), window_->width(), window_->height());

///
/// Load some HTML into our left and right overlays.
Expand All @@ -109,15 +102,19 @@ class MyApp : public WindowListener,
virtual ~MyApp() {}

///
/// Inherited from WindowListener, not used.
/// Inherited from WindowListener, called when the Window is closed.
///
/// We exit the application when the window is closed.
///
virtual void OnClose() override {}
virtual void OnClose(ultralight::Window* window) override {
app_->Quit();
}

///
/// Inherited from WindowListener, called when the Window is resized.
///
virtual void OnResize(uint32_t width, uint32_t height) override {
uint32_t left_pane_width_px = window_->DeviceToPixels(LEFT_PANE_WIDTH);
virtual void OnResize(ultralight::Window* window, uint32_t width, uint32_t height) override {
uint32_t left_pane_width_px = window_->ScreenToPixels(LEFT_PANE_WIDTH);
left_pane_->Resize(left_pane_width_px, height);

// Calculate the width of our right pane (window width - left width)
Expand All @@ -135,8 +132,7 @@ class MyApp : public WindowListener,
///
/// Inherited from ViewListener, called when the Cursor changes.
///
virtual void OnChangeCursor(ultralight::View* caller,
Cursor cursor) {
virtual void OnChangeCursor(ultralight::View* caller, ultralight::Cursor cursor) override {
window_->SetCursor(cursor);
}

Expand Down
Loading

0 comments on commit 705f20a

Please sign in to comment.