Files
cell/prosperon/imgui.cm

734 lines
23 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var imgui = this;
var color = use('color')
var debug = {}
var imdebug = function imdebug() {
imtoggle("Physics", debug, "draw_phys");
imtoggle("Bouning boxes", debug, "draw_bb");
imtoggle("Names", debug, "draw_names");
imtoggle("Sprite nums", debug, "sprite_nums");
imtoggle("Debug overlay", debug, "show");
imtoggle("Show ur names", debug, "urnames");
};
function imtoggle(name, obj, field) {
var changed = false;
var old = obj[field];
obj[field] = imgui.checkbox(name, obj[field]);
if (old != obj[field]) return true;
return false;
};
var render_menu = true;
imgui.render_menu = function(render) { render_menu = render; }
imgui.prosperon_menu = function prosperon_menu() {
imgui.newframe();
if (render_menu) {
if (debug.console)
debug.console = imgui.window("console", _ => {
imgui.text(log.transcript);
replstr = imgui.textinput(null, replstr);
imgui.button("submit", _ => {
eval(replstr);
replstr = "";
});
});
imgui.mainmenubar(_ => {
imgui.menu("File", _ => {
imgui.menu("Game settings", _ => {
prosperon.title = imgui.textinput("Title", prosperon.title);
prosperon.icon = imgui.textinput("Icon", prosperon.icon);
imgui.button("Refresh window", _ => {
prosperon.set_icon(graphics.texture(prosperon.icon));
});
});
imgui.button("quit", os.exit);
});
imgui.menu("Debug", imdebug);
imgui.menu("View", _ => {
imtoggle("Terminal out", debug, "termout");
imtoggle("Meta [f7]", debug, "meta");
imtoggle("Cheats [f8]", debug, "cheat");
imtoggle("Console [f9]", debug, "console");
});
// imgui.sokol_gfx();
imgui.menu("Graphics", _ => {
// imtoggle("Draw sprites", render, "draw_sprites");
// imtoggle("Draw particles", render, "draw_particles");
// imtoggle("Draw HUD", render, "draw_hud");
// imtoggle("Draw GUI", render, "draw_gui");
imgui.menu("Window", _ => {
prosperon.fullscreen = imgui.checkbox("fullscreen", prosperon.fullscreen);
// prosperon.vsync = imgui.checkbox("vsync", prosperon.vsync);
imgui.menu("MSAA", _ => {
for (var msaa of gamestate.msaa) imgui.button(msaa + "x", _ => (prosperon.sample_count = msaa));
});
});
});
});
/*
if (observed_tex) {
imgui.window("texture", _ => {
imgui.image(observed_tex);
});
}
var texs = {};
for (var path in graphics.texture.cache) {
var image = graphics.texture.cache[path];
if (image.texture && !texs[image.texture])
texs[image.texture] = image.texture;
}
imgui.window("textures", _ => {
for (var img in texs) {
imgui.button(img, _ => {
observed_tex = texs[img];
});
}
});
*/
}
prosperon.imgui();
};
imgui.windowpos[cell.DOC] = `Return the position of the current ImGui window as an ImVec2.
:return: A 2-element array [x, y] representing the top-left corner of the current window in screen coordinates.
`;
imgui.plot2pixels[cell.DOC] = `Convert a point from plot coordinates to pixel coordinates in the current ImPlot.
:param coords: A 2-element array [x, y] in plot coordinates.
:return: A 2-element array [x, y] in pixel coordinates, mapped from the current ImPlot.
`;
imgui.plotpos[cell.DOC] = `Return the top-left corner of the current ImPlot region in screen (pixel) coordinates.
:return: A 2-element array [x, y] representing the position of the current ImPlot in screen coordinates.
`;
imgui.plotlimits[cell.DOC] = `Retrieve the current plots axis limits (min/max) for both X and Y axes.
:return: An object { x: { min, max }, y: { min, max } } describing the current plots visible axis ranges.
`;
imgui.setaxes[cell.DOC] = `Switch the active axes in ImPlot (useful if multiple axes exist).
:param xAxis: The x-axis index (0..2).
:param yAxis: The y-axis index (0..2).
:return: None
`;
imgui.setupaxis[cell.DOC] = `Setup the specified axis in the current ImPlot (e.g., for customizing tick labels).
:param axis: The numeric index of the axis (0..2).
:return: None
`;
imgui.inplot[cell.DOC] = `Check if the given point is within the current ImPlot's visible region.
:param coords: A 2-element array [x, y] in plot coordinates.
:return: True if the point is within the visible plot region, otherwise false.
`;
imgui.window[cell.DOC] = `Create a new ImGui window with the given title and invoke the callback to render inside it.
:param title: The text displayed as the window title.
:param callback: A function called to render the contents of the window.
:return: A boolean indicating if the window is still active (open) after rendering.
`;
imgui.menu[cell.DOC] = `Create a new menu entry in a menu bar or menu. The callback is invoked to populate the menu if opened.
:param label: The label of the menu (visible in the menubar).
:param callback: A function called to render menu items when the menu is open.
:return: None
`;
imgui.sameline[cell.DOC] = `Place the next widget on the same line, optionally specifying a horizontal offset.
:param offset: A float offset from the current cursor position. If omitted, defaults to 0.
:return: None
`;
imgui.int[cell.DOC] = `Display an integer input box with a label.
:param label: The label text for the input.
:param value: The initial integer value.
:return: The updated integer value after user edits.
`;
imgui.pushid[cell.DOC] = `Push an integer ID onto the ImGui ID stack.
:param id: An integer used to differentiate widgets/items with the same label.
:return: None
`;
imgui.popid[cell.DOC] = `Pop an ID off the ImGui ID stack.
:return: None
`;
imgui.slider[cell.DOC] = `Create a float slider (or multi-float sliders if given an array) within the specified range.
:param label: The slider label text.
:param value: A single float or an array of floats (e.g., [r,g,b,a]).
:param minValue: The minimum slider value.
:param maxValue: The maximum slider value.
:return: The updated float or array of floats after user adjustment.
`;
imgui.intslider[cell.DOC] = `Create an integer slider (or multiple integer sliders if given a typed array) in the specified range.
:param label: The slider label text.
:param value: A single integer or a typed array of integers (for multi-component sliders).
:param minValue: The minimum integer value.
:param maxValue: The maximum integer value.
:return: The updated integer or array of integers after user adjustment.
`;
imgui.menubar[cell.DOC] = `Begin rendering a menubar. The callback is invoked to create menu items. Ends automatically.
:param callback: A function that creates menu items within the menubar.
:return: None
`;
imgui.mainmenubar[cell.DOC] = `Create the main menu bar at the top of the screen. The callback is invoked for populating it.
:param callback: A function to render items in the main menu bar.
:return: None
`;
imgui.menuitem[cell.DOC] = `Create a menu item that can optionally be toggled. If selected, calls the provided callback.
:param label: The text label of the menu item.
:param shortcut: An optional shortcut text to display (e.g. "Ctrl+S").
:param callback: A function called if the user clicks or activates this item.
:param selected: A boolean indicating whether this menu item is toggled or not.
:return: A boolean reflecting the toggled state.
`;
imgui.radio[cell.DOC] = `Create a radio button.
:param label: The text label for the radio button.
:param active: Whether this radio button is currently selected.
:return: True if this radio button is now selected by the user, otherwise false.
`;
imgui.image[cell.DOC] = `Render a texture as an image at a default size (100x100).
:param texture: The GPU texture to display.
:return: None
`;
imgui.imagebutton[cell.DOC] = `Create an ImageButton widget which displays a texture; calls the callback when clicked.
:param label: A string identifier (not visually used).
:param texture: The GPU texture to display on the button.
:param callback: A function called when the button is clicked.
:return: None
`;
imgui.textinput[cell.DOC] = `Show a single-line text input widget.
:param label: The label text next to the input box.
:param text: The current text. If null, the box starts empty.
:return: The updated text string after user editing.
`;
imgui.textbox[cell.DOC] = `Show a multi-line text input widget.
:param label: The label text next to the input box.
:param text: The current multi-line text. If null, starts empty.
:return: The updated text after user editing.
`;
imgui.button[cell.DOC] = `Create a button. The callback fires if the user clicks it.
:param label: The text displayed on the button.
:param callback: The function called on click.
:return: None
`;
imgui.checkbox[cell.DOC] = `Create a checkbox to toggle a boolean value.
:param label: The text label for the checkbox.
:param checked: The current boolean state.
:return: The updated boolean state after user toggle.
`;
imgui.text[cell.DOC] = `Render a line of text in the ImGui window.
:param text: The string to display.
:return: None
`;
imgui.plot[cell.DOC] = `Begin a new ImPlot region with the specified title. Calls the callback to render plot contents.
:param title: The title (label) of the plot.
:param callback: A function that sets up and draws within the ImPlot region.
:return: None
`;
imgui.lineplot[cell.DOC] = `Plot a line graph in the current ImPlot.
:param label: The label for the line plot.
:param data: An array of [x,y] points or a single array of y-values.
:param shaded: Boolean indicating if the area under the line should be filled.
:param lastPoint: (Optional) Additional point or frame usage. (Currently partial/placeholder in code.)
:return: None
`;
imgui.scatterplot[cell.DOC] = `Plot a scatter graph in the current ImPlot.
:param label: The label for the scatter plot.
:param data: An array of [x,y] points or a single array of y-values.
:param shaded: Typically unused for scatter.
:param lastPoint: (Optional) Additional param if needed.
:return: None
`;
imgui.stairplot[cell.DOC] = `Plot a stair-step graph in the current ImPlot.
:param label: The label for the stair plot.
:param data: An array of [x,y] points or a single array of y-values.
:param shaded: A boolean to fill under the stair-step line.
:param lastPoint: (Optional) Extended data usage if needed.
:return: None
`;
imgui.digitalplot[cell.DOC] = `Plot a digital (step-like) graph in the current ImPlot.
:param label: The label for the digital plot.
:param data: An array of [x,y] points or a single array of y-values.
:param shaded: Typically not used for digital plots.
:param lastPoint: (Optional) Extended data usage if needed.
:return: None
`;
imgui.barplot[cell.DOC] = `Plot a bar chart in the current ImPlot.
:param label: The label for the bar series.
:param data: An array of [x,y] points or just an array of y-values.
:param width: The width of each bar in plot units.
:return: None
`;
imgui.textplot[cell.DOC] = `Render text at the specified coordinates in plot space.
:param text: The string to render.
:param coords: A 2-element array [x, y] in plot coordinates.
:return: None
`;
imgui.histogramplot[cell.DOC] = `Plot a histogram from the given data array/typed array in the current ImPlot.
:param label: The label for the histogram.
:param data: A typed array (or numeric array) containing the values to bin/display.
:return: None
`;
imgui.plotaxes[cell.DOC] = `Set up labels for the X and Y axes of the current ImPlot.
:param xLabel: The label for the x-axis.
:param yLabel: The label for the y-axis.
:return: None
`;
imgui.plotmousepos[cell.DOC] = `Get the mouse cursors position in the current plots coordinate system.
:return: A 2-element array [x, y] representing the mouse position in plot coordinates.
`;
imgui.plothovered[cell.DOC] = `Check if the mouse is hovering over the current ImPlot.
:return: True if the plot area is hovered, otherwise false.
`;
imgui.axeslimits[cell.DOC] = `Set up the visible axis limits in the current ImPlot.
:param xMin: The left (min) bound of the x-axis.
:param xMax: The right (max) bound of the x-axis.
:param yMin: The bottom (min) bound of the y-axis.
:param yMax: The top (max) bound of the y-axis.
:return: None
`;
imgui.prepend[cell.DOC] = `Prepare ImGui draw data for rendering, typically called after ImGui::Render().
:param commandBuffer: The SDL GPU command buffer where draw data will be queued.
:return: None
`;
imgui.fitaxis[cell.DOC] = `Fit either the x-axis or y-axis to its data range on the next plot frame.
:param axis: 0 for X-axis, 1 for Y-axis.
:return: None
`;
imgui.columns[cell.DOC] = `Switch the layout to use a specified number of columns.
:param count: The number of columns to layout in the current region.
:return: None
`;
imgui.nextcolumn[cell.DOC] = `Advance to the next column in a multi-column layout.
:return: None
`;
imgui.collapsingheader[cell.DOC] = `Create a collapsible header. Returns true if it is open (expanded).
:param label: The text label of the header.
:return: True if the header is expanded, otherwise false.
`;
imgui.tree[cell.DOC] = `Create a tree node. If opened, calls the callback for nested content.
:param label: The label for the tree node.
:param callback: A function called if the node is expanded.
:return: None
`;
imgui.listbox[cell.DOC] = `Create a list box widget to select from a list of strings.
:param label: The label next to the list box.
:param items: An array of strings to display.
:param selectedIndex: The currently selected index.
:return: The updated selected index after user selection.
`;
imgui.axisfmt[cell.DOC] = `Set a custom formatter for a specified y-axis in ImPlot.
:param axis: The y-axis index (0..2) to format.
:param callback: A function(value) => string that converts axis values to text.
:return: None
`;
imgui.tabbar[cell.DOC] = `Begin a tab bar container. The callback is invoked to create tabs.
:param label: The identifier label of the tab bar.
:param callback: A function that creates tab items.
:return: None
`;
imgui.tab[cell.DOC] = `Create a tab item. If selected, calls the callback for tab content.
:param label: The name of the tab.
:param callback: A function to render the tabs content if active.
:return: None
`;
imgui.open_popup[cell.DOC] = `Open a popup by its identifier.
:param label: The identifier of the popup to open.
:return: None
`;
imgui.modal[cell.DOC] = `Begin a modal popup. The callback is invoked to display contents if the modal is open.
:param label: The identifier of the modal popup.
:param callback: A function for rendering the modals UI if open.
:return: None
`;
imgui.popup[cell.DOC] = `Begin a popup. The callback is invoked if the popup is open.
:param label: The identifier of the popup.
:param callback: A function for rendering the popups UI.
:return: None
`;
imgui.close_popup[cell.DOC] = `Close the current popup.
:return: None
`;
imgui.context[cell.DOC] = `Create a popup context menu. The callback is invoked if the menu opens.
:param label: The identifier for the context menu.
:param callback: A function that renders menu items in the context.
:return: None
`;
imgui.table[cell.DOC] = `Create a table with multiple columns. Optionally enable sorting and pass a sort callback.
:param label: The identifier for the table.
:param columns: The number of columns.
:param callback: A function to populate the table (rows/cells).
:param sortCallback: An optional function(columnIndex, ascending) called if user sorts a column.
:return: None
`;
imgui.tablenextcolumn[cell.DOC] = `Move to the next column in a table row.
:return: None
`;
imgui.tablenextrow[cell.DOC] = `Move to the next row in a table.
:return: None
`;
imgui.tableheadersrow[cell.DOC] = `Create a row of headers in the current table (should be called once after column setup).
:return: None
`;
imgui.tableangledheadersrow[cell.DOC] = `Create an angled header row (for advanced usage). Typically not used as often.
:return: None
`;
imgui.tablesetupcolumn[cell.DOC] = `Setup configuration for a single column in the table.
:param label: The label/header text for this column.
:return: None
`;
imgui.dnd[cell.DOC] = `Begin a drag source for custom data payload.
:param type: A string identifier for the drag-drop payload type.
:param payload: A numeric payload stored in the drag-drop.
:param callback: (Currently unused) Placeholder if you want to do extra on drag start.
:return: None
`;
imgui.dndtarget[cell.DOC] = `Create a drop target for matching drag-drop payload type. Invokes callback on drop.
:param type: A string identifier for the drag-drop payload type to accept.
:param callback: A function(payloadNumber) called when a matching payload is dropped.
:return: None
`;
imgui.color[cell.DOC] = `Create a color editor (3 or 4 floats). Returns the updated color.
:param label: The label for the color editor.
:param color: An array [r,g,b] or [r,g,b,a].
:return: Updated color array after user input.
`;
imgui.startnode[cell.DOC] = `Begin a node editor session with ImNodes. The callback defines nodes.
Additional callbacks handle link creation and hover events.
:param callback: A function to define node editor contents (adding nodes, etc).
:param linkCreatedCallback: A function(startAttr, endAttr) called when a new link is created.
:param nodeHoveredCallback: A function(nodeId) called when a node is hovered.
:param linkHoveredCallback: A function(linkId) called when a link is hovered.
:return: None
`;
imgui.node[cell.DOC] = `Begin a node with a unique ID, then call the callback to define its contents.
:param nodeId: A unique integer ID for this node.
:param callback: A function that populates the nodes UI.
:return: None
`;
imgui.nodein[cell.DOC] = `Create an input attribute in the current node.
:param attributeId: The attribute ID for this input.
:param callback: A function that defines the UI within the input attribute.
:return: None
`;
imgui.nodeout[cell.DOC] = `Create an output attribute in the current node.
:param attributeId: The attribute ID for this output.
:param callback: A function that defines the UI within the output attribute.
:return: None
`;
imgui.nodelink[cell.DOC] = `Link two node attributes by their IDs.
:param linkId: A unique integer ID for this link.
:param startAttributeId: The attribute ID where the link starts.
:param endAttributeId: The attribute ID where the link ends.
:return: None
`;
imgui.nodemini[cell.DOC] = `Show a minimap for the current node editor.
:param size: A float controlling the minimap size ratio.
:return: None
`;
imgui.mousehoveringrect[cell.DOC] = `Check if the mouse is hovering within the given rectangle.
:param min: A 2-element array [x, y] for the top-left corner.
:param max: A 2-element array [x, y] for the bottom-right corner.
:return: True if the mouse is within that rectangle, otherwise false.
`;
imgui.mouseclicked[cell.DOC] = `Check if a specific mouse button was clicked (went from up to down) this frame.
:param button: An integer for the mouse button index (0 = left, 1 = right, etc).
:return: True if the button was clicked, otherwise false.
`;
imgui.mousedown[cell.DOC] = `Check if the specified mouse button is currently held down.
:param button: The mouse button index.
:return: True if the button is down, otherwise false.
`;
imgui.mousereleased[cell.DOC] = `Check if the specified mouse button was released this frame.
:param button: The mouse button index.
:return: True if the button was released, otherwise false.
`;
imgui.mousedragging[cell.DOC] = `Check if the mouse is being dragged with the specified button.
:param button: The mouse button index.
:return: True if the mouse is dragging, otherwise false.
`;
imgui.mousedelta[cell.DOC] = `Get the mouse movement delta (difference) for the current frame.
:return: A 2-element array [dx, dy] representing the mouse movement.
`;
imgui.rect[cell.DOC] = `Draw a rectangle outline in the current windows draw list.
:param pMin: A 2-element array [x, y] for the top-left corner.
:param pMax: A 2-element array [x, y] for the bottom-right corner.
:param color: A 4-element array [r, g, b, a] specifying the outline color.
:return: None
`;
imgui.rectfilled[cell.DOC] = `Draw a filled rectangle in the current windows draw list.
:param pMin: [x, y] for the top-left corner.
:param pMax: [x, y] for the bottom-right corner.
:param color: [r, g, b, a] fill color.
:return: None
`;
imgui.line[cell.DOC] = `Draw a line between two points in the current windows draw list.
:param p1: [x, y] start position.
:param p2: [x, y] end position.
:param color: [r, g, b, a] line color.
:return: None
`;
imgui.bezierquad[cell.DOC] = `Draw a quadratic bezier curve.
:param p1: [x, y] start point.
:param p2: [x, y] control point.
:param p3: [x, y] end point.
:param color: [r, g, b, a] color.
:param thickness: Line thickness.
:return: None
`;
imgui.beziercubic[cell.DOC] = `Draw a cubic bezier curve.
:param p1: [x, y] start point.
:param p2: [x, y] first control point.
:param p3: [x, y] second control point.
:param p4: [x, y] end point.
:param color: [r, g, b, a] color.
:param thickness: Line thickness.
:return: None
`;
imgui.point[cell.DOC] = `Draw a filled circle (point) in the current windows draw list.
:param center: [x, y] center of the circle.
:param radius: The radius of the circle.
:param color: [r, g, b, a] fill color.
:return: None
`;
imgui.drawtext[cell.DOC] = `Draw text at the given screen position with a specified color.
:param text: The string to draw.
:param position: [x, y] in screen coordinates.
:param color: [r, g, b, a] text color.
:return: None
`;
imgui.cursorscreenpos[cell.DOC] = `Get the current ImGui cursor screen position.
:return: A 2-element array [x, y] in screen coordinates.
`;
imgui.setcursorscreenpos[cell.DOC] = `Set the ImGui cursor screen position.
:param position: A 2-element array [x, y] in screen coordinates.
:return: None
`;
imgui.contentregionavail[cell.DOC] = `Return the available space in the current windows content region.
:return: A 2-element array [width, height] of available space.
`;
imgui.dummy[cell.DOC] = `Add a dummy item (invisible) of the specified size to the layout.
:param size: A 2-element array [width, height].
:return: None
`;
imgui.invisiblebutton[cell.DOC] = `Create an invisible button that occupies a given size and can catch clicks.
:param label: The identifier for the button.
:param size: [width, height] specifying the button area.
:return: None
`;
imgui.width[cell.DOC] = `Set the width of the next item in the layout.
:param width: The width (in pixels) for the next item.
:return: None
`;
imgui.setclipboard[cell.DOC] = `Set the system clipboard text.
:param text: The string to put into the clipboard.
:return: None
`;
imgui.newframe[cell.DOC] = `Start a new ImGui frame. Should be called once per frame before rendering UI elements.
:return: None
`;
imgui.endframe[cell.DOC] = `Finalize and render the ImGui draw data to the specified command buffer and render pass.
:param commandBuffer: The SDL GPU command buffer to render into.
:param renderPass: The SDL GPU render pass used to draw ImGui data.
:return: None
`;
imgui.wantmouse[cell.DOC] = `Check if ImGui wants to capture the mouse (e.g., if a window or widget needs mouse events).
:return: True if ImGui is capturing the mouse, otherwise false.
`;
imgui.wantkeys[cell.DOC] = `Check if ImGui wants to capture the keyboard (e.g., if a text input is active).
:return: True if ImGui is capturing the keyboard, otherwise false.
`;
imgui.init[cell.DOC] = `Initialize ImGui with SDL and SDL_gpu, creating the ImGui context and configuring it.
:param gpuDevice: The SDL_GPUDevice object.
:param window: The SDL_Window object to attach ImGui onto.
:return: None
`;
return this