src/ascension/window.h

Thu, 18 Apr 2024 22:53:55 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 18 Apr 2024 22:53:55 +0200
changeset 65
9c44c55d327a
parent 64
f18dc427f86f
permissions
-rw-r--r--

consistently refer to windows by ID - fixes #381

This change discovered that the font cache is completely broken. We created issue #387 for this.

universe@0 1 /*
universe@0 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@0 3 * Copyright 2023 Mike Becker. All rights reserved.
universe@0 4 *
universe@0 5 * Redistribution and use in source and binary forms, with or without
universe@0 6 * modification, are permitted provided that the following conditions are met:
universe@0 7 *
universe@0 8 * 1. Redistributions of source code must retain the above copyright
universe@0 9 * notice, this list of conditions and the following disclaimer.
universe@0 10 *
universe@0 11 * 2. Redistributions in binary form must reproduce the above copyright
universe@0 12 * notice, this list of conditions and the following disclaimer in the
universe@0 13 * documentation and/or other materials provided with the distribution.
universe@0 14 *
universe@0 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@0 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@0 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@0 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@0 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@0 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@0 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@0 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@0 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@0 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@0 25 * POSSIBILITY OF SUCH DAMAGE.
universe@0 26 */
universe@0 27
universe@6 28 #ifndef ASCENSION_WINDOW_H
universe@6 29 #define ASCENSION_WINDOW_H
universe@0 30
universe@0 31 #include <SDL2/SDL.h>
universe@0 32
universe@7 33 #include "datatypes.h"
universe@44 34 #include "glcontext.h"
universe@29 35 #include "scene.h"
universe@7 36
universe@7 37 #ifndef ASC_MAX_WINDOWS
universe@7 38 /** The maximum number of windows that can exist simultaneously. */
universe@10 39 #define ASC_MAX_WINDOWS 4u
universe@7 40 #endif // ASC_MAX_WINDOWS
universe@7 41
universe@0 42 typedef struct AscWindowSettings {
universe@3 43 asc_vec2i dimensions;
universe@0 44 int fullscreen;
universe@0 45 char const* title;
universe@44 46 AscGLContextSettings glsettings;
universe@0 47 } AscWindowSettings;
universe@0 48
universe@0 49 typedef struct AscWindow {
universe@16 50 Uint32 id;
universe@0 51 SDL_Window* window;
universe@3 52 asc_vec2i dimensions;
universe@37 53 bool resized;
universe@44 54 AscGLContext glctx;
universe@47 55 AscSceneNode *ui;
universe@0 56 } AscWindow;
universe@0 57
universe@64 58 /**
universe@0 59 * Initializes the settings structure with default values.
universe@0 60 *
universe@0 61 * @param settings an uninitialized settings object
universe@0 62 */
universe@0 63 void asc_window_settings_init_defaults(AscWindowSettings* settings);
universe@0 64
universe@0 65 /**
universe@0 66 * Creates and initializes a new window and a corresponding OpenGL context.
universe@0 67 *
universe@16 68 * The new window will also be automatically activated (see asc_window_activate()).
universe@16 69 *
universe@7 70 * The index specified must not be in use by another window already.
universe@7 71 * The maximum number of windows is defined by #ASC_MAX_WINDOWS.
universe@7 72 *
universe@7 73 * @param index the index of the new window
universe@0 74 * @param settings the settings to be used for initialization
universe@0 75 */
universe@65 76 void asc_window_initialize(unsigned int index, AscWindowSettings const* settings);
universe@0 77
universe@0 78 /**
universe@0 79 * Destroys the window and its OpenGL context.
universe@0 80 *
universe@65 81 * When this window is currently active, there
universe@65 82 * will be \em no active window afterwards.
universe@16 83 *
universe@0 84 * Still alive windows will also be destroyed by asc_context_destroy()
universe@0 85 * automatically.
universe@0 86 *
universe@65 87 * @param index the index of the window
universe@0 88 */
universe@65 89 void asc_window_destroy(unsigned int index);
universe@0 90
universe@0 91 /**
universe@0 92 * Swaps buffers and adjusts the viewport to the current window size.
universe@0 93 *
universe@65 94 * This function is automatically invoked by asc_loop_next().
universe@65 95 * You usually should not call this function manually.
universe@0 96 *
universe@65 97 * If this function is invoked on a non-initialized window, nothing happens.
universe@65 98 *
universe@65 99 * @param index the index of the window
universe@0 100 */
universe@65 101 void asc_window_sync(unsigned int index);
universe@0 102
universe@16 103 /**
universe@16 104 * Switches the active window.
universe@16 105 *
universe@16 106 * In particular that makes the corresponding OpenGL context "current".
universe@16 107 * When you only want to draw into one window, you'll never need this.
universe@16 108 *
universe@65 109 * @param index the index of the window
universe@16 110 */
universe@65 111 void asc_window_activate(unsigned int index);
universe@16 112
universe@6 113 #endif /* ASCENSION_WINDOW_H */
universe@0 114

mercurial