src/ascension/window.h

Thu, 18 Apr 2024 21:53:53 +0200

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

make use of the asc_window_active macro

     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  * The currently active window in the context.
    60  * @see asc_window_activate()
    61  */
    62 #define asc_window_active asc_context.active_window
    64 /**
    65  * Initializes the settings structure with default values.
    66  *
    67  * @param settings an uninitialized settings object
    68  */
    69 void asc_window_settings_init_defaults(AscWindowSettings* settings);
    71 /**
    72  * Creates and initializes a new window and a corresponding OpenGL context.
    73  *
    74  * The new window will also be automatically activated (see asc_window_activate()).
    75  *
    76  * The index specified must not be in use by another window already.
    77  * The maximum number of windows is defined by #ASC_MAX_WINDOWS.
    78  *
    79  * @param index the index of the new window
    80  * @param settings the settings to be used for initialization
    81  * @return a pointer to the window data or \c NULL if initialization failed
    82  */
    83 AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const* settings);
    85 /**
    86  * Destroys the window and its OpenGL context.
    87  *
    88  * When this window is currently active, there will be \em no active window afterwards.
    89  *
    90  * Still alive windows will also be destroyed by asc_context_destroy()
    91  * automatically.
    92  *
    93  * @param window the window
    94  */
    95 void asc_window_destroy(AscWindow* window);
    97 /**
    98  * Swaps buffers and adjusts the viewport to the current window size.
    99  *
   100  * This function is automatically invoked for all initialized windows
   101  * by asc_loop_next(). You usually do not need to call this function manually.
   102  *
   103  * @param window the window
   104  */
   105 void asc_window_sync(AscWindow *window);
   107 /**
   108  * Switches the active window.
   109  *
   110  * In particular that makes the corresponding OpenGL context "current".
   111  * When you only want to draw into one window, you'll never need this.
   112  *
   113  * @param the window to activate
   114  */
   115 void asc_window_activate(AscWindow *window);
   117 #endif /* ASCENSION_WINDOW_H */

mercurial