SDL
The 'sdl' module provides SDL2 + ImGUI functionality
SDL2 Function Signatures
// Used to handle the correct event type in pollEvent
const EventType = {
QUIT: 256,
WINDOW: 512,
KEYDOWN: 768,
KEYUP: 769,
MOUSEMOTION: 1024,
MOUSEBUTTONDOWN: 1025,
MOUSEBUTTONUP: 1026,
MOUSEWHEEL: 1027
}
// Initializes the SDL library.
const initSDL = () => Number
// Creates a window with the specified parameters.
const createWindow = (windowName: String, xPos: Number, yPos: Number, width: Number, height: Number, flags = 4) => Pointer
// Creates a renderer for the given window.
const createRenderer = (window: Pointer, index = -1) => Pointer
// Clears the renderer's rendering target.
const renderClear = (renderer: Pointer) => None
// Presents the renderer's rendering target to the screen.
const renderPresent = (renderer: Pointer) => None
// Retrieves the name of the key corresponding to the given key code.
const getKeyName = (keyCode: Number) => String
// Sets the color used for drawing operations.
const setRenderDrawColor = (renderer: Pointer, r = 0, g = 0, b = 0, a = 255) => None
// Delays execution for the specified number of milliseconds.
const delay = (ms: Number) => None
// Retrieves the current state of the mouse.
const getMouseState = () => {
state: Number,
x: Number,
y: Number
}
// Draws a point on the renderer.
const drawPoint = (renderer: Pointer, xPos: Number, yPos: Number) => None
// Draws a line on the renderer.
const drawLine = (renderer: Pointer, x1: Number, y1: Number, x2: Number, y2: Number) => None
// Draws a rectangle on the renderer.
const drawRect = (renderer: Pointer, x: Number, y: Number, w: Number, h: Number) => None
// Draws geometry on the renderer.
const drawGeometry = (renderer: Pointer, vertices: Any, texture = None)
=> None
// Loads a texture onto the renderer.
const loadTexture = (renderer: Pointer, filePath: String) => Pointer
// Loads text onto the renderer with the specified font and parameters.
const loadText = (renderer: Pointer, fontPath: String, fontSize: Number, r: Number, g: Number, b: Number, text: String) => Pointer
// Retrieves the size of the window.
const getWindowSize = (window: Pointer) => {
w: Number,
h: Number
}
// Retrieves the position of the window.
const getWindowPos = (window: Pointer) => {
x: Number,
y: Number
}
// Shows or hides the cursor.
const showCursor = (flag: Boolean) => None
// Queries a texture for its information.
const queryTexture = (texture: Pointer) => {
x: Number,
y: Number
}
// Destroys a texture.
const destroyTexture = (texture: Pointer) => None
// Loads a WAV file.
const loadWav = (wav_file: String) => Pointer
// Plays a WAV file.
const playWav = (wav_ptr: Pointer, channel = -1, loops = 0) => Number
// Loads a music file.
const loadMusic = (music_file: String) => Pointer
// Plays a music file.
const playMusic = (music_ptr: Pointer, loops = 0) => Number
// Pauses music playback.
const pauseMusic = () => None
// Resumes music playback.
const resumeMusic = () => None
// Stops music playback.
const haltMusic = () => Number
// Retrieves the current status of music playback.
const musicStatus = () => {
playing: Boolean,
paused: Boolean
}
// Sets the volume of a channel or music.
const volume = (_volume = -1, channel = -1) => Number
// Sets the volume of music.
const musicVolume = (_volume = -1) => Number
// Polls for the next available event.
const pollEvent = () => {
status: Number,
event: {
type: Number,
button: {
button: Number,
clicks: Number,
x: Number,
y: Number,
which: Number
},
motion: {
x: Number,
y: Number,
which: Number,
windowID: Number
},
key: {
type: Number,
state: Number,
repeat: Number,
keysm: {
mod: Number,
scancode: Number,
sym: Number
}
},
window: {
event: Number,
data1: Number,
data2: Number,
windowID: Number
}
},
event_ptr: Pointer | None
}
/*
Information about the pollEvent() function:
- type {Number} - The type of the event.
- button {Object} - Information about a button event.
- button {Number} - The button number.
- clicks {Number} - The number of clicks.
- x {Number} - The x coordinate of the event.
- y {Number} - The y coordinate of the event.
- which {Number} - The mouse device index.
- motion {Object} - Information about a motion event.
- x {Number} - The x coordinate of the motion.
- y {Number} - The y coordinate of the motion.
- which {Number} - The mouse device index.
- windowID {Number} - The ID of the window where the motion occurred.
- key {Object} - Information about a keyboard event.
- type {Number} - The type of the keyboard event.
- state {Number} - The state of the key.
- repeat {Number} - The number of repeats for the key.
- keysm {Object} - Information about key modifiers.
- mod {Number} - The key modifier.
- scancode {Number} - The scancode of the key.
- sym {Number} - The symbolic code of the key.
- window {Object} - Information about a window event.
- event {Number} - The window event type.
- data1 {Number} - Additional data specific to the event.
- data2 {Number} - Additional data specific to the event.
- windowID {Number} - The ID of the window associated with the event.
- event_ptr {Pointer | None} - A pointer to the event data, or None if no event is available.
*/
ImGUI Function Signatures
// Object containing functions related to ImGui (Dear ImGui)
const imgui = {
// Checks the version of ImGui library
check_version: () => lib.imgui_check_version(),
// Creates an ImGui context
create_context: () => lib.imgui_create_context(),
// Initializes IO (Input/Output) for ImGui
init_io: () => lib.imgui_init_io(),
// Initializes ImGui for SDL (Simple DirectMedia Layer)
init_for_sdl: (window, renderer) => lib.imgui_init_for_sdl(window, renderer),
// Initializes SDL renderer for ImGui
sdl_render_init: (renderer) => lib.imgui_sdl_render_init(renderer),
// Retrieves IO (Input/Output) for ImGui
get_io: () => lib.imgui_get_io(),
// Processes an event for ImGui
process_event: (event) => lib.imgui_process_event(event),
// Starts a new frame for ImGui
new_frame: () => lib.imgui_new_frame(),
// Renders ImGui
render: () => lib.imgui_render(),
// Retrieves draw data for ImGui
get_draw_data: () => lib.imgui_get_draw_data(),
// Renders draw data for ImGui
render_draw_data: (data) => lib.imgui_render_draw_data(data),
// Shows a demo window in ImGui
show_demo_window: () => lib.imgui_show_demo_window(),
// Begins a new UI window with specified name and flags
begin: (name, flags = 0) => lib.imgui_begin(name, flags),
// Ends the current UI window
end: () => lib.imgui_end(),
// Displays text in ImGui
text: (content, wrapped = true) => lib.imgui_text(content, wrapped),
// Displays a button in ImGui
button: (text, x = 5, y = 5) => lib.imgui_button(text, x, y),
// Displays a checkbox in ImGui
checkbox: (text, checked) => lib.imgui_checkbox(text, checked),
// Displays a float slider in ImGui
slider_float: (text, number, min, max) => lib.imgui_slider_float(text, number, min, max),
// Begins the main menu bar in ImGui
begin_main_menu_bar: () => lib.imgui_begin_main_menu_bar(),
// Ends the main menu bar in ImGui
end_main_menu_bar: () => lib.imgui_end_main_menu_bar(),
// Begins a new menu in ImGui with specified name
begin_menu: (name) => lib.imgui_begin_menu(name),
// Ends the current menu in ImGui
end_menu: () => lib.imgui_end_menu(),
// Adds a menu item in ImGui
menu_item: (name) => lib.imgui_menu_item(name),
// Begins a new child window in ImGui
begin_child: (name, width, height, border = false, flags = 0) => lib.imgui_begin_child(name, width, height, border, flags),
// Ends the current child window in ImGui
end_child: () => lib.imgui_end_child(),
// Displays a combo box in ImGui
combo: (text, choice, choices) => lib.imgui_combo(text, choice, choices),
// Displays a text input box in ImGui
input_text: (label, text, hint = "") => {
var _label = label
if (label == "") {
_label = "##"
}
return lib.imgui_input_text(_label, text, hint)
},
// Displays a password input box in ImGui
input_password: (label, text, hint = "") => {
var _label = label
if (label == "") {
_label = "##"
}
return lib.imgui_input_password(_label, text, hint)
},
// Moves the cursor to the same line in ImGui
same_line: (offset_from_start_x = 0, spacing = -1) => lib.imgui_same_line(offset_from_start_x, spacing),
// Sets the cursor position along the X-axis in ImGui
set_cursor_pos_x: (local_x) => lib.imgui_set_cursor_pos_x(local_x),
// Sets the cursor position along the Y-axis in ImGui
set_cursor_pos_y: (local_y) => lib.imgui_set_cursor_pos_y(local_y),
// Sets the size of the current window in ImGui
set_window_size: (width, height) => lib.imgui_set_window_size(width, height),
// Sets the position of the current window in ImGui
set_window_pos: (xPos = 0, yPos = 0) => lib.imgui_set_window_pos(xPos, yPos),
// Retrieves the cursor position in ImGui
get_cursor_pos: () => lib.imgui_get_cursor_pos(),
// Displays an image in ImGui
image: (texture, width = -1, height = -1) => lib.imgui_image(texture, width, height),
// Pushes a style color onto the ImGui stack
push_style_color: (imgui_color = 0, r = 0, g = 0, b = 0, a = 255) => lib.imgui_push_style_color(imgui_color, r, g, b, a),
// Pops a style color from the ImGui stack
pop_style_color: (count = 1) => lib.imgui_pop_style_color(count),
// Imports a font into ImGui
import_font: (font_file, font_size = 12) => lib.imgui_import_font(font_file, font_size),
// Pushes a font onto the ImGui stack
push_font: (font_ptr) => lib.imgui_push_font(font_ptr),
// Pops a font from the ImGui stack
pop_font: () => lib.imgui_pop_font(),
// Retrieves the current font in ImGui
get_font: () => lib.imgui_get_font(),
// Sets the scroll position on the X-axis
set_scroll_here_x: (center_x_ratio = 0.5) => lib.imgui_set_scroll_here_x(center_x_ratio),
// Sets the scroll position on the Y-axis
set_scroll_here_y: (center_y_ratio = 0.5) => lib.imgui_set_scroll_here_y(center_y_ratio),
IMGUI_COLOR: {
Text: 0,
TextDisabled: 1,
WindowBg: 2, // Background of normal windows
ChildBg: 3, // Background of child windows
PopupBg: 4, // Background of popups, menus, tooltips windows
Border: 5,
BorderShadow: 6,
FrameBg: 7, // Background of checkbox, radio button, plot, slider, text input
FrameBgHovered: 8,
FrameBgActive: 9,
TitleBg: 10,
TitleBgActive: 11,
TitleBgCollapsed: 12,
MenuBarBg: 13,
ScrollbarBg: 14,
ScrollbarGrab: 15,
ScrollbarGrabHovered: 16,
ScrollbarGrabActive: 17,
CheckMark: 18,
SliderGrab: 19,
SliderGrabActive: 20,
Button: 21,
ButtonHovered: 22,
ButtonActive: 23,
Header: 24, // Header* colors are used for CollapsingHeader, TreeNode, Selectable, MenuItem
HeaderHovered: 25,
HeaderActive: 26,
Separator: 27,
SeparatorHovered: 28,
SeparatorActive: 29,
ResizeGrip: 30, // Resize grip in lower-right and lower-left corners of windows.
ResizeGripHovered: 31,
ResizeGripActive: 32,
Tab: 33, // TabItem in a TabBar
TabHovered: 34,
TabActive: 35,
TabUnfocused: 36,
TabUnfocusedActive: 37,
DockingPreview: 38, // Preview overlay color when about to docking something
DockingEmptyBg: 39, // Background color for empty node (e.g. CentralNode with no window docked into it)
PlotLines: 40,
PlotLinesHovered: 41,
PlotHistogram: 42,
PlotHistogramHovered: 43,
TableHeaderBg: 44, // Table header background
TableBorderStrong: 45, // Table outer and header borders (prefer using Alpha=1.0 here)
TableBorderLight: 46, // Table inner borders (prefer using Alpha=1.0 here)
TableRowBg: 47, // Table row background (even rows)
TableRowBgAlt: 48, // Table row background (odd rows)
TextSelectedBg: 49,
DragDropTarget: 50, // Rectangle highlighting a drop target
NavHighlight: 51, // Gamepad/keyboard: current highlighted item
NavWindowingHighlight: 52, // Highlight window when using CTRL+TAB
NavWindowingDimBg: 53, // Darken/colorize entire screen behind the CTRL+TAB window list, when active
ModalWindowDimBg: 54, // Darken/colorize entire screen behind a modal window, when one is active
},
WINDOW_FLAGS: {
"None": 0,
NoTitleBar: 1, // Disable title-bar
NoResize: 2, // Disable user resizing with the lower-right grip
NoMove: 4, // Disable user moving the window
NoScrollbar: 8, // Disable scrollbars (window can still scroll with mouse or programmatically)
NoScrollWithMouse: 16, // Disable user vertically scrolling with mouse wheel. On child window, mouse wheel will be forwarded to the parent unless NoScrollbar is also set.
NoCollapse: 32, // Disable user collapsing window by double-clicking on it. Also referred to as Window Menu Button (e.g. within a docking node).
AlwaysAutoResize: 64, // Resize every window to its content every frame
NoBackground: 128, // Disable drawing background color (WindowBg, etc.) and outside border. Similar as using SetNextWindowBgAlpha(0.0f).
NoSavedSettings: 256, // Never load/save settings in .ini file
NoMouseInputs: 512, // Disable catching mouse, hovering test with pass through.
MenuBar: 1024, // Has a menu-bar
HorizontalScrollbar: 2048, // Allow horizontal scrollbar to appear (off by default). You may use SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo in the "Horizontal Scrolling" section.
NoFocusOnAppearing: 4096, // Disable taking focus when transitioning from hidden to visible state
NoBringToFrontOnFocus: 8192, // Disable bringing window to front when taking focus (e.g. clicking on it or programmatically giving it focus)
AlwaysVerticalScrollbar: 16384, // Always show vertical scrollbar (even if ContentSize.y < Size.y)
AlwaysHorizontalScrollbar: 32768, // Always show horizontal scrollbar (even if ContentSize.x < Size.x)
AlwaysUseWindowPadding: 65536, // Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient)
NoNavInputs: 262144, // No gamepad/keyboard navigation within the window
NoNavFocus: 524288, // No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB)
UnsavedDocument: 1048576, // Display a dot next to the title. When used in a tab/docking context, tab is selected when clicking the X + closure is not assumed (will wait for user to stop submitting the tab). Otherwise closure is assumed when pressing the X, so if you keep submitting the tab may reappear at end of tab bar.
NoDocking: 2097152, // Disable docking of this window
NoNav: 786432,
NoDecoration: 43,
NoInputs: 786944
}
}
Last updated