DirectGUI

Since DirectGUI is implemented in Python, it is useless to C++ programmers. However, there is another GUI system, PGui, that forms the foundation of DirectGUI and is in fact implemented in C++.

Let’s take a look at some PGui functions.

The PGui C++ modules

[PGButton]

#include "pgButton.h"

with PGButton you can create a freely definable clickable button.

It can hold four different states:

ready

The default state of an untouched button

pressed

The pressed state (the user clicked on it)

roll over

When the user hovers over the button without clicking

inactive

Disabled state

Example usage, creating a texture for each state:

PT(PGButton) my_button;
my_button = new PGButton("MyButton");
my_button->setup("Button", 0.1);
PT(Texture) button_ready = TexturePool::load_texture("button.png");
PT(Texture) button_rollover = TexturePool::load_texture("button_active.png");
PT(Texture) button_pressed = TexturePool::load_texture("button_pressed.png");
PT(Texture) button_inactive = TexturePool::load_texture("button_inactive.png");

// PGFrameStyle is a powerful way to change the appearance of the button:
PGFrameStyle my_style = my_button->get_frame_style(0); // frame_style(0): ready state
my_style.set_type(PGFrameStyle::T_flat);

my_style.set_texture(button_ready);    my_button->set_frame_style(0, my_style);
my_style.set_texture(button_rollover); my_button->set_frame_style(1, my_style);
my_style.set_texture(button_pressed);  my_button->set_frame_style(2, my_style);
my_style.set_texture(button_inactive); my_button->set_frame_style(3, my_style);

NodePath button_np = window->get_aspect_2d().attach_new_node(my_button);
button_np.set_scale(0.1);

// Setup callback function
framework.define_key(my_button->get_click_event(MouseButton::one()), "", [=](const Event *ev) {
  printf("%s has been pressed.\n", my_button->get_name().c_str());
});

[PGSliderBar]

#include "pgSliderBar.h"

A simple sliderbar.

This slider basically has four components:

  • The thumb button. This is the sliding part.

  • The slider. This is the ‘rail’ the thumb button slides along.

  • The left button. User can click on it to slide the thumb button to the left.

  • The right button. User can click on it to slide the thumb button to the right.

Using default initialisation, none of these components are textured.

PT(PGSliderBar) slider = new PGSliderBar("MySliderBar");

// Setup, feeding the constructor with (bool vertical,float length,float width,float bevel)
slider->setup_slider(false, 0.1, 0.1, 0); // 'rail' properties
slider->set_range(0,1);
slider->set_value(0.5);

// Setup scroll bar (the 'moving thumb button' including left and right button)
slider->setup_scroll_bar(false, 0.35, 0.05, false);
NodePath slider_np = window->get_aspect_2d().attach_new_node(Slider);
slider_np.set_pos(0, 0, 0);

(work in progress, more to come soon.)