Thu, 18 Apr 2024 22:53:55 +0200
consistently refer to windows by ID - fixes #381
This change discovered that the font cache is completely broken. We created issue #387 for this.
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 */
28 #ifndef ASCENSION_WINDOW_H
29 #define ASCENSION_WINDOW_H
31 #include <SDL2/SDL.h>
33 #include "datatypes.h"
34 #include "glcontext.h"
35 #include "scene.h"
37 #ifndef ASC_MAX_WINDOWS
38 /** The maximum number of windows that can exist simultaneously. */
39 #define ASC_MAX_WINDOWS 4u
40 #endif // ASC_MAX_WINDOWS
42 typedef struct AscWindowSettings {
43 asc_vec2i dimensions;
44 int fullscreen;
45 char const* title;
46 AscGLContextSettings glsettings;
47 } AscWindowSettings;
49 typedef struct AscWindow {
50 Uint32 id;
51 SDL_Window* window;
52 asc_vec2i dimensions;
53 bool resized;
54 AscGLContext glctx;
55 AscSceneNode *ui;
56 } AscWindow;
58 /**
59 * Initializes the settings structure with default values.
60 *
61 * @param settings an uninitialized settings object
62 */
63 void asc_window_settings_init_defaults(AscWindowSettings* settings);
65 /**
66 * Creates and initializes a new window and a corresponding OpenGL context.
67 *
68 * The new window will also be automatically activated (see asc_window_activate()).
69 *
70 * The index specified must not be in use by another window already.
71 * The maximum number of windows is defined by #ASC_MAX_WINDOWS.
72 *
73 * @param index the index of the new window
74 * @param settings the settings to be used for initialization
75 */
76 void asc_window_initialize(unsigned int index, AscWindowSettings const* settings);
78 /**
79 * Destroys the window and its OpenGL context.
80 *
81 * When this window is currently active, there
82 * will be \em no active window afterwards.
83 *
84 * Still alive windows will also be destroyed by asc_context_destroy()
85 * automatically.
86 *
87 * @param index the index of the window
88 */
89 void asc_window_destroy(unsigned int index);
91 /**
92 * Swaps buffers and adjusts the viewport to the current window size.
93 *
94 * This function is automatically invoked by asc_loop_next().
95 * You usually should not call this function manually.
96 *
97 * If this function is invoked on a non-initialized window, nothing happens.
98 *
99 * @param index the index of the window
100 */
101 void asc_window_sync(unsigned int index);
103 /**
104 * Switches the active window.
105 *
106 * In particular that makes the corresponding OpenGL context "current".
107 * When you only want to draw into one window, you'll never need this.
108 *
109 * @param index the index of the window
110 */
111 void asc_window_activate(unsigned int index);
113 #endif /* ASCENSION_WINDOW_H */