mirror of https://github.com/mode777/rayjs.git
Use raygui as submodule
This commit is contained in:
parent
2da4065b07
commit
1947483541
|
@ -8,3 +8,4 @@
|
||||||
[submodule "thirdparty/raygui"]
|
[submodule "thirdparty/raygui"]
|
||||||
path = thirdparty/raygui
|
path = thirdparty/raygui
|
||||||
url = https://github.com/raysan5/raygui.git
|
url = https://github.com/raysan5/raygui.git
|
||||||
|
branch = tags/3.6
|
||||||
|
|
|
@ -37,6 +37,5 @@ file(GLOB files src/*.c)
|
||||||
add_executable(${CMAKE_PROJECT_NAME} ${files})
|
add_executable(${CMAKE_PROJECT_NAME} ${files})
|
||||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE include)
|
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE include)
|
||||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE src)
|
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE src)
|
||||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE thirdparty/raylib/examples/shapes)
|
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE thirdparty/raygui/src)
|
||||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE thirdparty/raylib/examples/shaders)
|
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME} quickjs raylib)
|
target_link_libraries(${CMAKE_PROJECT_NAME} quickjs raylib)
|
|
@ -42,4 +42,8 @@ export class ApiDescription{
|
||||||
if(!s) return null
|
if(!s) return null
|
||||||
return new ApiStruct(s)
|
return new ApiStruct(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getEnums(){
|
||||||
|
return this.api.enums
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -202,6 +202,15 @@ export abstract class GenericCodeGenerator<T extends CodeGenerator> {
|
||||||
this.line("#include <" + name + ">")
|
this.line("#include <" + name + ">")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public for(indexVar: string, lengthVar: string){
|
||||||
|
this.line(`for(int ${indexVar}; i < ${lengthVar}; i++){`)
|
||||||
|
this.indent()
|
||||||
|
const child = this.child()
|
||||||
|
this.unindent()
|
||||||
|
this.line("}")
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
public header(guard: string, fun?: (gen: T) => void){
|
public header(guard: string, fun?: (gen: T) => void){
|
||||||
this.line("#ifndef " + guard)
|
this.line("#ifndef " + guard)
|
||||||
this.line("#define " + guard)
|
this.line("#define " + guard)
|
||||||
|
|
|
@ -26,18 +26,19 @@ function main(){
|
||||||
const cameraApi = parser.parseFunctionDefinitions(rcameraHeader);
|
const cameraApi = parser.parseFunctionDefinitions(rcameraHeader);
|
||||||
cameraApi.forEach(x => api.functions.push(x))
|
cameraApi.forEach(x => api.functions.push(x))
|
||||||
|
|
||||||
const rguiHeader = readFileSync("thirdparty/raylib/examples/shapes/raygui.h","utf8");
|
const rguiHeader = readFileSync("thirdparty/raygui/src/raygui.h","utf8");
|
||||||
const rguiFunctions = parser.parseFunctionDefinitions(rguiHeader);
|
const rguiFunctions = parser.parseFunctionDefinitions(rguiHeader);
|
||||||
const rguiEnums = parser.parseFunctionDefinitions(rguiHeader);
|
const rguiEnums = parser.parseEnums(rguiHeader);
|
||||||
//rguiApi.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
//rguiApi.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
||||||
rguiFunctions.forEach(x => api.functions.push(x))
|
rguiFunctions.forEach(x => api.functions.push(x))
|
||||||
|
rguiEnums.forEach(x => api.enums.push(x))
|
||||||
|
|
||||||
const rlightsHeader = readFileSync("thirdparty/raylib/examples/shaders/rlights.h","utf8");
|
const rlightsHeader = readFileSync("include/rlights.h","utf8");
|
||||||
const rlightsFunctions = parser.parseFunctions(rlightsHeader, true);
|
const rlightsFunctions = parser.parseFunctions(rlightsHeader, true);
|
||||||
api.functions.push(rlightsFunctions[0])
|
api.functions.push(rlightsFunctions[0])
|
||||||
api.functions.push(rlightsFunctions[1])
|
api.functions.push(rlightsFunctions[1])
|
||||||
|
|
||||||
const reasingsHeader = readFileSync("thirdparty/raylib/examples/shapes/reasings.h","utf8");
|
const reasingsHeader = readFileSync("include/reasings.h","utf8");
|
||||||
const reasingsFunctions = parser.parseFunctions(reasingsHeader);
|
const reasingsFunctions = parser.parseFunctions(reasingsHeader);
|
||||||
//reasingsFunctions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
//reasingsFunctions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
||||||
reasingsFunctions.forEach(x => api.functions.push(x))
|
reasingsFunctions.forEach(x => api.functions.push(x))
|
||||||
|
@ -445,7 +446,18 @@ function main(){
|
||||||
//core.addApiFunctionByName("LoadDirectoryFilesEx")
|
//core.addApiFunctionByName("LoadDirectoryFilesEx")
|
||||||
// UnloadDirectoryFiles
|
// UnloadDirectoryFiles
|
||||||
core.addApiFunctionByName("IsFileDropped")
|
core.addApiFunctionByName("IsFileDropped")
|
||||||
//core.addApiFunctionByName("LoadDroppedFiles")
|
const ldf = apiDesc.getFunction("LoadDroppedFiles")
|
||||||
|
ldf!.returnType = "string[]"
|
||||||
|
core.addApiFunction(ldf!, null, {
|
||||||
|
body: gen => {
|
||||||
|
gen.call("LoadDroppedFiles", [], { type: "FilePathList", name: "files" })
|
||||||
|
gen.call("JS_NewArray", ["ctx"], { type: "JSValue", name:"ret"})
|
||||||
|
const f = gen.for("i", "files.count")
|
||||||
|
f.call("JS_SetPropertyUint32", ["ctx","ret", "i", "JS_NewString(ctx,files.paths[i])"])
|
||||||
|
gen.call("UnloadDroppedFiles", ["files"])
|
||||||
|
gen.returnExp("ret")
|
||||||
|
}
|
||||||
|
})
|
||||||
// UnloadDroppedFiles
|
// UnloadDroppedFiles
|
||||||
core.addApiFunctionByName("GetFileModTime")
|
core.addApiFunctionByName("GetFileModTime")
|
||||||
|
|
||||||
|
@ -1072,7 +1084,7 @@ function main(){
|
||||||
//core.addApiFunctionByName("GuiSpinner")
|
//core.addApiFunctionByName("GuiSpinner")
|
||||||
//core.addApiFunctionByName("GuiValueBox")
|
//core.addApiFunctionByName("GuiValueBox")
|
||||||
core.addApiFunctionByName("GuiTextBox")
|
core.addApiFunctionByName("GuiTextBox")
|
||||||
core.addApiFunctionByName("GuiTextBoxMulti")
|
//core.addApiFunctionByName("GuiTextBoxMulti")
|
||||||
core.addApiFunctionByName("GuiSlider")
|
core.addApiFunctionByName("GuiSlider")
|
||||||
core.addApiFunctionByName("GuiSliderBar")
|
core.addApiFunctionByName("GuiSliderBar")
|
||||||
core.addApiFunctionByName("GuiProgressBar")
|
core.addApiFunctionByName("GuiProgressBar")
|
||||||
|
@ -1095,9 +1107,6 @@ function main(){
|
||||||
//core.addApiFunctionByName("GuiGetIconData")
|
//core.addApiFunctionByName("GuiGetIconData")
|
||||||
//core.addApiFunctionByName("GuiSetIconData")
|
//core.addApiFunctionByName("GuiSetIconData")
|
||||||
core.addApiFunctionByName("GuiSetIconScale")
|
core.addApiFunctionByName("GuiSetIconScale")
|
||||||
core.addApiFunctionByName("GuiSetIconPixel")
|
|
||||||
core.addApiFunctionByName("GuiClearIconPixel")
|
|
||||||
core.addApiFunctionByName("GuiCheckIconPixel")
|
|
||||||
|
|
||||||
// module: rlights
|
// module: rlights
|
||||||
// TODO: Parse and support light struct
|
// TODO: Parse and support light struct
|
||||||
|
@ -1132,18 +1141,20 @@ function main(){
|
||||||
api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, description: x.description, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => {
|
api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, description: x.description, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => {
|
||||||
core.exportGlobalStruct("Color", x.name, x.values, x.description)
|
core.exportGlobalStruct("Color", x.name, x.values, x.description)
|
||||||
})
|
})
|
||||||
api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
|
||||||
api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
core.addAllEnums()
|
||||||
api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "MouseCursor")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "MouseCursor")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "CameraMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "ShaderLocationIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "ShaderUniformDataType")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "CameraMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "MaterialMapIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
// api.enums.find(x => x.name === "ShaderLocationIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
|
// api.enums.find(x => x.name === "ShaderUniformDataType")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
|
// api.enums.find(x => x.name === "MaterialMapIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
core.exportGlobalConstant("MATERIAL_MAP_DIFFUSE", "Albedo material (same as: MATERIAL_MAP_DIFFUSE")
|
core.exportGlobalConstant("MATERIAL_MAP_DIFFUSE", "Albedo material (same as: MATERIAL_MAP_DIFFUSE")
|
||||||
core.exportGlobalConstant("MATERIAL_MAP_SPECULAR", "Metalness material (same as: MATERIAL_MAP_SPECULAR)")
|
core.exportGlobalConstant("MATERIAL_MAP_SPECULAR", "Metalness material (same as: MATERIAL_MAP_SPECULAR)")
|
||||||
core.writeTo("src/bindings/js_raylib_core.h")
|
core.writeTo("src/bindings/js_raylib_core.h")
|
||||||
|
|
|
@ -72,6 +72,10 @@ export class RayLibHeader extends QuickJsHeader {
|
||||||
this.addApiFunction(func, jsName, options)
|
this.addApiFunction(func, jsName, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addAllEnums(){
|
||||||
|
this.api.getEnums().forEach(x => x.values.forEach(y => this.exportGlobalConstant(y.name, y.description)))
|
||||||
|
}
|
||||||
|
|
||||||
addApiStruct(struct: ApiStruct, destructor: ApiFunction | null, options?: StructBindingOptions){
|
addApiStruct(struct: ApiStruct, destructor: ApiFunction | null, options?: StructBindingOptions){
|
||||||
const classId = this.definitions.jsClassId(`js_${struct.name}_class_id`)
|
const classId = this.definitions.jsClassId(`js_${struct.name}_class_id`)
|
||||||
this.registerStruct(struct.name, classId)
|
this.registerStruct(struct.name, classId)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,221 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raygui - controls test suite
|
||||||
|
*
|
||||||
|
* TEST CONTROLS:
|
||||||
|
* - GuiDropdownBox()
|
||||||
|
* - GuiCheckBox()
|
||||||
|
* - GuiSpinner()
|
||||||
|
* - GuiValueBox()
|
||||||
|
* - GuiTextBox()
|
||||||
|
* - GuiButton()
|
||||||
|
* - GuiComboBox()
|
||||||
|
* - GuiListView()
|
||||||
|
* - GuiToggleGroup()
|
||||||
|
* - GuiColorPicker()
|
||||||
|
* - GuiSlider()
|
||||||
|
* - GuiSliderBar()
|
||||||
|
* - GuiProgressBar()
|
||||||
|
* - GuiColorBarAlpha()
|
||||||
|
* - GuiScrollPanel()
|
||||||
|
*
|
||||||
|
* LICENSE: zlib/libpng
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2023 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
**********************************************************************************************/
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const screenWidth = 690;
|
||||||
|
const screenHeight = 560;
|
||||||
|
|
||||||
|
initWindow(screenWidth, screenHeight, "raygui - controls test suite");
|
||||||
|
setExitKey(0);
|
||||||
|
|
||||||
|
// GUI controls initialization
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
let dropdownBox000Active = 0;
|
||||||
|
let dropDown000EditMode = false;
|
||||||
|
|
||||||
|
let dropdownBox001Active = 0;
|
||||||
|
let dropDown001EditMode = false;
|
||||||
|
|
||||||
|
let spinner001Value = 0;
|
||||||
|
let spinnerEditMode = false;
|
||||||
|
|
||||||
|
let valueBox002Value = 0;
|
||||||
|
let valueBoxEditMode = false;
|
||||||
|
|
||||||
|
let textBoxText = "Text box";
|
||||||
|
let textBoxEditMode = false;
|
||||||
|
|
||||||
|
let listViewScrollIndex = 0;
|
||||||
|
let listViewActive = -1;
|
||||||
|
|
||||||
|
let listViewExScrollIndex = 0;
|
||||||
|
let listViewExActive = 2;
|
||||||
|
let listViewExFocus = -1;
|
||||||
|
let listViewExList = [ "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" ];
|
||||||
|
|
||||||
|
let multiTextBoxText = "Multi text box";
|
||||||
|
let multiTextBoxEditMode = false;
|
||||||
|
let colorPickerValue = RED;
|
||||||
|
|
||||||
|
let sliderValue = 50.0;
|
||||||
|
let sliderBarValue = 60;
|
||||||
|
let progressValue = 0.4;
|
||||||
|
|
||||||
|
let forceSquaredChecked = false;
|
||||||
|
|
||||||
|
let alphaValue = 0.5;
|
||||||
|
|
||||||
|
let comboBoxActive = 1;
|
||||||
|
|
||||||
|
let toggleGroupActive = 0;
|
||||||
|
|
||||||
|
let viewScroll = new Vector2(0, 0);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Custom GUI font loading
|
||||||
|
//Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
|
||||||
|
//GuiSetFont(font);
|
||||||
|
|
||||||
|
let exitWindow = false;
|
||||||
|
let showMessageBox = false;
|
||||||
|
|
||||||
|
let textInput = new Array(256).fill(0);
|
||||||
|
let showTextInputBox = false;
|
||||||
|
|
||||||
|
let textInputFileName = new Array(256).fill(0);
|
||||||
|
|
||||||
|
setTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!exitWindow) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
exitWindow = windowShouldClose();
|
||||||
|
|
||||||
|
if (isKeyPressed(KEY_ESCAPE)) showMessageBox = !showMessageBox;
|
||||||
|
|
||||||
|
if (isKeyDown(KEY_LEFT_CONTROL) && isKeyPressed(KEY_S)) showTextInputBox = true;
|
||||||
|
|
||||||
|
if (isFileDropped())
|
||||||
|
{
|
||||||
|
const droppedFiles = loadDroppedFiles();
|
||||||
|
|
||||||
|
if ((droppedFiles.length > 0) && isFileExtension(droppedFiles[0], ".rgs")) guiLoadStyle(droppedFiles.paths[0]);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
beginDrawing();
|
||||||
|
|
||||||
|
clearBackground(getColor(guiGetStyle(DEFAULT, BACKGROUND_COLOR)));
|
||||||
|
|
||||||
|
// raygui: controls drawing
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Check all possible events that require GuiLock
|
||||||
|
if (dropDown000EditMode ||
|
||||||
|
dropDown001EditMode) guiLock();
|
||||||
|
|
||||||
|
// First GUI column
|
||||||
|
guiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
|
||||||
|
forceSquareChecked = guiCheckBox(new Rectangle(25, 108, 15, 15), "FORCE CHECK!", forceSquaredChecked);
|
||||||
|
|
||||||
|
guiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
|
||||||
|
guiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
|
||||||
|
if (guiSpinner(new Rectangle(25, 135, 125, 30), NULL, &spinner001Value, 0, 100, spinnerEditMode)) spinnerEditMode = !spinnerEditMode;
|
||||||
|
//if (guiValueBox(new Rectangle(25, 175, 125, 30), NULL, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
|
||||||
|
guiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
|
||||||
|
if (guiTextBox(new Rectangle(25, 215, 125, 30), textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
|
||||||
|
|
||||||
|
guiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
|
||||||
|
|
||||||
|
if (guiButton(new Rectangle( 25, 255, 125, 30 ), guiIconText(ICON_FILE_SAVE, "Save File"))) showTextInputBox = true;
|
||||||
|
|
||||||
|
guiGroupBox(Rectangle( 25, 310, 125, 150 ), "STATES");
|
||||||
|
//GuiLock();
|
||||||
|
guiSetState(STATE_NORMAL); if (guiButton(new Rectangle(30, 320, 115, 30), "NORMAL")) { }
|
||||||
|
guiSetState(STATE_FOCUSED); if (guiButton(new Rectangle(30, 355, 115, 30), "FOCUSED")) { }
|
||||||
|
guiSetState(STATE_PRESSED); if (guiButton(new Rectangle(30, 390, 115, 30), "#15#PRESSED")) { }
|
||||||
|
guiSetState(STATE_DISABLED); if (guiButton(new Rectangle(30, 425, 115, 30), "DISABLED")) { }
|
||||||
|
guiSetState(STATE_NORMAL);
|
||||||
|
//GuiUnlock();
|
||||||
|
|
||||||
|
comboBoxActive = guiComboBox(new Rectangle(25, 470, 125, 30), "ONE;TWO;THREE;FOUR", comboBoxActive);
|
||||||
|
|
||||||
|
// NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
|
||||||
|
GuiUnlock();
|
||||||
|
GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
|
||||||
|
if (GuiDropdownBox(new Rectangle(25, 65, 125, 30), "#01#ONE;#02#TWO;#03#THREE;#04#FOUR", &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
|
||||||
|
|
||||||
|
GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
|
||||||
|
if (GuiDropdownBox(new Rectangle(25, 25, 125, 30), "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
|
||||||
|
|
||||||
|
// Second GUI column
|
||||||
|
GuiListView(new Rectangle(165, 25, 140, 140), "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, &listViewActive);
|
||||||
|
GuiListViewEx(new Rectangle(165, 180, 140, 200), listViewExList, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus);
|
||||||
|
|
||||||
|
//GuiToggle(new Rectangle(165, 400, 140, 25), "#1#ONE", &toggleGroupActive);
|
||||||
|
GuiToggleGroup(new Rectangle(165, 400, 140, 25), "#1#ONE\n#3#TWO\n#8#THREE\n#23#", &toggleGroupActive);
|
||||||
|
|
||||||
|
// Third GUI column
|
||||||
|
GuiPanel(new Rectangle(320, 25, 225, 140), "Panel Info");
|
||||||
|
GuiColorPicker(new Rectangle(320, 185, 196, 192), NULL, &colorPickerValue);
|
||||||
|
|
||||||
|
GuiSlider(new Rectangle(355, 400, 165, 20), "TEST", TextFormat("%2.2f", sliderValue), &sliderValue, -50, 100);
|
||||||
|
GuiSliderBar(new Rectangle(320, 430, 200, 20), NULL, TextFormat("%i", (int)sliderBarValue), &sliderBarValue, 0, 100);
|
||||||
|
GuiProgressBar(new Rectangle(320, 460, 200, 20), NULL, NULL, &progressValue, 0, 1);
|
||||||
|
|
||||||
|
// NOTE: View rectangle could be used to perform some scissor test
|
||||||
|
Rectangle view = { 0 };
|
||||||
|
GuiScrollPanel(new Rectangle(560, 25, 102, 354), NULL, new Rectangle(560, 25, 300, 1200), &viewScroll, &view);
|
||||||
|
|
||||||
|
Vector2 mouseCell = { 0 };
|
||||||
|
GuiGrid((Rectangle) { 560, 25 + 180 + 195, 100, 120 }, NULL, 20, 2, &mouseCell);
|
||||||
|
|
||||||
|
GuiStatusBar(new Rectangle(0, (float)GetScreenHeight() - 20, (float)GetScreenWidth(), 20), "This is a status bar");
|
||||||
|
|
||||||
|
GuiColorBarAlpha(new Rectangle(320, 490, 200, 30), NULL, &alphaValue);
|
||||||
|
|
||||||
|
if (showMessageBox)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f));
|
||||||
|
int result = GuiMessageBox(new Rectangle((float)GetScreenWidth()/2 - 125, (float)GetScreenHeight()/2 - 50, 250, 100), GuiIconText(ICON_EXIT, "Close Window"), "Do you really want to exit?", "Yes;No");
|
||||||
|
|
||||||
|
if ((result == 0) || (result == 2)) showMessageBox = false;
|
||||||
|
else if (result == 1) exitWindow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showTextInputBox)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f));
|
||||||
|
int result = GuiTextInputBox(new Rectangle((float)GetScreenWidth()/2 - 120, (float)GetScreenHeight()/2 - 60, 240, 140), "Save", GuiIconText(ICON_FILE_SAVE, "Save file as..."), "Ok;Cancel", textInput, 255, NULL);
|
||||||
|
|
||||||
|
if (result == 1)
|
||||||
|
{
|
||||||
|
// TODO: Validate textInput value and save
|
||||||
|
|
||||||
|
strcpy(textInputFileName, textInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((result == 0) || (result == 1) || (result == 2))
|
||||||
|
{
|
||||||
|
showTextInputBox = false;
|
||||||
|
strcpy(textInput, "\0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
|
@ -51,6 +51,9 @@ class ApiDescription {
|
||||||
return null;
|
return null;
|
||||||
return new ApiStruct(s);
|
return new ApiStruct(s);
|
||||||
}
|
}
|
||||||
|
getEnums() {
|
||||||
|
return this.api.enums;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.ApiDescription = ApiDescription;
|
exports.ApiDescription = ApiDescription;
|
||||||
|
|
||||||
|
@ -251,6 +254,14 @@ class GenericCodeGenerator {
|
||||||
include(name) {
|
include(name) {
|
||||||
this.line("#include <" + name + ">");
|
this.line("#include <" + name + ">");
|
||||||
}
|
}
|
||||||
|
for(indexVar, lengthVar) {
|
||||||
|
this.line(`for(int ${indexVar}; i < ${lengthVar}; i++){`);
|
||||||
|
this.indent();
|
||||||
|
const child = this.child();
|
||||||
|
this.unindent();
|
||||||
|
this.line("}");
|
||||||
|
return child;
|
||||||
|
}
|
||||||
header(guard, fun) {
|
header(guard, fun) {
|
||||||
this.line("#ifndef " + guard);
|
this.line("#ifndef " + guard);
|
||||||
this.line("#define " + guard);
|
this.line("#define " + guard);
|
||||||
|
@ -740,6 +751,9 @@ class RayLibHeader extends quickjs_1.QuickJsHeader {
|
||||||
throw new Error("Function not in API: " + name);
|
throw new Error("Function not in API: " + name);
|
||||||
this.addApiFunction(func, jsName, options);
|
this.addApiFunction(func, jsName, options);
|
||||||
}
|
}
|
||||||
|
addAllEnums() {
|
||||||
|
this.api.getEnums().forEach(x => x.values.forEach(y => this.exportGlobalConstant(y.name, y.description)));
|
||||||
|
}
|
||||||
addApiStruct(struct, destructor, options) {
|
addApiStruct(struct, destructor, options) {
|
||||||
const classId = this.definitions.jsClassId(`js_${struct.name}_class_id`);
|
const classId = this.definitions.jsClassId(`js_${struct.name}_class_id`);
|
||||||
this.registerStruct(struct.name, classId);
|
this.registerStruct(struct.name, classId);
|
||||||
|
@ -990,16 +1004,17 @@ function main() {
|
||||||
const rcameraHeader = (0, fs_1.readFileSync)("thirdparty/raylib/src/rcamera.h", "utf8");
|
const rcameraHeader = (0, fs_1.readFileSync)("thirdparty/raylib/src/rcamera.h", "utf8");
|
||||||
const cameraApi = parser.parseFunctionDefinitions(rcameraHeader);
|
const cameraApi = parser.parseFunctionDefinitions(rcameraHeader);
|
||||||
cameraApi.forEach(x => api.functions.push(x));
|
cameraApi.forEach(x => api.functions.push(x));
|
||||||
const rguiHeader = (0, fs_1.readFileSync)("thirdparty/raylib/examples/shapes/raygui.h", "utf8");
|
const rguiHeader = (0, fs_1.readFileSync)("thirdparty/raygui/src/raygui.h", "utf8");
|
||||||
const rguiFunctions = parser.parseFunctionDefinitions(rguiHeader);
|
const rguiFunctions = parser.parseFunctionDefinitions(rguiHeader);
|
||||||
const rguiEnums = parser.parseFunctionDefinitions(rguiHeader);
|
const rguiEnums = parser.parseEnums(rguiHeader);
|
||||||
//rguiApi.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
//rguiApi.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
||||||
rguiFunctions.forEach(x => api.functions.push(x));
|
rguiFunctions.forEach(x => api.functions.push(x));
|
||||||
const rlightsHeader = (0, fs_1.readFileSync)("thirdparty/raylib/examples/shaders/rlights.h", "utf8");
|
rguiEnums.forEach(x => api.enums.push(x));
|
||||||
|
const rlightsHeader = (0, fs_1.readFileSync)("include/rlights.h", "utf8");
|
||||||
const rlightsFunctions = parser.parseFunctions(rlightsHeader, true);
|
const rlightsFunctions = parser.parseFunctions(rlightsHeader, true);
|
||||||
api.functions.push(rlightsFunctions[0]);
|
api.functions.push(rlightsFunctions[0]);
|
||||||
api.functions.push(rlightsFunctions[1]);
|
api.functions.push(rlightsFunctions[1]);
|
||||||
const reasingsHeader = (0, fs_1.readFileSync)("thirdparty/raylib/examples/shapes/reasings.h", "utf8");
|
const reasingsHeader = (0, fs_1.readFileSync)("include/reasings.h", "utf8");
|
||||||
const reasingsFunctions = parser.parseFunctions(reasingsHeader);
|
const reasingsFunctions = parser.parseFunctions(reasingsHeader);
|
||||||
//reasingsFunctions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
//reasingsFunctions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
||||||
reasingsFunctions.forEach(x => api.functions.push(x));
|
reasingsFunctions.forEach(x => api.functions.push(x));
|
||||||
|
@ -1393,7 +1408,18 @@ function main() {
|
||||||
//core.addApiFunctionByName("LoadDirectoryFilesEx")
|
//core.addApiFunctionByName("LoadDirectoryFilesEx")
|
||||||
// UnloadDirectoryFiles
|
// UnloadDirectoryFiles
|
||||||
core.addApiFunctionByName("IsFileDropped");
|
core.addApiFunctionByName("IsFileDropped");
|
||||||
//core.addApiFunctionByName("LoadDroppedFiles")
|
const ldf = apiDesc.getFunction("LoadDroppedFiles");
|
||||||
|
ldf.returnType = "string[]";
|
||||||
|
core.addApiFunction(ldf, null, {
|
||||||
|
body: gen => {
|
||||||
|
gen.call("LoadDroppedFiles", [], { type: "FilePathList", name: "files" });
|
||||||
|
gen.call("JS_NewArray", ["ctx"], { type: "JSValue", name: "ret" });
|
||||||
|
const f = gen.for("i", "files.count");
|
||||||
|
f.call("JS_SetPropertyUint32", ["ctx", "ret", "i", "JS_NewString(ctx,files.paths[i])"]);
|
||||||
|
gen.call("UnloadDroppedFiles", ["files"]);
|
||||||
|
gen.returnExp("ret");
|
||||||
|
}
|
||||||
|
});
|
||||||
// UnloadDroppedFiles
|
// UnloadDroppedFiles
|
||||||
core.addApiFunctionByName("GetFileModTime");
|
core.addApiFunctionByName("GetFileModTime");
|
||||||
// Compression/encoding functionality
|
// Compression/encoding functionality
|
||||||
|
@ -1974,7 +2000,7 @@ function main() {
|
||||||
//core.addApiFunctionByName("GuiSpinner")
|
//core.addApiFunctionByName("GuiSpinner")
|
||||||
//core.addApiFunctionByName("GuiValueBox")
|
//core.addApiFunctionByName("GuiValueBox")
|
||||||
core.addApiFunctionByName("GuiTextBox");
|
core.addApiFunctionByName("GuiTextBox");
|
||||||
core.addApiFunctionByName("GuiTextBoxMulti");
|
//core.addApiFunctionByName("GuiTextBoxMulti")
|
||||||
core.addApiFunctionByName("GuiSlider");
|
core.addApiFunctionByName("GuiSlider");
|
||||||
core.addApiFunctionByName("GuiSliderBar");
|
core.addApiFunctionByName("GuiSliderBar");
|
||||||
core.addApiFunctionByName("GuiProgressBar");
|
core.addApiFunctionByName("GuiProgressBar");
|
||||||
|
@ -1997,9 +2023,6 @@ function main() {
|
||||||
//core.addApiFunctionByName("GuiGetIconData")
|
//core.addApiFunctionByName("GuiGetIconData")
|
||||||
//core.addApiFunctionByName("GuiSetIconData")
|
//core.addApiFunctionByName("GuiSetIconData")
|
||||||
core.addApiFunctionByName("GuiSetIconScale");
|
core.addApiFunctionByName("GuiSetIconScale");
|
||||||
core.addApiFunctionByName("GuiSetIconPixel");
|
|
||||||
core.addApiFunctionByName("GuiClearIconPixel");
|
|
||||||
core.addApiFunctionByName("GuiCheckIconPixel");
|
|
||||||
// module: rlights
|
// module: rlights
|
||||||
// TODO: Parse and support light struct
|
// TODO: Parse and support light struct
|
||||||
// core.addApiFunctionByName("CreateLight")
|
// core.addApiFunctionByName("CreateLight")
|
||||||
|
@ -2031,18 +2054,19 @@ function main() {
|
||||||
api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, description: x.description, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => {
|
api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, description: x.description, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => {
|
||||||
core.exportGlobalStruct("Color", x.name, x.values, x.description);
|
core.exportGlobalStruct("Color", x.name, x.values, x.description);
|
||||||
});
|
});
|
||||||
api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
core.addAllEnums();
|
||||||
api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "MouseCursor")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "MouseCursor")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "CameraMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "ShaderLocationIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "CameraMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "ShaderUniformDataType")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "ShaderLocationIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
api.enums.find(x => x.name === "MaterialMapIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description));
|
// api.enums.find(x => x.name === "ShaderUniformDataType")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
|
// api.enums.find(x => x.name === "MaterialMapIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description))
|
||||||
core.exportGlobalConstant("MATERIAL_MAP_DIFFUSE", "Albedo material (same as: MATERIAL_MAP_DIFFUSE");
|
core.exportGlobalConstant("MATERIAL_MAP_DIFFUSE", "Albedo material (same as: MATERIAL_MAP_DIFFUSE");
|
||||||
core.exportGlobalConstant("MATERIAL_MAP_SPECULAR", "Metalness material (same as: MATERIAL_MAP_SPECULAR)");
|
core.exportGlobalConstant("MATERIAL_MAP_SPECULAR", "Metalness material (same as: MATERIAL_MAP_SPECULAR)");
|
||||||
core.writeTo("src/bindings/js_raylib_core.h");
|
core.writeTo("src/bindings/js_raylib_core.h");
|
||||||
|
|
|
@ -0,0 +1,263 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* reasings - raylib easings library, based on Robert Penner library
|
||||||
|
*
|
||||||
|
* Useful easing functions for values animation
|
||||||
|
*
|
||||||
|
* This header uses:
|
||||||
|
* #define REASINGS_STATIC_INLINE // Inlines all functions code, so it runs faster.
|
||||||
|
* // This requires lots of memory on system.
|
||||||
|
* How to use:
|
||||||
|
* The four inputs t,b,c,d are defined as follows:
|
||||||
|
* t = current time (in any unit measure, but same unit as duration)
|
||||||
|
* b = starting value to interpolate
|
||||||
|
* c = the total change in value of b that needs to occur
|
||||||
|
* d = total time it should take to complete (duration)
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* int currentTime = 0;
|
||||||
|
* int duration = 100;
|
||||||
|
* float startPositionX = 0.0f;
|
||||||
|
* float finalPositionX = 30.0f;
|
||||||
|
* float currentPositionX = startPositionX;
|
||||||
|
*
|
||||||
|
* while (currentPositionX < finalPositionX)
|
||||||
|
* {
|
||||||
|
* currentPositionX = EaseSineIn(currentTime, startPositionX, finalPositionX - startPositionX, duration);
|
||||||
|
* currentTime++;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* A port of Robert Penner's easing equations to C (http://robertpenner.com/easing/)
|
||||||
|
*
|
||||||
|
* Robert Penner License
|
||||||
|
* ---------------------------------------------------------------------------------
|
||||||
|
* Open source under the BSD License.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2001 Robert Penner. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* - Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* - Neither the name of the author nor the names of contributors may be used
|
||||||
|
* to endorse or promote products derived from this software without specific
|
||||||
|
* prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
* ---------------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||||
|
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||||
|
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||||
|
* in the product documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||||
|
* as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef REASINGS_H
|
||||||
|
#define REASINGS_H
|
||||||
|
|
||||||
|
#define REASINGS_STATIC_INLINE // NOTE: By default, compile functions as static inline
|
||||||
|
|
||||||
|
#if defined(REASINGS_STATIC_INLINE)
|
||||||
|
#define EASEDEF static inline
|
||||||
|
#else
|
||||||
|
#define EASEDEF extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <math.h> // Required for: sinf(), cosf(), sqrtf(), powf()
|
||||||
|
|
||||||
|
#ifndef PI
|
||||||
|
#define PI 3.14159265358979323846f //Required as PI is not always defined in math.h
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Linear Easing functions
|
||||||
|
EASEDEF float EaseLinearNone(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear
|
||||||
|
EASEDEF float EaseLinearIn(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear In
|
||||||
|
EASEDEF float EaseLinearOut(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear Out
|
||||||
|
EASEDEF float EaseLinearInOut(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear In Out
|
||||||
|
|
||||||
|
// Sine Easing functions
|
||||||
|
EASEDEF float EaseSineIn(float t, float b, float c, float d) { return (-c*cosf(t/d*(PI/2.0f)) + c + b); } // Ease: Sine In
|
||||||
|
EASEDEF float EaseSineOut(float t, float b, float c, float d) { return (c*sinf(t/d*(PI/2.0f)) + b); } // Ease: Sine Out
|
||||||
|
EASEDEF float EaseSineInOut(float t, float b, float c, float d) { return (-c/2.0f*(cosf(PI*t/d) - 1.0f) + b); } // Ease: Sine In Out
|
||||||
|
|
||||||
|
// Circular Easing functions
|
||||||
|
EASEDEF float EaseCircIn(float t, float b, float c, float d) { t /= d; return (-c*(sqrtf(1.0f - t*t) - 1.0f) + b); } // Ease: Circular In
|
||||||
|
EASEDEF float EaseCircOut(float t, float b, float c, float d) { t = t/d - 1.0f; return (c*sqrtf(1.0f - t*t) + b); } // Ease: Circular Out
|
||||||
|
EASEDEF float EaseCircInOut(float t, float b, float c, float d) // Ease: Circular In Out
|
||||||
|
{
|
||||||
|
if ((t/=d/2.0f) < 1.0f) return (-c/2.0f*(sqrtf(1.0f - t*t) - 1.0f) + b);
|
||||||
|
t -= 2.0f; return (c/2.0f*(sqrtf(1.0f - t*t) + 1.0f) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cubic Easing functions
|
||||||
|
EASEDEF float EaseCubicIn(float t, float b, float c, float d) { t /= d; return (c*t*t*t + b); } // Ease: Cubic In
|
||||||
|
EASEDEF float EaseCubicOut(float t, float b, float c, float d) { t = t/d - 1.0f; return (c*(t*t*t + 1.0f) + b); } // Ease: Cubic Out
|
||||||
|
EASEDEF float EaseCubicInOut(float t, float b, float c, float d) // Ease: Cubic In Out
|
||||||
|
{
|
||||||
|
if ((t/=d/2.0f) < 1.0f) return (c/2.0f*t*t*t + b);
|
||||||
|
t -= 2.0f; return (c/2.0f*(t*t*t + 2.0f) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quadratic Easing functions
|
||||||
|
EASEDEF float EaseQuadIn(float t, float b, float c, float d) { t /= d; return (c*t*t + b); } // Ease: Quadratic In
|
||||||
|
EASEDEF float EaseQuadOut(float t, float b, float c, float d) { t /= d; return (-c*t*(t - 2.0f) + b); } // Ease: Quadratic Out
|
||||||
|
EASEDEF float EaseQuadInOut(float t, float b, float c, float d) // Ease: Quadratic In Out
|
||||||
|
{
|
||||||
|
if ((t/=d/2) < 1) return (((c/2)*(t*t)) + b);
|
||||||
|
return (-c/2.0f*(((t - 1.0f)*(t - 3.0f)) - 1.0f) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exponential Easing functions
|
||||||
|
EASEDEF float EaseExpoIn(float t, float b, float c, float d) { return (t == 0.0f) ? b : (c*powf(2.0f, 10.0f*(t/d - 1.0f)) + b); } // Ease: Exponential In
|
||||||
|
EASEDEF float EaseExpoOut(float t, float b, float c, float d) { return (t == d) ? (b + c) : (c*(-powf(2.0f, -10.0f*t/d) + 1.0f) + b); } // Ease: Exponential Out
|
||||||
|
EASEDEF float EaseExpoInOut(float t, float b, float c, float d) // Ease: Exponential In Out
|
||||||
|
{
|
||||||
|
if (t == 0.0f) return b;
|
||||||
|
if (t == d) return (b + c);
|
||||||
|
if ((t/=d/2.0f) < 1.0f) return (c/2.0f*powf(2.0f, 10.0f*(t - 1.0f)) + b);
|
||||||
|
|
||||||
|
return (c/2.0f*(-powf(2.0f, -10.0f*(t - 1.0f)) + 2.0f) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Back Easing functions
|
||||||
|
EASEDEF float EaseBackIn(float t, float b, float c, float d) // Ease: Back In
|
||||||
|
{
|
||||||
|
float s = 1.70158f;
|
||||||
|
float postFix = t/=d;
|
||||||
|
return (c*(postFix)*t*((s + 1.0f)*t - s) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
EASEDEF float EaseBackOut(float t, float b, float c, float d) // Ease: Back Out
|
||||||
|
{
|
||||||
|
float s = 1.70158f;
|
||||||
|
t = t/d - 1.0f;
|
||||||
|
return (c*(t*t*((s + 1.0f)*t + s) + 1.0f) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
EASEDEF float EaseBackInOut(float t, float b, float c, float d) // Ease: Back In Out
|
||||||
|
{
|
||||||
|
float s = 1.70158f;
|
||||||
|
if ((t/=d/2.0f) < 1.0f)
|
||||||
|
{
|
||||||
|
s *= 1.525f;
|
||||||
|
return (c/2.0f*(t*t*((s + 1.0f)*t - s)) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
float postFix = t-=2.0f;
|
||||||
|
s *= 1.525f;
|
||||||
|
return (c/2.0f*((postFix)*t*((s + 1.0f)*t + s) + 2.0f) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bounce Easing functions
|
||||||
|
EASEDEF float EaseBounceOut(float t, float b, float c, float d) // Ease: Bounce Out
|
||||||
|
{
|
||||||
|
if ((t/=d) < (1.0f/2.75f))
|
||||||
|
{
|
||||||
|
return (c*(7.5625f*t*t) + b);
|
||||||
|
}
|
||||||
|
else if (t < (2.0f/2.75f))
|
||||||
|
{
|
||||||
|
float postFix = t-=(1.5f/2.75f);
|
||||||
|
return (c*(7.5625f*(postFix)*t + 0.75f) + b);
|
||||||
|
}
|
||||||
|
else if (t < (2.5/2.75))
|
||||||
|
{
|
||||||
|
float postFix = t-=(2.25f/2.75f);
|
||||||
|
return (c*(7.5625f*(postFix)*t + 0.9375f) + b);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float postFix = t-=(2.625f/2.75f);
|
||||||
|
return (c*(7.5625f*(postFix)*t + 0.984375f) + b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EASEDEF float EaseBounceIn(float t, float b, float c, float d) { return (c - EaseBounceOut(d - t, 0.0f, c, d) + b); } // Ease: Bounce In
|
||||||
|
EASEDEF float EaseBounceInOut(float t, float b, float c, float d) // Ease: Bounce In Out
|
||||||
|
{
|
||||||
|
if (t < d/2.0f) return (EaseBounceIn(t*2.0f, 0.0f, c, d)*0.5f + b);
|
||||||
|
else return (EaseBounceOut(t*2.0f - d, 0.0f, c, d)*0.5f + c*0.5f + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elastic Easing functions
|
||||||
|
EASEDEF float EaseElasticIn(float t, float b, float c, float d) // Ease: Elastic In
|
||||||
|
{
|
||||||
|
if (t == 0.0f) return b;
|
||||||
|
if ((t/=d) == 1.0f) return (b + c);
|
||||||
|
|
||||||
|
float p = d*0.3f;
|
||||||
|
float a = c;
|
||||||
|
float s = p/4.0f;
|
||||||
|
float postFix = a*powf(2.0f, 10.0f*(t-=1.0f));
|
||||||
|
|
||||||
|
return (-(postFix*sinf((t*d-s)*(2.0f*PI)/p )) + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
EASEDEF float EaseElasticOut(float t, float b, float c, float d) // Ease: Elastic Out
|
||||||
|
{
|
||||||
|
if (t == 0.0f) return b;
|
||||||
|
if ((t/=d) == 1.0f) return (b + c);
|
||||||
|
|
||||||
|
float p = d*0.3f;
|
||||||
|
float a = c;
|
||||||
|
float s = p/4.0f;
|
||||||
|
|
||||||
|
return (a*powf(2.0f,-10.0f*t)*sinf((t*d-s)*(2.0f*PI)/p) + c + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
EASEDEF float EaseElasticInOut(float t, float b, float c, float d) // Ease: Elastic In Out
|
||||||
|
{
|
||||||
|
if (t == 0.0f) return b;
|
||||||
|
if ((t/=d/2.0f) == 2.0f) return (b + c);
|
||||||
|
|
||||||
|
float p = d*(0.3f*1.5f);
|
||||||
|
float a = c;
|
||||||
|
float s = p/4.0f;
|
||||||
|
|
||||||
|
if (t < 1.0f)
|
||||||
|
{
|
||||||
|
float postFix = a*powf(2.0f, 10.0f*(t-=1.0f));
|
||||||
|
return -0.5f*(postFix*sinf((t*d-s)*(2.0f*PI)/p)) + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
float postFix = a*powf(2.0f, -10.0f*(t-=1.0f));
|
||||||
|
|
||||||
|
return (postFix*sinf((t*d-s)*(2.0f*PI)/p)*0.5f + c + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // REASINGS_H
|
|
@ -0,0 +1,170 @@
|
||||||
|
/**********************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib.lights - Some useful functions to deal with lights data
|
||||||
|
*
|
||||||
|
* CONFIGURATION:
|
||||||
|
*
|
||||||
|
* #define RLIGHTS_IMPLEMENTATION
|
||||||
|
* Generates the implementation of the library into the included file.
|
||||||
|
* If not defined, the library is in header only mode and can be included in other headers
|
||||||
|
* or source files without problems. But only ONE file should hold the implementation.
|
||||||
|
*
|
||||||
|
* LICENSE: zlib/libpng
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2023 Victor Fisac (@victorfisac) and Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||||
|
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||||
|
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||||
|
* in the product documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||||
|
* as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef RLIGHTS_H
|
||||||
|
#define RLIGHTS_H
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#define MAX_LIGHTS 4 // Max dynamic lights supported by shader
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Light data
|
||||||
|
typedef struct {
|
||||||
|
int type;
|
||||||
|
bool enabled;
|
||||||
|
Vector3 position;
|
||||||
|
Vector3 target;
|
||||||
|
Color color;
|
||||||
|
float attenuation;
|
||||||
|
|
||||||
|
// Shader locations
|
||||||
|
int enabledLoc;
|
||||||
|
int typeLoc;
|
||||||
|
int positionLoc;
|
||||||
|
int targetLoc;
|
||||||
|
int colorLoc;
|
||||||
|
int attenuationLoc;
|
||||||
|
} Light;
|
||||||
|
|
||||||
|
// Light type
|
||||||
|
typedef enum {
|
||||||
|
LIGHT_DIRECTIONAL = 0,
|
||||||
|
LIGHT_POINT
|
||||||
|
} LightType;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader); // Create a light and get shader locations
|
||||||
|
void UpdateLightValues(Shader shader, Light light); // Send light properties to shader
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // RLIGHTS_H
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************************
|
||||||
|
*
|
||||||
|
* RLIGHTS IMPLEMENTATION
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(RLIGHTS_IMPLEMENTATION)
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// ...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// ...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static int lightsCount = 0; // Current amount of created lights
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module specific Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// ...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Create a light and get shader locations
|
||||||
|
Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader)
|
||||||
|
{
|
||||||
|
Light light = { 0 };
|
||||||
|
|
||||||
|
if (lightsCount < MAX_LIGHTS)
|
||||||
|
{
|
||||||
|
light.enabled = true;
|
||||||
|
light.type = type;
|
||||||
|
light.position = position;
|
||||||
|
light.target = target;
|
||||||
|
light.color = color;
|
||||||
|
|
||||||
|
// NOTE: Lighting shader naming must be the provided ones
|
||||||
|
light.enabledLoc = GetShaderLocation(shader, TextFormat("lights[%i].enabled", lightsCount));
|
||||||
|
light.typeLoc = GetShaderLocation(shader, TextFormat("lights[%i].type", lightsCount));
|
||||||
|
light.positionLoc = GetShaderLocation(shader, TextFormat("lights[%i].position", lightsCount));
|
||||||
|
light.targetLoc = GetShaderLocation(shader, TextFormat("lights[%i].target", lightsCount));
|
||||||
|
light.colorLoc = GetShaderLocation(shader, TextFormat("lights[%i].color", lightsCount));
|
||||||
|
|
||||||
|
UpdateLightValues(shader, light);
|
||||||
|
|
||||||
|
lightsCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return light;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send light properties to shader
|
||||||
|
// NOTE: Light shader locations should be available
|
||||||
|
void UpdateLightValues(Shader shader, Light light)
|
||||||
|
{
|
||||||
|
// Send to shader light enabled state and type
|
||||||
|
SetShaderValue(shader, light.enabledLoc, &light.enabled, SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(shader, light.typeLoc, &light.type, SHADER_UNIFORM_INT);
|
||||||
|
|
||||||
|
// Send to shader light position values
|
||||||
|
float position[3] = { light.position.x, light.position.y, light.position.z };
|
||||||
|
SetShaderValue(shader, light.positionLoc, position, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
|
// Send to shader light target position values
|
||||||
|
float target[3] = { light.target.x, light.target.y, light.target.z };
|
||||||
|
SetShaderValue(shader, light.targetLoc, target, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
|
// Send to shader light color values
|
||||||
|
float color[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255,
|
||||||
|
(float)light.color.b/(float)255, (float)light.color.a/(float)255 };
|
||||||
|
SetShaderValue(shader, light.colorLoc, color, SHADER_UNIFORM_VEC4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // RLIGHTS_IMPLEMENTATION
|
File diff suppressed because it is too large
Load Diff
|
@ -1 +1 @@
|
||||||
Subproject commit 83e6cae9e433bc3e40c491513a5853eed30be0db
|
Subproject commit aa81c167f10707ea173ea1190eda18e57d841b8f
|
Loading…
Reference in New Issue