Skip to content

Commit

Permalink
UPBGE: Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
youle31 committed Jan 8, 2025
1 parent e93fc1f commit 28296cf
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 13 deletions.
10 changes: 2 additions & 8 deletions source/blender/blenkernel/BKE_sca.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@

#pragma once

#include "BKE_lib_query.hh"

/** \file
* \ingroup bke
*/

#ifdef __cplusplus
extern "C" {
#endif

struct Main;
struct Object;
struct bSensor;
Expand Down Expand Up @@ -108,7 +106,3 @@ void BKE_sca_controllers_id_loop(struct ListBase *contlist,
SCAControllerIDFunc func,
void *userdata);
void BKE_sca_actuators_id_loop(struct ListBase *atclist, SCAActuatorIDFunc func, void *userdata);

#ifdef __cplusplus
}
#endif
4 changes: 1 addition & 3 deletions source/blender/draw/intern/draw_manager_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3271,10 +3271,8 @@ void DRW_gpu_context_activate(bool drw_state)
/****************UPBGE**************************/

#include "BKE_colortools.hh"
#include "BLF_api.hh"
#include "BLI_link_utils.h"
#include "GPU_immediate.hh"
#include "GPU_matrix.hh"
#include "BLI_linklist.h"
#include "IMB_colormanagement.hh"

/*--UPBGE Viewport Debug Drawing --*/
Expand Down
112 changes: 112 additions & 0 deletions source/blender/editors/interface/templates/interface_templates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* \ingroup edinterface
*/

#include "BKE_sca.hh"
#include "BKE_screen.hh"

#include "BLI_string_ref.hh"
Expand Down Expand Up @@ -312,3 +313,114 @@ void uiTemplateFileSelectPath(uiLayout *layout, bContext *C, FileSelectParams *p
}

/** \} */

static void handle_layer_buttons(bContext *C, void *arg1, void *arg2)
{
uiBut *but = static_cast<uiBut *>(arg1);
const int cur = POINTER_AS_INT(arg2);
wmWindow *win = CTX_wm_window(C);
const bool shift = win->eventstate->modifier & KM_SHIFT;

if (!shift) {
const int tot = RNA_property_array_length(&but->rnapoin, but->rnaprop);

/* Normally clicking only selects one layer */
RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, cur, true);
for (int i = 0; i < tot; i++) {
if (i != cur) {
RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, i, false);
}
}
}

/* view3d layer change should update depsgraph (invisible object changed maybe) */
/* see `view3d_header.cc` */
}

void uiTemplateGameStates(uiLayout *layout,
PointerRNA *ptr,
const char *propname,
PointerRNA *used_ptr,
const char *used_propname,
int active_state)
{
uiLayout *uRow, *uCol;
PropertyRNA *prop, *used_prop = NULL;
int groups, cols, states;
int group, col, state, row;
int cols_per_group = 5;
Object *ob = (Object *)ptr->owner_id;

prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
RNA_warning("states property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}

/* the number of states determines the way we group them
* - we want 2 rows only (for now)
* - the number of columns (cols) is the total number of buttons per row
* the 'remainder' is added to this, as it will be ok to have first row slightly wider if need
*be
* - for now, only split into groups if group will have at least 5 items
*/
states = RNA_property_array_length(ptr, prop);
cols = (states / 2) + (states % 2);
groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group);

if (used_ptr && used_propname) {
used_prop = RNA_struct_find_property(used_ptr, used_propname);
if (!used_prop) {
RNA_warning("used layers property not found: %s.%s",
RNA_struct_identifier(ptr->type),
used_propname);
return;
}

if (RNA_property_array_length(used_ptr, used_prop) < states)
used_prop = NULL;
}

/* layers are laid out going across rows, with the columns being divided into groups */

for (group = 0; group < groups; group++) {
uCol = uiLayoutColumn(layout, true);

for (row = 0; row < 2; row++) {
uiBlock *block;
uiBut *but;

uRow = uiLayoutRow(uCol, true);
block = uiLayoutGetBlock(uRow);
state = groups * cols_per_group * row + cols_per_group * group;

/* add layers as toggle buts */
for (col = 0; (col < cols_per_group) && (state < states); col++, state++) {
int icon = 0;
int butlay = 1 << state;

if (active_state & butlay)
icon = ICON_LAYER_ACTIVE;
else if (used_prop && RNA_property_boolean_get_index(used_ptr, used_prop, state))
icon = ICON_LAYER_USED;

but = uiDefIconButR_prop(block,
UI_BTYPE_ICON_TOGGLE,
0,
icon,
0,
0,
UI_UNIT_X / 2,
UI_UNIT_Y / 2,
ptr,
prop,
state,
0,
0,
BKE_sca_get_name_state(ob, state));
UI_but_func_set(but, handle_layer_buttons, but, POINTER_FROM_INT(state));
but->type = UI_BTYPE_TOGGLE;
}
}
}
}
2 changes: 1 addition & 1 deletion source/blender/nodes/NOD_static_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ DefNode(ShaderNode, SH_NODE_WAVELENGTH, 0, Wave
DefNode(ShaderNode, SH_NODE_WIREFRAME, def_sh_tex_wireframe, Wireframe)

/* UPBGE*/
DefNode(ShaderNode, SH_NODE_SPRITES_ANIMATION, 0, SpritesAnimation, "Sprites Animation", "")
DefNode(ShaderNode, SH_NODE_SPRITES_ANIMATION, 0, SpritesAnimation)

/* NOTE: #OutputFile node has special RNA setup function called in `rna_nodetree.cc`. */
DefNode(CompositorNode, CMP_NODE_ALPHAOVER, def_cmp_alpha_over, AlphaOver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void register_node_type_sh_sprites_animation()
static blender::bke::bNodeType ntype;

sh_fn_node_type_base(
&ntype, SH_NODE_SPRITES_ANIMATION, "Sprites Animation", NODE_CLASS_SHADER);
&ntype, SH_NODE_SPRITES_ANIMATION, NODE_CLASS_SHADER);
ntype.declare = file_ns::node_declare;
ntype.add_ui_poll = object_eevee_shader_nodes_poll;
ntype.gpu_fn = file_ns::gpu_shader_sprites_animation;
Expand Down

0 comments on commit 28296cf

Please sign in to comment.