Blender V4.3
wm_gizmo_group_type.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdio>
10
11#include "BLI_ghash.h"
12#include "BLI_utildefines.h"
13
14#include "MEM_guardedalloc.h"
15
16#include "RNA_access.hh"
17#include "RNA_define.hh"
18#include "RNA_prototypes.hh"
19
20#include "WM_types.hh"
21
22/* Own includes. */
23#include "wm_gizmo_intern.hh"
24#include "wm_gizmo_wmapi.hh"
25
26/* -------------------------------------------------------------------- */
33
34wmGizmoGroupType *WM_gizmogrouptype_find(const char *idname, bool quiet)
35{
36 if (idname[0]) {
37 wmGizmoGroupType *gzgt;
38
39 gzgt = static_cast<wmGizmoGroupType *>(BLI_ghash_lookup(global_gizmogrouptype_hash, idname));
40 if (gzgt) {
41 return gzgt;
42 }
43
44 if (!quiet) {
45 printf("search for unknown gizmo group '%s'\n", idname);
46 }
47 }
48 else {
49 if (!quiet) {
50 printf("search for empty gizmo group\n");
51 }
52 }
53
54 return nullptr;
55}
56
61
63{
64 wmGizmoGroupType *gzgt = static_cast<wmGizmoGroupType *>(
65 MEM_callocN(sizeof(wmGizmoGroupType), "gizmogrouptype"));
66 gzgt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_GizmoGroupProperties);
67#if 0
68 /* Set the default i18n context now, so that opfunc can redefine it if needed! */
71#endif
72 return gzgt;
73}
75{
76 BLI_assert(gzgt->name != nullptr);
77 BLI_assert(gzgt->idname != nullptr);
78
80
82
83 /* If not set, use default. */
84 if (gzgt->setup_keymap == nullptr) {
85 if (gzgt->flag & WM_GIZMOGROUPTYPE_SELECT) {
87 }
88 else {
90 }
91 }
92
94}
95
97{
99 wtfunc(gzgt);
101 return gzgt;
102}
103
105 void *userdata)
106{
108 wtfunc(gzgt, userdata);
110 return gzgt;
111}
112
114 void (*wtfunc)(wmGizmoGroupType *))
115{
117
118 gzgt->gzmap_params.spaceid = gzmap_type->spaceid;
119 gzgt->gzmap_params.regionid = gzmap_type->regionid;
120
121 return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt);
122}
123
128{
129 /* Python gizmo group, allocates its own string. */
130 if (gzgt->rna_ext.srna) {
131 MEM_freeN((void *)gzgt->idname);
132 }
133
134 MEM_freeN(gzgt);
135}
136
138{
139 BLI_assert(gzgt == WM_gizmogrouptype_find(gzgt->idname, false));
140
141 BLI_ghash_remove(global_gizmogrouptype_hash, gzgt->idname, nullptr, nullptr);
142
144
145 /* XXX, TODO: update the world! */
146}
147
148bool WM_gizmo_group_type_free(const char *idname)
149{
150 wmGizmoGroupType *gzgt = static_cast<wmGizmoGroupType *>(
152
153 if (gzgt == nullptr) {
154 return false;
155 }
156
158
159 return true;
160}
161
166
173
175{
176 /* Reserve size is set based on blender default setup. */
177 global_gizmogrouptype_hash = BLI_ghash_str_new_ex("wm_gizmogrouptype_init gh", 128);
178}
179
#define BLI_assert(a)
Definition BLI_assert.h:50
void(* GHashValFreeFP)(void *val)
Definition BLI_ghash.h:39
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:787
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:731
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.c:707
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:860
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition BLI_ghash.c:895
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
Read Guarded memory(de)allocation.
@ WM_GIZMOMAPTYPE_KEYMAP_INIT
@ WM_GIZMOGROUPTYPE_SELECT
#define printf
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
BlenderRNA BLENDER_RNA
StructRNA * srna
Definition RNA_types.hh:780
wmGizmoGroupFnSetupKeymap setup_keymap
const char * idname
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
eWM_GizmoFlagMapTypeUpdateFlag type_update_flag
ExtensionRNA rna_ext
const char * translation_context
Definition WM_types.hh:994
StructRNA * srna
Definition WM_types.hh:1080
wmOperatorType * ot
Definition wm_files.cc:4125
wmKeyMap * WM_gizmogroup_setup_keymap_generic(const wmGizmoGroupType *, wmKeyConfig *kc)
wmGizmoGroupTypeRef * WM_gizmomaptype_group_link_ptr(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt)
wmKeyMap * WM_gizmogroup_setup_keymap_generic_select(const wmGizmoGroupType *, wmKeyConfig *kc)
void wm_gizmogrouptype_init()
wmGizmoGroupType * WM_gizmogrouptype_append(void(*wtfunc)(wmGizmoGroupType *))
static void wm_gizmogrouptype_ghash_free_cb(wmGizmoGroupType *gzgt)
void WM_gizmogrouptype_iter(GHashIterator *ghi)
static void gizmogrouptype_free(wmGizmoGroupType *gzgt)
wmGizmoGroupType * WM_gizmogrouptype_append_ptr(void(*wtfunc)(wmGizmoGroupType *, void *), void *userdata)
static void wm_gizmogrouptype_append__end(wmGizmoGroupType *gzgt)
void WM_gizmo_group_type_free_ptr(wmGizmoGroupType *gzgt)
void wm_gizmogrouptype_free()
wmGizmoGroupTypeRef * WM_gizmogrouptype_append_and_link(wmGizmoMapType *gzmap_type, void(*wtfunc)(wmGizmoGroupType *))
bool WM_gizmo_group_type_free(const char *idname)
wmGizmoGroupType * WM_gizmogrouptype_find(const char *idname, bool quiet)
static wmGizmoGroupType * wm_gizmogrouptype_append__begin()
static GHash * global_gizmogrouptype_hash