Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / object / object_lod.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) Blender Foundation
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/object/object_lod.c
29  *  \ingroup edobj
30  */
31
32 #include "DNA_object_types.h"
33
34 #include "BKE_context.h"
35
36 #include "WM_api.h"
37 #include "WM_types.h"
38
39 #include "RNA_access.h"
40 #include "RNA_define.h"
41
42 #include "ED_screen.h"
43 #include "ED_object.h"
44
45 #ifdef WITH_GAMEENGINE
46 #  include "BKE_object.h"
47
48 #  include "RNA_enum_types.h"
49 #endif
50
51 #include "object_intern.h"
52
53 static int object_lod_add_exec(bContext *C, wmOperator *UNUSED(op))
54 {
55         Object *ob = ED_object_context(C);
56
57 #ifdef WITH_GAMEENGINE
58         BKE_object_lod_add(ob);
59 #else
60         (void)ob;
61 #endif
62
63         return OPERATOR_FINISHED;
64 }
65
66 void OBJECT_OT_lod_add(wmOperatorType *ot)
67 {
68         /* identifiers */
69         ot->name = "Add Level of Detail";
70         ot->description = "Add a level of detail to this object";
71         ot->idname = "OBJECT_OT_lod_add";
72
73         /* api callbacks */
74         ot->exec = object_lod_add_exec;
75         ot->poll = ED_operator_object_active;
76
77         /* flags */
78         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
79 }
80
81 static int object_lod_remove_exec(bContext *C, wmOperator *op)
82 {
83         Object *ob = ED_object_context(C);
84         int index = RNA_int_get(op->ptr, "index");
85
86 #ifdef WITH_GAMEENGINE
87         if (!BKE_object_lod_remove(ob, index))
88                 return OPERATOR_CANCELLED;
89 #else
90         (void)ob;
91         (void)index;
92 #endif
93
94         WM_event_add_notifier(C, NC_OBJECT | ND_LOD, CTX_wm_view3d(C));
95         return OPERATOR_FINISHED;
96 }
97
98 void OBJECT_OT_lod_remove(wmOperatorType *ot)
99 {
100         /* identifiers */
101         ot->name = "Remove Level of Detail";
102         ot->description = "Remove a level of detail from this object";
103         ot->idname = "OBJECT_OT_lod_remove";
104
105         /* api callbacks */
106         ot->exec = object_lod_remove_exec;
107         ot->poll = ED_operator_object_active;
108
109         /* flags */
110         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
111
112         /* properties */
113         ot->prop = RNA_def_int(ot->srna, "index", 1, 1, INT_MAX, "Index", "", 1, INT_MAX);
114 }