Utils module

Contents

Files

file resources.h
Helpers for loading and using resources such as icons.

Enums

enum ZGtkFill { Z_GTK_NO_FILL, Z_GTK_FILL }
For readability, instead of using 0s and 1s.

Functions

void audio_decode(struct adinfo* nfo, SRC_DATA* src_data, float** out_buff, long* out_buff_size, const char* filename)
Decodes the given filename (absolute path).
void audio_write_raw_file(float* buff, long size, int samplerate, int channels, const char* filename)
Writes the buffer as a raw file to the given path.
auto audio_get_num_cores() -> int
Returns the number of CPU cores.
static void z_cairo_rounded_rectangle(cairo_t* cr, double x, double y, double width, double height, double aspect, double corner_radius)
void z_cairo_get_text_extents_for_widget(GtkWidget* widget, const char* text, int* width, int* height)
Gets the width of the given text in pixels for the given widget when z_cairo_draw_text() is used.
void z_cairo_get_text_extents_for_widget_full(GtkWidget* widget, const char* text, int* width, int* height, const char* font)
Gets the width of the given text in pixels for the given widget when using the given font settings.
void z_cairo_draw_text_full(cairo_t* cr, const char* text, int start_x, int start_y, const char* font)
Draws the given text using the given font starting at the given position.
static void z_cairo_diamond(cairo_t* cr, double x, double y, double width, double height)
Draws a diamond shape.
auto z_cairo_get_surface_from_icon_name(const char* icon_name, int size, int scale) -> cairo_surface_t*
Returns a surface for the icon name.
void z_gtk_container_remove_all_children(GtkContainer* container)
NOTE: bumps reference, must be decremented after calling.
void z_gtk_configure_simple_combo_box(GtkComboBox* cb, GtkTreeModel* model)
Configures a simple value-text combo box using the given model.
auto z_gtk_button_new_with_icon(const char* name) -> GtkButton*
Creates a button with the given icon name.
auto z_gtk_toggle_button_new_with_icon(const char* name) -> GtkToggleButton*
Creates a toggle button with the given icon name.
auto z_gtk_button_new_with_resource(IconType icon_type, const char* name) -> GtkButton*
Creates a button with the given resource name as icon.
auto z_gtk_toggle_button_new_with_resource(IconType icon_type, const char* name) -> GtkToggleButton*
Creates a toggle button with the given resource name as icon.
auto z_gtk_create_menu_item(gchar* label_name, gchar* icon_name, IconType resource_icon_type, gchar* resource, int is_toggle, const char* action_name) -> GtkMenuItem*
TODO add description.
auto z_gtk_get_single_selection_pointer(GtkTreeView* tv, int column) -> void*
Returns a pointer stored at the given selection.
auto z_gtk_get_label_from_menu_item(GtkMenuItem* mi) -> GtkLabel*
Returns the label from a given GtkMenuItem.
void z_gtk_set_tooltip_for_actionable(GtkActionable* actionable, const char* tooltip)
Sets the tooltip and finds the accel keys and appends them to the tooltip in small text.
void z_gtk_widget_add_style_class(GtkWidget* widget, const gchar* class_name)
Adds the given style class to the GtkWidget.
static auto z_gtk_widget_get_device(GtkWidget* widget) -> GdkDevice*
Gets the GdkDevice for a GtkWidget.
static void z_gtk_widget_get_mask(GtkWidget* widget, GdkModifierType* mask)
Sets the GdkModifierType given for the widget.
static auto z_gtk_container_get_single_child(GtkContainer* container) -> GtkWidget*
Returns the single child of a container.
void z_gtk_setup_foldable_notebook(GtkNotebook* notebook)
Makes the given notebook foldable.
auto io_get_dir(const char* filename) -> char*
Gets directory part of filename.
void io_mkdir(const char* dir)
Makes directory if doesn't exist.
auto io_get_home_dir() -> char*
Gets home dir.
auto io_touch_file(const char* filename) -> FILE*
Creates the file if doesn't exist.
auto io_file_strip_ext(const char* filename) -> char*
Strips extensions from given filename.
auto io_file_get_ext(const char* file) -> char*
Returns file extension or NULL.
auto io_path_get_basename(const char* filename) -> char*
Strips path from given filename.
auto io_remove(const char* path) -> int
Removes the given file.
auto io_rmdir(const char* path, int force) -> int
Removes a dir, optionally forcing deletion.
void localization_get_string_code(UiLanguage lang, char* str)
Returns the 2-character string code for the language (e.g.
auto localization_init() -> int
Sets the locale to the currently selected one and inits gettext.
void _free_later(void* object, void(*)(void*) dfunc)
Frees the object after a while.
void object_utils_init()
Inits the subsystems for the object utils in this file.
auto resources_get_icon(IconType icon_type, const char* filename) -> GtkWidget*
Creates a GtkImage of from the given information and returns it as a GtkWidget.
void resources_set_class_template(GtkWidgetClass* klass, const char* filename)
Sets class template from resource.
auto string_is_ascii(const char* string) -> int
Returns if the string is ASCII.
auto string_array_contains_substr(char** str_array, int num_str, char* substr) -> char*
Returns the matched string if the string array contains the given substring.
auto string_is_equal(const char* str1, const char* str2, int ignore_case) -> int
Returns if the two strings are equal.

Defines

#define STRIP_SIZE
Number of plugin slots per channel.
#define Z_CAIRO_FONT
Default font for drawing pango text.
#define Z_CAIRO_TEXT_PADDING
Padding to leave from the top/left edges when drawing text.
#define io_file_exists(file)
Returns 1 if the file/dir exists.
#define free_later(obj, func)
Calls _free_later after doing the casting so the caller doesn't have to.
#define SERIALIZE_INC(camelcase, lowercase)
Serializes to XML.

Function documentation

void audio_decode(struct adinfo* nfo, SRC_DATA* src_data, float** out_buff, long* out_buff_size, const char* filename)

Decodes the given filename (absolute path).

Parameters
nfo Pointer to an adinfo struct.
src_data Pointer to a SRC_DATA struct.
out_buff Pointer to a buffer array to put the raw audio data in.
out_buff_size
filename The file to read the audio data from.

static void z_cairo_rounded_rectangle(cairo_t* cr, double x, double y, double width, double height, double aspect, double corner_radius)

Parameters
cr
x
y
width
height
aspect Aspect ratio.
corner_radius Corner curvature radius.

void z_cairo_get_text_extents_for_widget(GtkWidget* widget, const char* text, int* width, int* height)

Gets the width of the given text in pixels for the given widget when z_cairo_draw_text() is used.

Parameters
widget The widget to derive a PangoLayout from.
text The text to draw.
width The width to fill in.
height The height to fill in.

void z_cairo_get_text_extents_for_widget_full(GtkWidget* widget, const char* text, int* width, int* height, const char* font)

Gets the width of the given text in pixels for the given widget when using the given font settings.

Parameters
widget The widget to derive a PangoLayout from.
text The text to draw.
width The width to fill in.
height The height to fill in.
font

GtkLabel* z_gtk_get_label_from_menu_item(GtkMenuItem* mi)

Returns the label from a given GtkMenuItem.

The menu item must have a box with an optional icon and a label inside.

static void z_gtk_widget_get_mask(GtkWidget* widget, GdkModifierType* mask)

Sets the GdkModifierType given for the widget.

Used in eg. drag_motion events to check if Ctrl is held.

void z_gtk_setup_foldable_notebook(GtkNotebook* notebook)

Makes the given notebook foldable.

The pages of the notebook must all be wrapped in GtkBox's.

char* io_get_dir(const char* filename)

Gets directory part of filename.

MUST be freed.filename containing directory

MUST be freed.

char* io_get_home_dir()

Gets home dir.

MUST be freed.

char* io_file_strip_ext(const char* filename)

Strips extensions from given filename.

MUST be freed.

char* io_path_get_basename(const char* filename)

Strips path from given filename.

MUST be freed.

void localization_get_string_code(UiLanguage lang, char* str)

Returns the 2-character string code for the language (e.g.

Parameters
lang
str is a preallocated buffer.

"fr").

int localization_init()

Sets the locale to the currently selected one and inits gettext.

Returns if a locale for the selected language exists on the system or not.

void _free_later(void* object, void(*)(void*) dfunc)

Frees the object after a while.

This is useful when the object will be in use for a while, for example in the current processing cycle.

GtkWidget* resources_get_icon(IconType icon_type, const char* filename)

Creates a GtkImage of from the given information and returns it as a GtkWidget.

Returns a GtkImage.

void resources_set_class_template(GtkWidgetClass* klass, const char* filename)

Sets class template from resource.

Filename is part after .../ui/

Define documentation

#define SERIALIZE_INC(camelcase, lowercase)

Serializes to XML.

MUST be free'd.