5
Scene
josh edited this page 2025-02-03 20:13:50 -05:00

The Scene Widget is the root of your GUI. It will pass input along to it's child objects, as well as manage drawing and updating for its children.

Usage:

// This is a contrived example to show you how to create and run a JUI scene.
// You must integrate this with your gameloop / framework of choice.

// Create the scene object itself
auto* scene = new JUI::Scene();

// Create objects and bind them to the scene.
auto* subcomponent = new JUI::Rect(scene);

// This is identical to setting the parent manually.
auto* another = new JUI::Button();
another->Parent(scene);

// Hook the following callbacks to their appropriate place in your engine.

// Rendering.
void game_draw()
{
    scene->Draw();
}

// Logic Update Tick. 
void game_update(float elapsed) {
    scene->SetViewportSize({1920, 1080});
    scene->Update(elapsed);
}

void mouse_moved(float x, float y) {
    scene->ObserveMouseMovement({x, y});
}

void mouse_btn_up(int button_index) {
    // Further conversion to our mousebutton representation may be needed.
    scene->ObserveMouseInput(button_index, false);
}

void mouse_btn_down(int button_index) {
    // Further conversion to our mousebutton representation may be needed.
    scene->ObserveMouseInput(button_index, true);
}

void key_down(int charcode) {
    // Further conversion to our key representation may be needed.
    scene->ObserveKeyInput(charcode, true);
}
void key_up(int charcode) {
    // Further conversion to our key representation may be needed
    scene->ObserveKeyInput(charcode, false);
}