Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
mundusnine committed Oct 3, 2023
1 parent 594a36c commit dced44b
Show file tree
Hide file tree
Showing 16 changed files with 5,147 additions and 17 deletions.
12 changes: 10 additions & 2 deletions Libraries/ServiceProviders/raylib/RaylibGfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@
#include "enginedefs.h"

#include <assert.h>

static int isBegin = 0;
void raylib_begin(int window){
assert(isBegin ==0 && "End before you begin.");
isBegin = 1;
BeginDrawing();
}
void raylib_end(int window){
assert(isBegin == 1 && "Begin before you end.");
isBegin = 0;
EndDrawing();
}

static int isBegin3D = 0;
void raylib_begin3D(Camera cam){
assert(isBegin3D ==0 && "End before you begin.");
isBegin3D = 1;
BeginMode3D(cam);
}

void raylib_end3D(){
assert(isBegin3D ==1 && "Begin before you end.");
isBegin3D = 0;
EndMode3D();
}

Expand Down
44 changes: 42 additions & 2 deletions Libraries/ServiceProviders/raylib/RaylibUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

#include "rlImGui.h"
#include "imgui.h"
#include "imgui_internal.h"

#include <stdio.h>
#include <stdarg.h>

static int isBegin = 0;
void rl_begin(void){
assert(!isBegin && "End before you begin");
rlImGuiBegin();
isBegin = 1;
// bool open = true;
// ImGui::ShowDemoWindow(&open);
}
void rl_end(void){
assert(isBegin && "Begin before you end");
Expand All @@ -35,6 +39,20 @@ void rl_window_end(void){
ImGui::End();
}

void rl_popup_open(const char* str_id){
ImGui::OpenPopup(str_id);
}
void rl_popup_close(void){
ImGui::CloseCurrentPopup();
}
int rl_popup_begin(const char* str_id, int flags){
return (int)ImGui::BeginPopup(str_id,flags);
}

void rl_popup_end(void){
ImGui::EndPopup();
}

void rl_elem_set_pos(float x, float y){
if(x >= 0){
ImGui::SetCursorPosX(x);
Expand All @@ -43,6 +61,11 @@ void rl_elem_set_pos(float x, float y){
ImGui::SetCursorPosY(y);
}
}
Vector2 rl_elem_get_pos(void){
ImVec2 pos = ImGui::GetCursorPos();
return {.x=pos.x,.y=pos.y};
}

void rl_elem_same_line(void){
ImGui::SameLine();
}
Expand All @@ -63,14 +86,24 @@ void rl_image(UID image_id,float w, float h){
ImGui::Image((ImTextureID)image, ImVec2(width, height));
}

void rl_text(char* fmt,float fontSize,...){
Vector2 rl_text(char* fmt,float fontSize,...){
fontSize = fontSize >0 ? fontSize : ImGui::GetFontSize();
ImGui::SetWindowFontScale(fontSize/ImGui::GetFontSize());
va_list args;
va_start(args, fmt);
ImGui::TextV(fmt,args);
const char* text, *text_end;
ImFormatStringToTempBufferV(&text, &text_end, fmt, args);
ImVec2 item_size = ImGui::CalcTextSize(text,text_end,false);
va_end(args);
ImGui::TextUnformatted(text);
ImGui::SetWindowFontScale(1.0f);
Vector2 out = {.x= item_size.x,.y=item_size.y};

return out;
}

int rl_text_input(const char* label,char* text_buffer,size_t buffer_size){
return (int)ImGui::InputText(label,text_buffer,buffer_size);
}

int rl_table_begin(const char* id, int num_columns){
Expand Down Expand Up @@ -102,15 +135,22 @@ void create_ui_provider(void* engine){
ui.window_set_pos = rl_window_set_pos;
ui.window_set_size = rl_window_set_size;

ui.popup_open = rl_popup_open;
ui.popup_close = rl_popup_close;
ui.popup_begin = rl_popup_begin;
ui.popup_end = rl_popup_end;

ui.table_begin = rl_table_begin;
ui.table_end = rl_table_end;
ui.table_next_column = rl_table_next_column;

ui.elem_set_pos = rl_elem_set_pos;
ui.elem_get_pos = rl_elem_get_pos;
ui.elem_same_line = rl_elem_same_line;

ui.image = rl_image;
ui.text = rl_text;
ui.text_input = rl_text_input;
ui.button = rl_button;

ui.private_funcs[2] = rl_shutdown;
Expand Down
3 changes: 2 additions & 1 deletion Libraries/kfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ project.addFiles(
'imgui/imgui.h',
'imgui/imgui_draw.cpp',
'imgui/imgui_tables.cpp',
'imgui/imgui_widgets.cpp'
'imgui/imgui_widgets.cpp',
'imgui/imgui_demo.cpp',
);

if(Options[0] === "raylib"){
Expand Down
2 changes: 1 addition & 1 deletion Libraries/raylib
Submodule raylib updated 103 files
8 changes: 7 additions & 1 deletion Sources/IUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ typedef struct IUi {
void (*window_set_size)(float w,float h);
int (*window_begin)(const char* name,int* open,int flags);
void(*window_end)(void);
void (*popup_open)(const char* str_id);
void (*popup_close)(void);
int (*popup_begin)(const char* str_id,int flags);
void (*popup_end)(void);
void (*elem_set_pos)(float x,float y);
Vector2 (*elem_get_pos)(void);
void (*elem_same_line)(void);
int (*table_begin)(const char* name,int num_colums);
void (*table_next_column)(void);
void (*table_end)();
void (*image)(UID image_id, float w, float h);
void (*text)(char* fmt,float fontSize,...);
Vector2 (*text)(char* fmt,float fontSize,...);
int (*text_input)(const char* label,char* text_buffer,size_t buffer_size);
int (*button)(const char* label,float w, float h);
void (*private_funcs[MAX_PRIVATE_FUNCS])(void* data);
} IUi;
Expand Down
3 changes: 3 additions & 0 deletions Sources/WorldService.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static Entity entities[MAX_ENTITIES] = {0};
UID world_create_entity(Vector3 position,Vector3 scale,Vector3 rotation){
Entity* ent = &entities[num_entities];
memset(ent,0,sizeof(Entity));
ent->active = 1;
memset(ent->components,0,sizeof(Component) * MAX_COMPONENTS);
ent->transform = MatrixTranslate(position.x,position.y,position.z);
ent->transform = MatrixMultiply(ent->transform,MatrixScale(scale.x,scale.y,scale.z));
Expand All @@ -36,6 +37,7 @@ void world_update(void* data){
Component* comp;
for(int i =0; i < num_entities;++i){
Entity* ent = &entities[i];
if(!ent->active) continue;
for(int y = 0; y < MAX_COMPONENTS && ent->components[y] != NULL;++y){
comp = ent->components[y];
if(comp->type == Updateable || comp->type == Both){
Expand All @@ -51,6 +53,7 @@ void world_render(void* data){
Component* comp;
for(int i =0; i < num_entities;++i){
Entity* ent = &entities[i];
if(!ent->active) continue;
for(int y = 0; y < MAX_COMPONENTS && ent->components[y] != NULL;++y){
comp = ent->components[y];
if(comp->type == Renderable || comp->type == Both){
Expand Down
3 changes: 2 additions & 1 deletion Sources/enginedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#else
#include "raylib.h"
#endif

#include <stdlib.h>
#include <stdint.h>

typedef struct KRect{
Expand Down Expand Up @@ -52,6 +52,7 @@ struct Component{
void (*funcs[2])(Entity* ent);
};
struct Entity {
uint8_t active;
Matrix transform;
Component* components[MAX_COMPONENTS];
UID assets[NUM_ASSETS_TYPES];
Expand Down
20 changes: 20 additions & 0 deletions examples/editor/Libraries/cJSON/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Loading

0 comments on commit dced44b

Please sign in to comment.