libelec
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Functions
libelec_vis.h File Reference
#include <stdbool.h>
#include <acfutils/mt_cairo_render.h>
#include "libelec.h"
Include dependency graph for libelec_vis.h:

Go to the source code of this file.

Functions

libelec_vis_t * libelec_vis_new (const elec_sys_t *sys, double pos_scale, double font_sz)
 
void libelec_vis_destroy (libelec_vis_t *vis)
 
bool libelec_vis_is_open (libelec_vis_t *vis)
 
void libelec_vis_open (libelec_vis_t *vis)
 
void libelec_vis_close (libelec_vis_t *vis)
 
void libelec_vis_set_offset (libelec_vis_t *vis, vect2_t offset)
 
vect2_t libelec_vis_get_offset (const libelec_vis_t *vis)
 

Detailed Description

This file contains a simple visualizer for libelec networks. This is using X-Plane's XPLM SDK for window handling, compositing and mouse interaction.

To create a new visualizer, use libelec_vis_new(), passing it a handle to an initialized and started elec_sys_t. On shutdown, you must call libelec_vis_destroy() before stopping and destroying the referenced electrical system. You can open the window using libelec_vis_open() if it was closed by the user (use libelec_vis_is_open() to check).

Note
If you plan on running libelec in a simulator other than X-Plane, or outside of a simulator entirely, you can still use the same visualizations by using the functions from libelec_drawing.h and implementing your own window handling and interaction layers.
See also
libelec_vis_new()
libelec_vis_destroy()
libelec_vis_open()
libelec_vis_is_open()

Definition in file libelec_vis.h.

Function Documentation

◆ libelec_vis_close()

void libelec_vis_close ( libelec_vis_t *  vis)

Closes the libelec_vis_t window, if open, otherwise does nothing. Closing the window stops the renderer thread and deinitializes the renderer's framebuffer, so removes essentially all CPU, RAM and VRAM footprint that the visualizer had while open. As such, you don't need to immediately perform a libelec_vis_destroy() as soon as the window is closed. You can delay that until simulator shutdown. This will help preserve the window's position and size, if the user moved and/or resized it.

Definition at line 492 of file libelec_vis.c.

◆ libelec_vis_destroy()

void libelec_vis_destroy ( libelec_vis_t *  vis)

Destroys a previously created libelec_vis_t. You must call this before destroying the underlying elec_sys_t handle.

Definition at line 412 of file libelec_vis.c.

◆ libelec_vis_get_offset()

vect2_t libelec_vis_get_offset ( const libelec_vis_t *  vis)
Returns
The current panning offset of the view.

Definition at line 444 of file libelec_vis.c.

◆ libelec_vis_is_open()

bool libelec_vis_is_open ( libelec_vis_t *  vis)
Returns
True if the visualizer window is open, false if it isn't.

Definition at line 454 of file libelec_vis.c.

◆ libelec_vis_new()

libelec_vis_t* libelec_vis_new ( const elec_sys_t *  sys,
double  pos_scale,
double  font_sz 
)

Creates a window showing a visualization of an electrical network. This is using the drawing routines within libelec_drawing.h to draw an image of the network, as well as implement mouse interaction for panning & zooming around in the network.

Parameters
sysThe electrical system to display. This must have been previously initialized using libelec_new(). The visualizer keeps a reference to the system, so you must NOT destroy the elec_sys_t before the visualizer.
pos_scaleA scaling multiplier applied to all GUI_POS stanzas in the network layout configuration file. This lets you use abstract size units in the config file and then scale them up as you see fit.
font_szDefault font size to be used for all drawing. This sets the default header and title sizes, and is also used as a baseline for smaller font scales for things such as subscripts.
Returns
An initialized visualizer, ready for display. The window of the visualizer is not yet visible. You should call libelec_vis_open() to make it visible.

Definition at line 365 of file libelec_vis.c.

◆ libelec_vis_open()

void libelec_vis_open ( libelec_vis_t *  vis)

Opens the libelec_vis_t window. The window will automatically switch to VR positioning mode, if the user is in VR (or return back to 2D mode, if they have exited VR).

Definition at line 467 of file libelec_vis.c.

◆ libelec_vis_set_offset()

void libelec_vis_set_offset ( libelec_vis_t *  vis,
vect2_t  offset 
)

Sets the panning offset of the contents of the rendering. Initially this is (0,0), but if your network layout is better centered on another position, you can use this function to pre-pan the view to that offset after creating the visualizer.

Parameters
offsetThe visual offset to set in pixels.

Definition at line 434 of file libelec_vis.c.