Thu, 12 Jun 2025 22:44:49 +0200
consistent naming of structs and their typedefs
fixes #664
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * Copyright 2023 Mike Becker. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
25 | * POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | |
27 | ||
6
302971e8599b
move window related stuff to its own unit
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
28 | #ifndef ASCENSION_WINDOW_H |
302971e8599b
move window related stuff to its own unit
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
29 | #define ASCENSION_WINDOW_H |
0 | 30 | |
31 | #include <SDL2/SDL.h> | |
32 | ||
7 | 33 | #include "datatypes.h" |
44
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
34 | #include "glcontext.h" |
29
1d001eb694dc
bring first scene graph to live
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
35 | #include "scene.h" |
7 | 36 | |
37 | #ifndef ASC_MAX_WINDOWS | |
38 | /** The maximum number of windows that can exist simultaneously. */ | |
10
05d329adcecc
make ASC_MAX_WINDOWS an unsigned literal
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
39 | #define ASC_MAX_WINDOWS 4u |
7 | 40 | #endif // ASC_MAX_WINDOWS |
41 | ||
96
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
42 | #ifndef ASC_MAX_SCENES |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
43 | /** The maximum number of non-UI scenes per window. */ |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
44 | #define ASC_MAX_SCENES 8u |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
45 | #endif // ASC_MAX_SCENES |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
46 | |
145
a3231310d66d
consistent naming of structs and their typedefs
Mike Becker <universe@uap-core.de>
parents:
125
diff
changeset
|
47 | typedef struct asc_window_settings_s { |
68
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
48 | AscGLContextSettings glsettings; |
3 | 49 | asc_vec2i dimensions; |
0 | 50 | char const* title; |
68
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
51 | bool fullscreen; |
0 | 52 | } AscWindowSettings; |
53 | ||
145
a3231310d66d
consistent naming of structs and their typedefs
Mike Becker <universe@uap-core.de>
parents:
125
diff
changeset
|
54 | typedef struct asc_window_s { |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
55 | Uint32 id; |
68
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
56 | bool resized; |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
57 | bool focused; |
0 | 58 | SDL_Window* window; |
105 | 59 | asc_vec2u dimensions; |
44
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
60 | AscGLContext glctx; |
95
622887f7e954
in preparation of more scenes, bring back AscScene struct
Mike Becker <universe@uap-core.de>
parents:
75
diff
changeset
|
61 | AscScene ui; |
96
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
62 | AscScene scenes[ASC_MAX_SCENES]; |
0 | 63 | } AscWindow; |
64 | ||
64
f18dc427f86f
make use of the asc_window_active macro
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
65 | /** |
0 | 66 | * Initializes the settings structure with default values. |
67 | * | |
68 | * @param settings an uninitialized settings object | |
69 | */ | |
70 | void asc_window_settings_init_defaults(AscWindowSettings* settings); | |
71 | ||
72 | /** | |
73 | * Creates and initializes a new window and a corresponding OpenGL context. | |
74 | * | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
75 | * The new window will also be automatically activated (see asc_window_activate()). |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
76 | * |
7 | 77 | * The index specified must not be in use by another window already. |
78 | * The maximum number of windows is defined by #ASC_MAX_WINDOWS. | |
79 | * | |
80 | * @param index the index of the new window | |
0 | 81 | * @param settings the settings to be used for initialization |
82 | */ | |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
83 | void asc_window_initialize(unsigned int index, AscWindowSettings const* settings); |
0 | 84 | |
85 | /** | |
86 | * Destroys the window and its OpenGL context. | |
87 | * | |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
88 | * When this window is currently active, there |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
89 | * will be \em no active window afterwards. |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
90 | * |
0 | 91 | * Still alive windows will also be destroyed by asc_context_destroy() |
92 | * automatically. | |
93 | * | |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
94 | * @param index the index of the window |
0 | 95 | */ |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
96 | void asc_window_destroy(unsigned int index); |
0 | 97 | |
98 | /** | |
99 | * Swaps buffers and adjusts the viewport to the current window size. | |
100 | * | |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
101 | * This function is automatically invoked by asc_loop_next(). |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
102 | * You usually should not call this function manually. |
0 | 103 | * |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
104 | * If this function is invoked on a non-initialized window, nothing happens. |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
105 | * |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
106 | * @param index the index of the window |
0 | 107 | */ |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
108 | void asc_window_sync(unsigned int index); |
0 | 109 | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
110 | /** |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
111 | * Switches the active window. |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
112 | * |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
113 | * In particular that makes the corresponding OpenGL context "current". |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
114 | * When you only want to draw into one window, you'll never need this. |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
115 | * |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
116 | * @param index the index of the window |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
117 | */ |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
118 | void asc_window_activate(unsigned int index); |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
119 | |
68
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
120 | |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
121 | /** |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
122 | * Returns the index of the window with the specified SDL window ID. |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
123 | * |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
124 | * Returns #ASC_MAX_WINDOWS if no window with the specified ID exists. |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
125 | * |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
126 | * @param id the SDL window ID |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
127 | * @return the window index |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
128 | */ |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
129 | unsigned int asc_window_index(Uint32 id); |
823c03733e42
add mouse and window focus - resolves #382
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
130 | |
96
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
131 | /** |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
132 | * Returns a pointer to the scene within the currently active window with the specified index. |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
133 | * |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
134 | * If you want to use a scene, you need to initialize it first. |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
135 | * You can destroy the scene any time you want, but used scenes are also |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
136 | * destroyed automatically when the window gets destroyed. |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
137 | * |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
138 | * @param index an index less than #ASC_MAX_SCENES |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
139 | * @return a pointer to the scene |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
140 | */ |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
141 | AscScene *asc_window_scene(unsigned int index); |
9e25f080a33e
add scenes, but they don't draw yet
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
142 | |
95
622887f7e954
in preparation of more scenes, bring back AscScene struct
Mike Becker <universe@uap-core.de>
parents:
75
diff
changeset
|
143 | void asc_add_ui_node(AscSceneNode *node); |
622887f7e954
in preparation of more scenes, bring back AscScene struct
Mike Becker <universe@uap-core.de>
parents:
75
diff
changeset
|
144 | |
6
302971e8599b
move window related stuff to its own unit
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
145 | #endif /* ASCENSION_WINDOW_H */ |
0 | 146 |