Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 81e0956
Author: Kleber Garcia <[email protected]>
Date:   Sat Aug 12 23:21:24 2023 -0400

    Tutorial, and more apis for imgui

commit 6536ef9
Author: Kleber Garcia <[email protected]>
Date:   Sun Aug 6 21:27:45 2023 -0400

    Improving docs

commit 721dcce
Author: Kleber Garcia <[email protected]>
Date:   Sun Aug 6 20:37:09 2023 -0400

    Tutorial layout

commit 49c791e
Author: Kleber Garcia <[email protected]>
Date:   Sun Aug 6 20:12:43 2023 -0400

    Initial tutorial files

commit 0523b0d
Author: Kleber Garcia <[email protected]>
Date:   Sat Jul 29 19:51:41 2023 -0400

    ignore generated files from jekyll site

commit fb46627
Author: Kleber Garcia <[email protected]>
Date:   Sat Jul 29 19:49:59 2023 -0400

    Gemfiles of site
  • Loading branch information
kecho committed Aug 13, 2023
1 parent 6dc46d2 commit 81d2c21
Show file tree
Hide file tree
Showing 28 changed files with 1,211 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ t2-output
tags
imgui.ini
.shader_pdb

docs/_site/*
154 changes: 154 additions & 0 deletions Source/pymodules/gpu/ImguiBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,160 @@ PyObject* treePop(PyObject* self, PyObject* vargs, PyObject* kwds)
Py_RETURN_NONE;
}

PyObject* colorEdit3(PyObject* self, PyObject* vargs, PyObject* kwds)
{
ModuleState& moduleState = parentModule(self);
CHECK_IMGUI

char* label = nullptr;
PyObject* c = nullptr;
int flags = 0;

static char* argnames[] = { "label", "col", "flags", nullptr };
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "sO|i", argnames, &label, &c, &flags))
return nullptr;

float colVal[3];
if (!getTupleValuesFloat(c, colVal, 3, 3))
{
PyErr_SetString(moduleState.exObj(), "Cannot parse col value. Must be a tuple or list of length 3");
return nullptr;
}

if (ImGui::ColorEdit3(label, colVal, flags))
return Py_BuildValue("(fff)", colVal[0], colVal[1], colVal[2]);
else
Py_RETURN_NONE;
}


PyObject* colorEdit4(PyObject* self, PyObject* vargs, PyObject* kwds)
{
ModuleState& moduleState = parentModule(self);
CHECK_IMGUI

char* label = nullptr;
PyObject* c = nullptr;
int flags = 0;

static char* argnames[] = { "label", "col", "flags", nullptr };
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "sO|i", argnames, &label, &c, &flags))
return nullptr;

float colVal[4];
if (!getTupleValuesFloat(c, colVal, 4, 4))
{
PyErr_SetString(moduleState.exObj(), "Cannot parse col value. Must be a tuple or list of length 4");
return nullptr;
}

if (ImGui::ColorEdit4(label, colVal, flags))
return Py_BuildValue("(ffff)", colVal[0], colVal[1], colVal[2], colVal[3]);
else
Py_RETURN_NONE;
}

PyObject* colorPicker3(PyObject* self, PyObject* vargs, PyObject* kwds)
{
ModuleState& moduleState = parentModule(self);
CHECK_IMGUI

char* label = nullptr;
PyObject* c = nullptr;
int flags = 0;

static char* argnames[] = { "label", "col", "flags", nullptr };
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "sO|i", argnames, &label, &c, &flags))
return nullptr;

float colVal[3];
if (!getTupleValuesFloat(c, colVal, 3, 3))
{
PyErr_SetString(moduleState.exObj(), "Cannot parse col value. Must be a tuple or list of length 3");
return nullptr;
}

if (ImGui::ColorPicker3(label, colVal, flags))
return Py_BuildValue("(fff)", colVal[0], colVal[1], colVal[2]);
else
Py_RETURN_NONE;
}

PyObject* colorPicker4(PyObject* self, PyObject* vargs, PyObject* kwds)
{
ModuleState& moduleState = parentModule(self);
CHECK_IMGUI

char* label = nullptr;
PyObject* c = nullptr;
int flags = 0;

static char* argnames[] = { "label", "col", "flags", nullptr };
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "sO|i", argnames, &label, &c, &flags))
return nullptr;

float colVal[4];
if (!getTupleValuesFloat(c, colVal, 4, 4))
{
PyErr_SetString(moduleState.exObj(), "Cannot parse col value. Must be a tuple or list of length 4");
return nullptr;
}

if (ImGui::ColorPicker4(label, colVal, flags))
return Py_BuildValue("(ffff)", colVal[0], colVal[1], colVal[2], colVal[3]);
else
Py_RETURN_NONE;
}

PyObject* colorButton(PyObject* self, PyObject* vargs, PyObject* kwds)
{
ModuleState& moduleState = parentModule(self);
CHECK_IMGUI

char* label = nullptr;
PyObject* c = nullptr;
PyObject* s = nullptr;
int flags = 0;

static char* argnames[] = { "desc_id", "col", "flags", "size", nullptr };
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "sO|iO", argnames, &label, &c, &flags, &s))
return nullptr;

float sz[2] = { 0.0f, 0.0f };
if (s != nullptr && !getTupleValuesFloat(s, sz, 2, 2))
{
PyErr_SetString(moduleState.exObj(), "Cannot parse size value. Must be a tuple or list of length 4");
return nullptr;
}

float colVal[4];
if (!getTupleValuesFloat(c, colVal, 4, 4))
{
PyErr_SetString(moduleState.exObj(), "Cannot parse col value. Must be a tuple or list of length 4");
return nullptr;
}

ImVec2 sizeArg(sz[0], sz[1]);
ImVec4 colArg(colVal[0], colVal[1], colVal[2], colVal[3]);
if (ImGui::ColorButton(label, colArg, flags, sizeArg))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}

PyObject* setColorEditOptions(PyObject* self, PyObject* vargs, PyObject* kwds)
{
CHECK_IMGUI
static char* argnames[] = { "flags", nullptr };
int flags = 0;
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "i", argnames, &flags))
return nullptr;

ImGui::SetColorEditOptions(flags);
Py_RETURN_NONE;
}


}//methods

}//gpu
Expand Down
16 changes: 16 additions & 0 deletions Source/pymodules/gpu/ModuleSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ namespace methods
else
Py_RETURN_FALSE;
}

PyObject* loadSettings(PyObject* self, PyObject* vargs, PyObject* kwds)
{
ModuleState& moduleState = parentModule(self);
ModuleSettings* settingsObj = reinterpret_cast<ModuleSettings*>(self);

static char* arguments[] = { "filename", nullptr };
char* fileName = nullptr;
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "s", arguments, &fileName))
return nullptr;

if (settingsObj->load(moduleState.fs(), fileName))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion Source/pymodules/gpu/SettingsSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bool SettingsSchema::serialize(IFileSystem& fs, const char* filename, const void
fs.closeHandle(handle);
free(str);
cJSON_Delete(root);
return false;
return success;
}

bool SettingsSchema::load(IFileSystem& fs, const char* filename, void* settingsObj)
Expand Down
90 changes: 89 additions & 1 deletion Source/pymodules/gpu/bindings/Imgui.inl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ COALPY_FN(input_float, inputFloat, R"(
The new float value that the user set. Feed this value back on v on the next call to see a proper state update.
)")

COALPY_FN(input_float3, inputFloat3, R"(
COALPY_FN(input_float2, inputFloat2, R"(
Draws a box to input a float2 value.
Parameters:
Expand Down Expand Up @@ -661,6 +661,66 @@ COALPY_FN(tree_pop, treePop, R"(
Must be called if tree_node returns True.
)")

COALPY_FN(color_edit3, colorEdit3, R"(
Parameters:
label (str): label of widget
col (float): tuple or array size 3 of color values (tuple or array)
flags (optional): see coalpy.gpu.ImGuiColorEditFlags
Return:
The color edited (tuple of size 3) or None if nothing was set
)")

COALPY_FN(color_edit4, colorEdit4, R"(
Parameters:
label (str): label of widget
col (float): tuple or array size 4 of color values (tuple or array)
flags (optional): see coalpy.gpu.ImGuiColorEditFlags
Return:
The color edited (tuple of size 4) or None if nothing was set
)")

COALPY_FN(color_picker3, colorPicker3, R"(
Parameters:
label (str): label of widget
col (float): tuple or array size 3 of color values (tuple or array)
flags (optional): see coalpy.gpu.ImGuiColorEditFlags
Return:
The color picked (tuple of size 3) or None if nothing was set
)")

COALPY_FN(color_picker4, colorPicker4, R"(
Parameters:
label (str): label of widget
col (float): tuple or array size 4 of color values (tuple or array)
flags (optional): see coalpy.gpu.ImGuiColorEditFlags
Return:
The color picked (tuple of size 4) or None if nothing was set
)")

COALPY_FN(color_button, colorButton, R"(
display a color square/button, hover for details, return true when pressed.
Parameters:
desc_id (str)
col (float): tuple size 4 of color
flags (optional): see coalpy.gpu.ImGuiColorEditFlags
size (float tuple 2)(optional): size of the button. Defualt is (0, 0)
Return:
True if pressed, false otherwise
)")

COALPY_FN(set_color_edit_options, setColorEditOptions, R"(
initialize current options (generally on application startup) if you want to select a default format, picker type, etc. User will be able to change many settings, unless you pass the _NoOptions flag to your calls.
Parameters:
flags : see coalpy.gpu.ImGuiColorEditFlags
)")


//Imgui focus flags enums
COALPY_ENUM_BEGIN(ImGuiFocusedFlags, "ImGUI Focused flags")
Expand Down Expand Up @@ -920,6 +980,34 @@ COALPY_ENUM(Leading, ImGuiTabItemFlags_Leading, R"(Enforce
COALPY_ENUM(Trailing, ImGuiTabItemFlags_Trailing, R"(the tab position to the right of the tab bar (before the scrolling buttons))")
COALPY_ENUM_END(ImGuiTabItemFlags)

COALPY_ENUM_BEGIN(ImGuiColorEditFlags, "")
COALPY_ENUM(None, ImGuiColorEditFlags_None, "")
COALPY_ENUM(NoAlpha, ImGuiColorEditFlags_NoAlpha, R"(ColorEdit, ColorPicker, ColorButton: ignore Alpha component (will only read 3 components from the input pointer).)")
COALPY_ENUM(NoPicker, ImGuiColorEditFlags_NoPicker, R"(ColorEdit: disable picker when clicking on color square.)")
COALPY_ENUM(NoOptions, ImGuiColorEditFlags_NoOptions, R"(ColorEdit: disable toggling options menu when right-clicking on inputs/small preview.)")
COALPY_ENUM(NoSmallPreview, ImGuiColorEditFlags_NoSmallPreview, R"(ColorEdit, ColorPicker: disable color square preview next to the inputs. (e.g. to show only the inputs))")
COALPY_ENUM(NoInputs, ImGuiColorEditFlags_NoInputs, R"(ColorEdit, ColorPicker: disable inputs sliders/text widgets (e.g. to show only the small preview color square).)")
COALPY_ENUM(NoTooltip, ImGuiColorEditFlags_NoTooltip, R"(ColorEdit, ColorPicker, ColorButton: disable tooltip when hovering the preview.)")
COALPY_ENUM(NoLabel, ImGuiColorEditFlags_NoLabel, R"(ColorEdit, ColorPicker: disable display of inline text label (the label is still forwarded to the tooltip and picker).)")
COALPY_ENUM(NoSidePreview, ImGuiColorEditFlags_NoSidePreview, R"(ColorPicker: disable bigger color preview on right side of the picker, use small color square preview instead.)")
COALPY_ENUM(NoDragDrop, ImGuiColorEditFlags_NoDragDrop, R"(ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source.)")
COALPY_ENUM(NoBorder, ImGuiColorEditFlags_NoBorder, R"(ColorButton: disable border (which is enforced by default))")
COALPY_ENUM(AlphaBar, ImGuiColorEditFlags_AlphaBar, R"(ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker.)")
COALPY_ENUM(AlphaPreview, ImGuiColorEditFlags_AlphaPreview, R"(ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque.)")
COALPY_ENUM(AlphaPreviewHalf, ImGuiColorEditFlags_AlphaPreviewHalf, R"(ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque.)")
COALPY_ENUM(HDR, ImGuiColorEditFlags_HDR, R"((WIP) ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well).)")
COALPY_ENUM(DisplayRGB, ImGuiColorEditFlags_DisplayRGB, R"([Display] ColorEdit: override _display_ type among RGB/HSV/Hex. ColorPicker: select any combination using one or more of RGB/HSV/Hex.)")
COALPY_ENUM(DisplayHSV, ImGuiColorEditFlags_DisplayHSV, R"([Display] ")")
COALPY_ENUM(DisplayHex, ImGuiColorEditFlags_DisplayHex, R"([Display] ")")
COALPY_ENUM(Uint8, ImGuiColorEditFlags_Uint8, R"([DataType] ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255.)")
COALPY_ENUM(Float, ImGuiColorEditFlags_Float, R"([DataType] ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers.)")
COALPY_ENUM(PickerHueBar, ImGuiColorEditFlags_PickerHueBar, R"([Picker] ColorPicker: bar for Hue, rectangle for Sat/Value.)")
COALPY_ENUM(PickerHueWheel, ImGuiColorEditFlags_PickerHueWheel, R"([Picker] ColorPicker: wheel for Hue, triangle for Sat/Value.)")
COALPY_ENUM(InputRGB, ImGuiColorEditFlags_InputRGB, R"([Input] ColorEdit, ColorPicker: input and output data in RGB format.)")
COALPY_ENUM(InputHSV, ImGuiColorEditFlags_InputHSV, R"([Input] ColorEdit, ColorPicker: input and output data in HSV format.)")
COALPY_ENUM(DefaultOptions_, ImGuiColorEditFlags_DefaultOptions_, "Default options")
COALPY_ENUM_END(ImGuiColorEditFlags)

#undef COALPY_ENUM_END
#undef COALPY_ENUM_BEGIN
#undef COALPY_ENUM
Expand Down
2 changes: 1 addition & 1 deletion Source/pymodules/gpu/bindings/ModuleFunctions.inl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COALPY_FN(get_settings, getSettings,
Returns an object containing all the settings loaded for the coalpy.gpu module.
Returns:
Object: object containing all the settings loaded for coalpy.gpu
Object (Settings): object containing all the settings loaded for coalpy.gpu of type Settings.
)"
)

Expand Down
13 changes: 11 additions & 2 deletions Source/pymodules/gpu/bindings/ModuleSettings.inl
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
COALPY_FN(save, saveSettings, R"(
Saves settings to a file.
Saves settings to a json file.
Parameters:
filename (optional): optional name of the device.
filename (optional): optional name of the file. Ensure to include the .json extension if specified.
If not used, default settings are saved in ".coalpy_settings.json"
which is the default settings read at module boot.
Returns:
True if successful, False if it failed.
)")

COALPY_FN(load, loadSettings, R"(
Load settings from a json file.
Parameters:
filename: name of the file to load.
Returns:
True if successful, False if it failed.
)")

#undef COALPY_FN
Loading

0 comments on commit 81d2c21

Please sign in to comment.