Slider widget
[Widget toolkit]

Collaboration diagram for Slider widget:

Modules

 Slider widget options

Functions

struct wtk_sliderwtk_slider_create (struct win_window *parent, struct win_area const *area, uint8_t maximum, uint8_t value, uint8_t option, win_command_t command_data)
 Create a new slider widget.
struct win_windowwtk_slider_as_child (struct wtk_slider *slider)
 Get pointer to slider window.
bool wtk_slider_is_moving (struct wtk_slider const *slider)
 Get slider status.
uint8_t wtk_slider_get_value (struct wtk_slider const *slider)
 Get slider value.
bool wtk_slider_set_value (struct wtk_slider *slider, uint8_t value)
 Set new slider value.



enum  wtk_slider_state { WTK_SLIDER_NORMAL, WTK_SLIDER_MOVING }
 

Valid states for slider, relevant to pointer operations.

More...
static bool wtk_slider_handler (struct win_window *win, enum win_event_type type, void const *data)
 Slider event handler.



#define WTK_SLIDER_PARENT_MOVE_SUPPORT   0
 Move support for sliders.
#define WTK_SLIDER_KNOB_WIDTH   10
 Width of the slider knob, including borders, in pixels.
#define WTK_SLIDER_BORDER_COLOR   GFX_COLOR(0, 0, 0)
 Color of all the slider's borders.
#define WTK_SLIDER_BACKGROUND_COLOR   GFX_COLOR(128, 128, 128)
 Color of the slider's background.
#define WTK_SLIDER_KNOB_COLOR_NORMAL   GFX_COLOR(128, 0, 0)
 Color of the slider knob when normal.
#define WTK_SLIDER_KNOB_COLOR_MOVING   GFX_COLOR(255, 255, 255)
 Color of the slider knob when moving.

Define Documentation

#define WTK_SLIDER_BACKGROUND_COLOR   GFX_COLOR(128, 128, 128)

Color of the slider's background.

Definition at line 329 of file wtk.h.

Referenced by wtk_slider_handler().

#define WTK_SLIDER_BORDER_COLOR   GFX_COLOR(0, 0, 0)

Color of all the slider's borders.

Definition at line 324 of file wtk.h.

Referenced by wtk_slider_handler().

#define WTK_SLIDER_KNOB_COLOR_MOVING   GFX_COLOR(255, 255, 255)

Color of the slider knob when moving.

Definition at line 339 of file wtk.h.

Referenced by wtk_slider_handler().

#define WTK_SLIDER_KNOB_COLOR_NORMAL   GFX_COLOR(128, 0, 0)

Color of the slider knob when normal.

Definition at line 334 of file wtk.h.

Referenced by wtk_slider_handler().

#define WTK_SLIDER_KNOB_WIDTH   10

Width of the slider knob, including borders, in pixels.

Definition at line 319 of file wtk.h.

Referenced by wtk_slider_create(), wtk_slider_handler(), and wtk_slider_set_value().

#define WTK_SLIDER_PARENT_MOVE_SUPPORT   0

Move support for sliders.

This define enables and disables move support for sliders. Move support is needed if the application is using moving parent widgets/windows. If not needed, disable it to save CPU cycles.

Set to 1 to enable move support or 0 to disable move support.

Definition at line 314 of file wtk.h.


Enumeration Type Documentation

Valid states for slider, relevant to pointer operations.

For internal use only.

Enumerator:
WTK_SLIDER_NORMAL 

Normal state, no highlight or movement.

WTK_SLIDER_MOVING 

Slider is pressed, highlighted and moving.

Definition at line 54 of file wtk_slider.c.


Function Documentation

struct win_window* wtk_slider_as_child ( struct wtk_slider slider  )  [read]

Get pointer to slider window.

Returns a reference to the window that should be used when managing the widget, such as destroying, moving or reparenting it.

Parameters:
slider Pointer to wtk_slider struct to manage.
Returns:
Pointer to window to be used for managing the slider.

Definition at line 101 of file wtk_slider.c.

References assert, and wtk_slider::container.

Referenced by app_tank_launch().

struct wtk_slider* wtk_slider_create ( struct win_window parent,
struct win_area const *  area,
uint8_t  maximum,
uint8_t  value,
uint8_t  option,
win_command_t  command 
) [read]

Create a new slider widget.

Allocates the necessary memory and intializes the window and data for slider widgets. If there is not enough memory, the function returns NULL.
To destroy a slider widget and all its contents, and free its memory, call win_destroy() on the slider's child reference, given by wtk_slider_as_child(), like this: "win_destroy(wtk_slider_as_child(my_slider_ptr));".

Slider widgets fill the specified area and perform a mapping of the slider knob's position to a value between 0 and maximum. The length of the slider cannot exceed 255 pixels.

By default, the value 0 corresponds to the top-most position for a vertical slider, and the left-most position for a horizontal one. The slider's orientation and inversion of the value can be configured.

A slider can be configured to issue command events whenever its value is changed by a pointer and/or when a pointer releases it.

Refer to <gfx/wtk.h> for available configuration options.

Todo:
Revisit, support larger sliders and values given a config symbol.
Parameters:
parent Pointer to parent win_window struct.
area Pointer to win_area struct with position and size of the slider.
maximum Maximum value of the slider.
value Initial value of the slider.
option Configuration options for slider. See Slider widget options
command Command to send to parent window. Must be non-zero if used.
Returns:
Pointer to new slider, if memory allocation was successful.

Definition at line 466 of file wtk_slider.c.

References win_attributes::area, assert, win_attributes::background, win_attributes::behavior, wtk_slider::command, wtk_slider::container, win_attributes::custom, win_attributes::event_handler, wtk_slider::maximum, membag_alloc(), membag_free(), wtk_slider::option, wtk_slider::position, wtk_slider::root_pos, win_area::size, wtk_slider::state, wtk_slider::value, win_create(), win_translate_win_to_root(), wtk_rescale_value(), WTK_SLIDER_CMD_MOVE, WTK_SLIDER_CMD_RELEASE, wtk_slider_handler(), WTK_SLIDER_INVERT, WTK_SLIDER_KNOB_WIDTH, WTK_SLIDER_NORMAL, and WTK_SLIDER_VERTICAL.

Referenced by app_tank_launch().

uint8_t wtk_slider_get_value ( struct wtk_slider const *  slider  ) 

Get slider value.

Returns the slider value, inverted if such behavior is configured.

Parameters:
slider Pointer to wtk_slider struct to get value from.
Returns:
Value of slider.

Definition at line 132 of file wtk_slider.c.

References assert, wtk_slider::maximum, wtk_slider::option, wtk_slider::value, and WTK_SLIDER_INVERT.

Referenced by tank_worker(), and widget_frame_command_handler().

static bool wtk_slider_handler ( struct win_window win,
enum win_event_type  type,
void const *  data 
) [static]

Slider event handler.

This is the window event handler for slider widgets. It handles the three relevant event types sent to a slider's container window, i.e., drawing, pointer and destroy events.

For POINTER events, the slider value is only updated when the pointer moves, and not upon press or release events. The handler will grab the pointer and allow for it to move outside the actual widget window and still control the slider knob.

Parameters:
win Window receiving the event.
type The event type.
data Custom data, depending on event type.
Returns:
True if the event was recognized and accepted.

Definition at line 213 of file wtk_slider.c.

References assert, wtk_slider::command, wtk_slider::container, win_command_event::data, gfx_draw_filled_rect, gfx_draw_rect, wtk_slider::maximum, membag_free(), wtk_slider::option, win_clip_region::origin, wtk_slider::position, win_command_event::recipient, wtk_slider::root_pos, win_command_event::sender, win_area::size, wtk_slider::state, win_pointer_event::type, wtk_slider::value, WIN_EVENT_DESTROY, WIN_EVENT_DRAW, WIN_EVENT_POINTER, win_get_area(), win_get_custom_data(), win_grab_pointer(), WIN_POINTER_MOVE, WIN_POINTER_PRESS, WIN_POINTER_RELEASE, win_queue_command_event(), win_redraw(), win_translate_win_to_root(), wtk_rescale_value(), WTK_SLIDER_BACKGROUND_COLOR, WTK_SLIDER_BORDER_COLOR, WTK_SLIDER_CMD_MOVE, WTK_SLIDER_CMD_RELEASE, WTK_SLIDER_KNOB_COLOR_MOVING, WTK_SLIDER_KNOB_COLOR_NORMAL, WTK_SLIDER_KNOB_WIDTH, WTK_SLIDER_MOVING, WTK_SLIDER_NORMAL, and WTK_SLIDER_VERTICAL.

Referenced by wtk_slider_create().

bool wtk_slider_is_moving ( struct wtk_slider const *  slider  ) 

Get slider status.

Returns whether or not the slider is currently being manipulated by pointer events, i.e., it is moving.

Parameters:
slider Pointer to wtk_slider struct to get status of.
Returns:
True if slider is currently moving.

Definition at line 117 of file wtk_slider.c.

References assert, wtk_slider::state, and WTK_SLIDER_MOVING.

bool wtk_slider_set_value ( struct wtk_slider slider,
uint8_t  value 
)

Set new slider value.

Updates the current value and issues a redrawing of the slider if its value was indeed changed. In this case, the new position of the slider knob is also computed.

Parameters:
slider Pointer to wtk_slider struct to set new value for.
value New value for the slider.
Returns:
True if slider value was changed.

Definition at line 155 of file wtk_slider.c.

References assert, wtk_slider::container, wtk_slider::maximum, wtk_slider::option, wtk_slider::position, win_area::size, wtk_slider::value, win_get_area(), win_redraw(), wtk_rescale_value(), WTK_SLIDER_INVERT, WTK_SLIDER_KNOB_WIDTH, and WTK_SLIDER_VERTICAL.

Generated on Thu Apr 29 14:09:59 2010 for display-demo by  doxygen 1.6.3