# Copyright 2014-2026 Tom Rothamel <pytom@bishoujo.us>
# Copyright 2014 Patrick Dawson <pat@dw.is>
#
# This software is provided 'as-is', without any express or implied
# warranty.  In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
#    claim that you wrote the original software. If you use this software
#    in a product, an acknowledgment in the product documentation would be
#    appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
#    misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.

import sys
from typing import Callable


# Lists of functions that are called on init and quit.
init_functions: list[Callable[[], None]] = []
quit_functions: list[Callable[[], None]] = []


def init():
    numpass = 0
    numfail = 0

    for i in init_functions:
        try:
            i()
            numpass += 1
        except Exception:
            numfail += 1
            raise

    return numpass, numfail


def quit():
    for i in quit_functions:
        try:
            i()
        except Exception:
            pass


# Import core modules.
from .error import *

from .locals import (
    NOEVENT as NOEVENT,
    QUIT as QUIT,
    TERMINATING as TERMINATING,
    LOWMEMORY as LOWMEMORY,
    WILLENTERBACKGROUND as WILLENTERBACKGROUND,
    DIDENTERBACKGROUND as DIDENTERBACKGROUND,
    WILLENTERFOREGROUND as WILLENTERFOREGROUND,
    DIDENTERFOREGROUND as DIDENTERFOREGROUND,
    LOCALECHANGED as LOCALECHANGED,
    SYSTEMTHEMECHANGED as SYSTEMTHEMECHANGED,
    DISPLAYORIENTATION as DISPLAYORIENTATION,
    DISPLAYADDED as DISPLAYADDED,
    DISPLAYREMOVED as DISPLAYREMOVED,
    DISPLAYMOVED as DISPLAYMOVED,
    DISPLAYDESKTOPMODECHANGED as DISPLAYDESKTOPMODECHANGED,
    DISPLAYCURRENTMODECHANGED as DISPLAYCURRENTMODECHANGED,
    DISPLAYCONTENTSCALECHANGED as DISPLAYCONTENTSCALECHANGED,
    DISPLAYUSABLEBOUNDSCHANGED as DISPLAYUSABLEBOUNDSCHANGED,
    DISPLAYFIRST as DISPLAYFIRST,
    DISPLAYLAST as DISPLAYLAST,
    WINDOWSHOWN as WINDOWSHOWN,
    WINDOWHIDDEN as WINDOWHIDDEN,
    WINDOWEXPOSED as WINDOWEXPOSED,
    WINDOWMOVED as WINDOWMOVED,
    WINDOWRESIZED as WINDOWRESIZED,
    WINDOWPIXELSIZECHANGED as WINDOWPIXELSIZECHANGED,
    WINDOWMETALVIEWRESIZED as WINDOWMETALVIEWRESIZED,
    WINDOWMINIMIZED as WINDOWMINIMIZED,
    WINDOWMAXIMIZED as WINDOWMAXIMIZED,
    WINDOWRESTORED as WINDOWRESTORED,
    WINDOWMOUSEENTER as WINDOWMOUSEENTER,
    WINDOWMOUSELEAVE as WINDOWMOUSELEAVE,
    WINDOWFOCUSGAINED as WINDOWFOCUSGAINED,
    WINDOWFOCUSLOST as WINDOWFOCUSLOST,
    WINDOWCLOSEREQUESTED as WINDOWCLOSEREQUESTED,
    WINDOWHITTEST as WINDOWHITTEST,
    WINDOWICCPROFCHANGED as WINDOWICCPROFCHANGED,
    WINDOWDISPLAYCHANGED as WINDOWDISPLAYCHANGED,
    WINDOWDISPLAYSCALECHANGED as WINDOWDISPLAYSCALECHANGED,
    WINDOWSAFEAREACHANGED as WINDOWSAFEAREACHANGED,
    WINDOWOCCLUDED as WINDOWOCCLUDED,
    WINDOWENTERFULLSCREEN as WINDOWENTERFULLSCREEN,
    WINDOWLEAVEFULLSCREEN as WINDOWLEAVEFULLSCREEN,
    WINDOWDESTROYED as WINDOWDESTROYED,
    WINDOWHDRSTATECHANGED as WINDOWHDRSTATECHANGED,
    WINDOWFIRST as WINDOWFIRST,
    WINDOWLAST as WINDOWLAST,
    KEYDOWN as KEYDOWN,
    KEYUP as KEYUP,
    TEXTEDITING as TEXTEDITING,
    TEXTINPUT as TEXTINPUT,
    KEYMAPCHANGED as KEYMAPCHANGED,
    KEYBOARDADDED as KEYBOARDADDED,
    KEYBOARDREMOVED as KEYBOARDREMOVED,
    TEXTEDITINGCANDIDATES as TEXTEDITINGCANDIDATES,
    SCREENKEYBOARDHIDDEN as SCREENKEYBOARDHIDDEN,
    MOUSEMOTION as MOUSEMOTION,
    MOUSEBUTTONDOWN as MOUSEBUTTONDOWN,
    MOUSEBUTTONUP as MOUSEBUTTONUP,
    MOUSEWHEEL as MOUSEWHEEL,
    MOUSEADDED as MOUSEADDED,
    MOUSEREMOVED as MOUSEREMOVED,
    JOYSTICKAXISMOTION as JOYSTICKAXISMOTION,
    JOYSTICKBALLMOTION as JOYSTICKBALLMOTION,
    JOYSTICKHATMOTION as JOYSTICKHATMOTION,
    JOYSTICKBUTTONDOWN as JOYSTICKBUTTONDOWN,
    JOYSTICKBUTTONUP as JOYSTICKBUTTONUP,
    JOYSTICKADDED as JOYSTICKADDED,
    JOYSTICKREMOVED as JOYSTICKREMOVED,
    JOYSTICKBATTERYUPDATED as JOYSTICKBATTERYUPDATED,
    JOYSTICKUPDATECOMPLETE as JOYSTICKUPDATECOMPLETE,
    GAMEPADAXISMOTION as GAMEPADAXISMOTION,
    GAMEPADBUTTONDOWN as GAMEPADBUTTONDOWN,
    GAMEPADBUTTONUP as GAMEPADBUTTONUP,
    GAMEPADADDED as GAMEPADADDED,
    GAMEPADREMOVED as GAMEPADREMOVED,
    GAMEPADREMAPPED as GAMEPADREMAPPED,
    GAMEPADTOUCHPADDOWN as GAMEPADTOUCHPADDOWN,
    GAMEPADTOUCHPADMOTION as GAMEPADTOUCHPADMOTION,
    GAMEPADTOUCHPADUP as GAMEPADTOUCHPADUP,
    GAMEPADSENSORUPDATE as GAMEPADSENSORUPDATE,
    GAMEPADUPDATECOMPLETE as GAMEPADUPDATECOMPLETE,
    GAMEPADSTEAMHANDLEUPDATED as GAMEPADSTEAMHANDLEUPDATED,
    FINGERDOWN as FINGERDOWN,
    FINGERUP as FINGERUP,
    FINGERMOTION as FINGERMOTION,
    FINGERCANCELED as FINGERCANCELED,
    PINCHBEGIN as PINCHBEGIN,
    PINCHUPDATE as PINCHUPDATE,
    PINCHEND as PINCHEND,
    CLIPBOARDUPDATE as CLIPBOARDUPDATE,
    DROPFILE as DROPFILE,
    DROPTEXT as DROPTEXT,
    DROPBEGIN as DROPBEGIN,
    DROPCOMPLETE as DROPCOMPLETE,
    DROPPOSITION as DROPPOSITION,
    AUDIODEVICEADDED as AUDIODEVICEADDED,
    AUDIODEVICEREMOVED as AUDIODEVICEREMOVED,
    AUDIODEVICEFORMATCHANGED as AUDIODEVICEFORMATCHANGED,
    SENSORUPDATE as SENSORUPDATE,
    PENPROXIMITYIN as PENPROXIMITYIN,
    PENPROXIMITYOUT as PENPROXIMITYOUT,
    PENDOWN as PENDOWN,
    PENUP as PENUP,
    PENBUTTONDOWN as PENBUTTONDOWN,
    PENBUTTONUP as PENBUTTONUP,
    PENMOTION as PENMOTION,
    PENAXIS as PENAXIS,
    CAMERADEVICEADDED as CAMERADEVICEADDED,
    CAMERADEVICEREMOVED as CAMERADEVICEREMOVED,
    CAMERADEVICEAPPROVED as CAMERADEVICEAPPROVED,
    CAMERADEVICEDENIED as CAMERADEVICEDENIED,
    RENDERTARGETSRESET as RENDERTARGETSRESET,
    RENDERDEVICERESET as RENDERDEVICERESET,
    RENDERDEVICELOST as RENDERDEVICELOST,
    USEREVENT as USEREVENT,
    JOYAXISMOTION as JOYAXISMOTION,
    JOYBALLMOTION as JOYBALLMOTION,
    JOYHATMOTION as JOYHATMOTION,
    JOYBUTTONDOWN as JOYBUTTONDOWN,
    JOYBUTTONUP as JOYBUTTONUP,
    JOYDEVICEADDED as JOYDEVICEADDED,
    JOYDEVICEREMOVED as JOYDEVICEREMOVED,
    CONTROLLERAXISMOTION as CONTROLLERAXISMOTION,
    CONTROLLERBUTTONDOWN as CONTROLLERBUTTONDOWN,
    CONTROLLERBUTTONUP as CONTROLLERBUTTONUP,
    CONTROLLERDEVICEADDED as CONTROLLERDEVICEADDED,
    CONTROLLERDEVICEREMOVED as CONTROLLERDEVICEREMOVED,
    CONTROLLERDEVICEREMAPPED as CONTROLLERDEVICEREMAPPED,
    DISPLAYEVENT as DISPLAYEVENT,
    WINDOWEVENT as WINDOWEVENT,
    SYSWMEVENT as SYSWMEVENT,
    DOLLARGESTURE as DOLLARGESTURE,
    DOLLARRECORD as DOLLARRECORD,
    MULTIGESTURE as MULTIGESTURE,
    GL_RED_SIZE as GL_RED_SIZE,
    GL_GREEN_SIZE as GL_GREEN_SIZE,
    GL_BLUE_SIZE as GL_BLUE_SIZE,
    GL_ALPHA_SIZE as GL_ALPHA_SIZE,
    GL_BUFFER_SIZE as GL_BUFFER_SIZE,
    GL_DOUBLEBUFFER as GL_DOUBLEBUFFER,
    GL_DEPTH_SIZE as GL_DEPTH_SIZE,
    GL_STENCIL_SIZE as GL_STENCIL_SIZE,
    GL_ACCUM_RED_SIZE as GL_ACCUM_RED_SIZE,
    GL_ACCUM_GREEN_SIZE as GL_ACCUM_GREEN_SIZE,
    GL_ACCUM_BLUE_SIZE as GL_ACCUM_BLUE_SIZE,
    GL_ACCUM_ALPHA_SIZE as GL_ACCUM_ALPHA_SIZE,
    GL_STEREO as GL_STEREO,
    GL_MULTISAMPLEBUFFERS as GL_MULTISAMPLEBUFFERS,
    GL_MULTISAMPLESAMPLES as GL_MULTISAMPLESAMPLES,
    GL_ACCELERATED_VISUAL as GL_ACCELERATED_VISUAL,
    GL_RETAINED_BACKING as GL_RETAINED_BACKING,
    GL_CONTEXT_MAJOR_VERSION as GL_CONTEXT_MAJOR_VERSION,
    GL_CONTEXT_MINOR_VERSION as GL_CONTEXT_MINOR_VERSION,
    GL_CONTEXT_FLAGS as GL_CONTEXT_FLAGS,
    GL_CONTEXT_PROFILE_MASK as GL_CONTEXT_PROFILE_MASK,
    GL_SHARE_WITH_CURRENT_CONTEXT as GL_SHARE_WITH_CURRENT_CONTEXT,
    GL_FRAMEBUFFER_SRGB_CAPABLE as GL_FRAMEBUFFER_SRGB_CAPABLE,
    GL_CONTEXT_RELEASE_BEHAVIOR as GL_CONTEXT_RELEASE_BEHAVIOR,
    GL_CONTEXT_RESET_NOTIFICATION as GL_CONTEXT_RESET_NOTIFICATION,
    GL_CONTEXT_NO_ERROR as GL_CONTEXT_NO_ERROR,
    GL_FLOATBUFFERS as GL_FLOATBUFFERS,
    GL_EGL_PLATFORM as GL_EGL_PLATFORM,
    GL_SWAP_CONTROL as GL_SWAP_CONTROL,
    GL_CONTEXT_PROFILE_CORE as GL_CONTEXT_PROFILE_CORE,
    GL_CONTEXT_PROFILE_COMPATIBILITY as GL_CONTEXT_PROFILE_COMPATIBILITY,
    GL_CONTEXT_PROFILE_ES as GL_CONTEXT_PROFILE_ES,
    RLEACCEL as RLEACCEL,
    BLEND_ADD as BLEND_ADD,
    BLEND_SUB as BLEND_SUB,
    BLEND_MULT as BLEND_MULT,
    BLEND_MIN as BLEND_MIN,
    BLEND_MAX as BLEND_MAX,
    BLEND_RGB_ADD as BLEND_RGB_ADD,
    BLEND_RGB_SUB as BLEND_RGB_SUB,
    BLEND_RGB_MULT as BLEND_RGB_MULT,
    BLEND_RGB_MIN as BLEND_RGB_MIN,
    BLEND_RGB_MAX as BLEND_RGB_MAX,
    BLEND_RGBA_ADD as BLEND_RGBA_ADD,
    BLEND_RGBA_SUB as BLEND_RGBA_SUB,
    BLEND_RGBA_MULT as BLEND_RGBA_MULT,
    BLEND_RGBA_MIN as BLEND_RGBA_MIN,
    BLEND_RGBA_MAX as BLEND_RGBA_MAX,
    BLEND_PREMULTIPLIED as BLEND_PREMULTIPLIED,
    BLEND_ALPHA_SDL2 as BLEND_ALPHA_SDL2,
    SRCCOLORKEY as SRCCOLORKEY,
    SRCALPHA as SRCALPHA,
    HWSURFACE as HWSURFACE,
    SWSURFACE as SWSURFACE,
    WINDOW_FULLSCREEN as WINDOW_FULLSCREEN,
    WINDOW_OPENGL as WINDOW_OPENGL,
    WINDOW_OCCLUDED as WINDOW_OCCLUDED,
    WINDOW_HIDDEN as WINDOW_HIDDEN,
    WINDOW_BORDERLESS as WINDOW_BORDERLESS,
    WINDOW_RESIZABLE as WINDOW_RESIZABLE,
    WINDOW_MINIMIZED as WINDOW_MINIMIZED,
    WINDOW_MAXIMIZED as WINDOW_MAXIMIZED,
    WINDOW_MOUSE_GRABBED as WINDOW_MOUSE_GRABBED,
    WINDOW_INPUT_FOCUS as WINDOW_INPUT_FOCUS,
    WINDOW_MOUSE_FOCUS as WINDOW_MOUSE_FOCUS,
    WINDOW_EXTERNAL as WINDOW_EXTERNAL,
    WINDOW_MODAL as WINDOW_MODAL,
    WINDOW_HIGH_PIXEL_DENSITY as WINDOW_HIGH_PIXEL_DENSITY,
    WINDOW_MOUSE_CAPTURE as WINDOW_MOUSE_CAPTURE,
    WINDOW_MOUSE_RELATIVE_MODE as WINDOW_MOUSE_RELATIVE_MODE,
    WINDOW_ALWAYS_ON_TOP as WINDOW_ALWAYS_ON_TOP,
    WINDOW_UTILITY as WINDOW_UTILITY,
    WINDOW_TOOLTIP as WINDOW_TOOLTIP,
    WINDOW_POPUP_MENU as WINDOW_POPUP_MENU,
    WINDOW_KEYBOARD_GRABBED as WINDOW_KEYBOARD_GRABBED,
    WINDOW_FILL_DOCUMENT as WINDOW_FILL_DOCUMENT,
    WINDOW_VULKAN as WINDOW_VULKAN,
    WINDOW_METAL as WINDOW_METAL,
    WINDOW_TRANSPARENT as WINDOW_TRANSPARENT,
    WINDOW_NOT_FOCUSABLE as WINDOW_NOT_FOCUSABLE,
    WINDOW_FULLSCREEN_DESKTOP as WINDOW_FULLSCREEN_DESKTOP,
    FULLSCREEN as FULLSCREEN,
    OPENGL as OPENGL,
    NOFRAME as NOFRAME,
    RESIZABLE as RESIZABLE,
    DOUBLEBUF as DOUBLEBUF,
    WINDOWPOS_UNDEFINED as WINDOWPOS_UNDEFINED,
    WINDOWPOS_CENTERED as WINDOWPOS_CENTERED,
    SCRAP_TEXT as SCRAP_TEXT,
    BYTEORDER as BYTEORDER,
    LIL_ENDIAN as LIL_ENDIAN,
    BIG_ENDIAN as BIG_ENDIAN,
    TOUCH_MOUSEID as TOUCH_MOUSEID,
    POWERSTATE_UNKNOWN as POWERSTATE_UNKNOWN,
    POWERSTATE_ON_BATTERY as POWERSTATE_ON_BATTERY,
    POWERSTATE_NO_BATTERY as POWERSTATE_NO_BATTERY,
    POWERSTATE_CHARGING as POWERSTATE_CHARGING,
    POWERSTATE_CHARGED as POWERSTATE_CHARGED,
    K_UNKNOWN as K_UNKNOWN,
    K_RETURN as K_RETURN,
    K_ESCAPE as K_ESCAPE,
    K_BACKSPACE as K_BACKSPACE,
    K_TAB as K_TAB,
    K_SPACE as K_SPACE,
    K_EXCLAIM as K_EXCLAIM,
    K_QUOTEDBL as K_QUOTEDBL,
    K_DBLAPOSTROPHE as K_DBLAPOSTROPHE,
    K_HASH as K_HASH,
    K_DOLLAR as K_DOLLAR,
    K_PERCENT as K_PERCENT,
    K_AMPERSAND as K_AMPERSAND,
    K_QUOTE as K_QUOTE,
    K_APOSTROPHE as K_APOSTROPHE,
    K_LEFTPAREN as K_LEFTPAREN,
    K_RIGHTPAREN as K_RIGHTPAREN,
    K_ASTERISK as K_ASTERISK,
    K_PLUS as K_PLUS,
    K_COMMA as K_COMMA,
    K_MINUS as K_MINUS,
    K_PERIOD as K_PERIOD,
    K_SLASH as K_SLASH,
    K_0 as K_0,
    K_1 as K_1,
    K_2 as K_2,
    K_3 as K_3,
    K_4 as K_4,
    K_5 as K_5,
    K_6 as K_6,
    K_7 as K_7,
    K_8 as K_8,
    K_9 as K_9,
    K_COLON as K_COLON,
    K_SEMICOLON as K_SEMICOLON,
    K_LESS as K_LESS,
    K_EQUALS as K_EQUALS,
    K_GREATER as K_GREATER,
    K_QUESTION as K_QUESTION,
    K_AT as K_AT,
    K_LEFTBRACKET as K_LEFTBRACKET,
    K_BACKSLASH as K_BACKSLASH,
    K_RIGHTBRACKET as K_RIGHTBRACKET,
    K_CARET as K_CARET,
    K_UNDERSCORE as K_UNDERSCORE,
    K_BACKQUOTE as K_BACKQUOTE,
    K_GRAVE as K_GRAVE,
    K_a as K_a,
    K_A as K_A,
    K_b as K_b,
    K_B as K_B,
    K_c as K_c,
    K_C as K_C,
    K_d as K_d,
    K_D as K_D,
    K_e as K_e,
    K_E as K_E,
    K_f as K_f,
    K_F as K_F,
    K_g as K_g,
    K_G as K_G,
    K_h as K_h,
    K_H as K_H,
    K_i as K_i,
    K_I as K_I,
    K_j as K_j,
    K_J as K_J,
    K_k as K_k,
    K_K as K_K,
    K_l as K_l,
    K_L as K_L,
    K_m as K_m,
    K_M as K_M,
    K_n as K_n,
    K_N as K_N,
    K_o as K_o,
    K_O as K_O,
    K_p as K_p,
    K_P as K_P,
    K_q as K_q,
    K_Q as K_Q,
    K_r as K_r,
    K_R as K_R,
    K_s as K_s,
    K_S as K_S,
    K_t as K_t,
    K_T as K_T,
    K_u as K_u,
    K_U as K_U,
    K_v as K_v,
    K_V as K_V,
    K_w as K_w,
    K_W as K_W,
    K_x as K_x,
    K_X as K_X,
    K_y as K_y,
    K_Y as K_Y,
    K_z as K_z,
    K_Z as K_Z,
    K_LEFTBRACE as K_LEFTBRACE,
    K_PIPE as K_PIPE,
    K_RIGHTBRACE as K_RIGHTBRACE,
    K_TILDE as K_TILDE,
    K_DELETE as K_DELETE,
    K_PLUSMINUS as K_PLUSMINUS,
    K_CAPSLOCK as K_CAPSLOCK,
    K_F1 as K_F1,
    K_F2 as K_F2,
    K_F3 as K_F3,
    K_F4 as K_F4,
    K_F5 as K_F5,
    K_F6 as K_F6,
    K_F7 as K_F7,
    K_F8 as K_F8,
    K_F9 as K_F9,
    K_F10 as K_F10,
    K_F11 as K_F11,
    K_F12 as K_F12,
    K_PRINTSCREEN as K_PRINTSCREEN,
    K_SCROLLLOCK as K_SCROLLLOCK,
    K_PAUSE as K_PAUSE,
    K_INSERT as K_INSERT,
    K_HOME as K_HOME,
    K_PAGEUP as K_PAGEUP,
    K_END as K_END,
    K_PAGEDOWN as K_PAGEDOWN,
    K_RIGHT as K_RIGHT,
    K_LEFT as K_LEFT,
    K_DOWN as K_DOWN,
    K_UP as K_UP,
    K_NUMLOCKCLEAR as K_NUMLOCKCLEAR,
    K_KP_DIVIDE as K_KP_DIVIDE,
    K_KP_MULTIPLY as K_KP_MULTIPLY,
    K_KP_MINUS as K_KP_MINUS,
    K_KP_PLUS as K_KP_PLUS,
    K_KP_ENTER as K_KP_ENTER,
    K_KP1 as K_KP1,
    K_KP_1 as K_KP_1,
    K_KP2 as K_KP2,
    K_KP_2 as K_KP_2,
    K_KP3 as K_KP3,
    K_KP_3 as K_KP_3,
    K_KP4 as K_KP4,
    K_KP_4 as K_KP_4,
    K_KP5 as K_KP5,
    K_KP_5 as K_KP_5,
    K_KP6 as K_KP6,
    K_KP_6 as K_KP_6,
    K_KP7 as K_KP7,
    K_KP_7 as K_KP_7,
    K_KP8 as K_KP8,
    K_KP_8 as K_KP_8,
    K_KP9 as K_KP9,
    K_KP_9 as K_KP_9,
    K_KP0 as K_KP0,
    K_KP_0 as K_KP_0,
    K_KP_PERIOD as K_KP_PERIOD,
    K_APPLICATION as K_APPLICATION,
    K_POWER as K_POWER,
    K_KP_EQUALS as K_KP_EQUALS,
    K_F13 as K_F13,
    K_F14 as K_F14,
    K_F15 as K_F15,
    K_F16 as K_F16,
    K_F17 as K_F17,
    K_F18 as K_F18,
    K_F19 as K_F19,
    K_F20 as K_F20,
    K_F21 as K_F21,
    K_F22 as K_F22,
    K_F23 as K_F23,
    K_F24 as K_F24,
    K_EXECUTE as K_EXECUTE,
    K_HELP as K_HELP,
    K_MENU as K_MENU,
    K_SELECT as K_SELECT,
    K_STOP as K_STOP,
    K_AGAIN as K_AGAIN,
    K_UNDO as K_UNDO,
    K_CUT as K_CUT,
    K_COPY as K_COPY,
    K_PASTE as K_PASTE,
    K_FIND as K_FIND,
    K_MUTE as K_MUTE,
    K_VOLUMEUP as K_VOLUMEUP,
    K_VOLUMEDOWN as K_VOLUMEDOWN,
    K_KP_COMMA as K_KP_COMMA,
    K_KP_EQUALSAS400 as K_KP_EQUALSAS400,
    K_ALTERASE as K_ALTERASE,
    K_SYSREQ as K_SYSREQ,
    K_CANCEL as K_CANCEL,
    K_CLEAR as K_CLEAR,
    K_PRIOR as K_PRIOR,
    K_RETURN2 as K_RETURN2,
    K_SEPARATOR as K_SEPARATOR,
    K_OUT as K_OUT,
    K_OPER as K_OPER,
    K_CLEARAGAIN as K_CLEARAGAIN,
    K_CRSEL as K_CRSEL,
    K_EXSEL as K_EXSEL,
    K_KP_00 as K_KP_00,
    K_KP_000 as K_KP_000,
    K_THOUSANDSSEPARATOR as K_THOUSANDSSEPARATOR,
    K_DECIMALSEPARATOR as K_DECIMALSEPARATOR,
    K_CURRENCYUNIT as K_CURRENCYUNIT,
    K_CURRENCYSUBUNIT as K_CURRENCYSUBUNIT,
    K_KP_LEFTPAREN as K_KP_LEFTPAREN,
    K_KP_RIGHTPAREN as K_KP_RIGHTPAREN,
    K_KP_LEFTBRACE as K_KP_LEFTBRACE,
    K_KP_RIGHTBRACE as K_KP_RIGHTBRACE,
    K_KP_TAB as K_KP_TAB,
    K_KP_BACKSPACE as K_KP_BACKSPACE,
    K_KP_A as K_KP_A,
    K_KP_B as K_KP_B,
    K_KP_C as K_KP_C,
    K_KP_D as K_KP_D,
    K_KP_E as K_KP_E,
    K_KP_F as K_KP_F,
    K_KP_XOR as K_KP_XOR,
    K_KP_POWER as K_KP_POWER,
    K_KP_PERCENT as K_KP_PERCENT,
    K_KP_LESS as K_KP_LESS,
    K_KP_GREATER as K_KP_GREATER,
    K_KP_AMPERSAND as K_KP_AMPERSAND,
    K_KP_DBLAMPERSAND as K_KP_DBLAMPERSAND,
    K_KP_VERTICALBAR as K_KP_VERTICALBAR,
    K_KP_DBLVERTICALBAR as K_KP_DBLVERTICALBAR,
    K_KP_COLON as K_KP_COLON,
    K_KP_HASH as K_KP_HASH,
    K_KP_SPACE as K_KP_SPACE,
    K_KP_AT as K_KP_AT,
    K_KP_EXCLAM as K_KP_EXCLAM,
    K_KP_MEMSTORE as K_KP_MEMSTORE,
    K_KP_MEMRECALL as K_KP_MEMRECALL,
    K_KP_MEMCLEAR as K_KP_MEMCLEAR,
    K_KP_MEMADD as K_KP_MEMADD,
    K_KP_MEMSUBTRACT as K_KP_MEMSUBTRACT,
    K_KP_MEMMULTIPLY as K_KP_MEMMULTIPLY,
    K_KP_MEMDIVIDE as K_KP_MEMDIVIDE,
    K_KP_PLUSMINUS as K_KP_PLUSMINUS,
    K_KP_CLEAR as K_KP_CLEAR,
    K_KP_CLEARENTRY as K_KP_CLEARENTRY,
    K_KP_BINARY as K_KP_BINARY,
    K_KP_OCTAL as K_KP_OCTAL,
    K_KP_DECIMAL as K_KP_DECIMAL,
    K_KP_HEXADECIMAL as K_KP_HEXADECIMAL,
    K_LCTRL as K_LCTRL,
    K_LSHIFT as K_LSHIFT,
    K_LALT as K_LALT,
    K_LGUI as K_LGUI,
    K_RCTRL as K_RCTRL,
    K_RSHIFT as K_RSHIFT,
    K_RALT as K_RALT,
    K_RGUI as K_RGUI,
    K_MODE as K_MODE,
    K_SLEEP as K_SLEEP,
    K_WAKE as K_WAKE,
    K_CHANNEL_INCREMENT as K_CHANNEL_INCREMENT,
    K_CHANNEL_DECREMENT as K_CHANNEL_DECREMENT,
    K_MEDIA_PLAY as K_MEDIA_PLAY,
    K_MEDIA_PAUSE as K_MEDIA_PAUSE,
    K_MEDIA_RECORD as K_MEDIA_RECORD,
    K_MEDIA_FAST_FORWARD as K_MEDIA_FAST_FORWARD,
    K_MEDIA_REWIND as K_MEDIA_REWIND,
    K_MEDIA_NEXT_TRACK as K_MEDIA_NEXT_TRACK,
    K_MEDIA_PREVIOUS_TRACK as K_MEDIA_PREVIOUS_TRACK,
    K_MEDIA_STOP as K_MEDIA_STOP,
    K_MEDIA_EJECT as K_MEDIA_EJECT,
    K_MEDIA_PLAY_PAUSE as K_MEDIA_PLAY_PAUSE,
    K_MEDIA_SELECT as K_MEDIA_SELECT,
    K_AC_NEW as K_AC_NEW,
    K_AC_OPEN as K_AC_OPEN,
    K_AC_CLOSE as K_AC_CLOSE,
    K_AC_EXIT as K_AC_EXIT,
    K_AC_SAVE as K_AC_SAVE,
    K_AC_PRINT as K_AC_PRINT,
    K_AC_PROPERTIES as K_AC_PROPERTIES,
    K_AC_SEARCH as K_AC_SEARCH,
    K_AC_HOME as K_AC_HOME,
    K_AC_BACK as K_AC_BACK,
    K_AC_FORWARD as K_AC_FORWARD,
    K_AC_STOP as K_AC_STOP,
    K_AC_REFRESH as K_AC_REFRESH,
    K_AC_BOOKMARKS as K_AC_BOOKMARKS,
    K_SOFTLEFT as K_SOFTLEFT,
    K_SOFTRIGHT as K_SOFTRIGHT,
    K_CALL as K_CALL,
    K_ENDCALL as K_ENDCALL,
    K_LEFT_TAB as K_LEFT_TAB,
    K_LEVEL5_SHIFT as K_LEVEL5_SHIFT,
    K_MULTI_KEY_COMPOSE as K_MULTI_KEY_COMPOSE,
    K_LMETA as K_LMETA,
    K_RMETA as K_RMETA,
    K_LHYPER as K_LHYPER,
    K_RHYPER as K_RHYPER,
    K_BREAK as K_BREAK,
    K_EURO as K_EURO,
    K_NUMLOCK as K_NUMLOCK,
    K_PRINT as K_PRINT,
    K_AUDIOMUTE as K_AUDIOMUTE,
    K_AUDIONEXT as K_AUDIONEXT,
    K_AUDIOPLAY as K_AUDIOPLAY,
    K_AUDIOPREV as K_AUDIOPREV,
    K_AUDIOREWIND as K_AUDIOREWIND,
    K_AUDIOSTOP as K_AUDIOSTOP,
    K_EJECT as K_EJECT,
    K_MEDIASELECT as K_MEDIASELECT,
    KMOD_NONE as KMOD_NONE,
    KMOD_LSHIFT as KMOD_LSHIFT,
    KMOD_RSHIFT as KMOD_RSHIFT,
    KMOD_LEVEL5 as KMOD_LEVEL5,
    KMOD_LCTRL as KMOD_LCTRL,
    KMOD_RCTRL as KMOD_RCTRL,
    KMOD_LALT as KMOD_LALT,
    KMOD_RALT as KMOD_RALT,
    KMOD_LSUPER as KMOD_LSUPER,
    KMOD_LMETA as KMOD_LMETA,
    KMOD_LGUI as KMOD_LGUI,
    KMOD_RSUPER as KMOD_RSUPER,
    KMOD_RMETA as KMOD_RMETA,
    KMOD_RGUI as KMOD_RGUI,
    KMOD_NUM as KMOD_NUM,
    KMOD_CAPS as KMOD_CAPS,
    KMOD_MODE as KMOD_MODE,
    KMOD_SCROLL as KMOD_SCROLL,
    KMOD_CTRL as KMOD_CTRL,
    KMOD_SHIFT as KMOD_SHIFT,
    KMOD_ALT as KMOD_ALT,
    KMOD_META as KMOD_META,
    KMOD_GUI as KMOD_GUI,
    KMOD_SUPER as KMOD_SUPER,
    BUTTON_LEFT as BUTTON_LEFT,
    BUTTON_MIDDLE as BUTTON_MIDDLE,
    BUTTON_RIGHT as BUTTON_RIGHT,
    BUTTON_X1 as BUTTON_X1,
    BUTTON_X2 as BUTTON_X2,
    BUTTON_LMASK as BUTTON_LMASK,
    BUTTON_MMASK as BUTTON_MMASK,
    BUTTON_RMASK as BUTTON_RMASK,
    BUTTON_X1MASK as BUTTON_X1MASK,
    BUTTON_X2MASK as BUTTON_X2MASK,
    CONTROLLER_BUTTON_INVALID as CONTROLLER_BUTTON_INVALID,
    GAMEPAD_BUTTON_INVALID as GAMEPAD_BUTTON_INVALID,
    CONTROLLER_BUTTON_SOUTH as CONTROLLER_BUTTON_SOUTH,
    GAMEPAD_BUTTON_SOUTH as GAMEPAD_BUTTON_SOUTH,
    CONTROLLER_BUTTON_EAST as CONTROLLER_BUTTON_EAST,
    GAMEPAD_BUTTON_EAST as GAMEPAD_BUTTON_EAST,
    CONTROLLER_BUTTON_WEST as CONTROLLER_BUTTON_WEST,
    GAMEPAD_BUTTON_WEST as GAMEPAD_BUTTON_WEST,
    CONTROLLER_BUTTON_NORTH as CONTROLLER_BUTTON_NORTH,
    GAMEPAD_BUTTON_NORTH as GAMEPAD_BUTTON_NORTH,
    CONTROLLER_BUTTON_BACK as CONTROLLER_BUTTON_BACK,
    GAMEPAD_BUTTON_BACK as GAMEPAD_BUTTON_BACK,
    CONTROLLER_BUTTON_GUIDE as CONTROLLER_BUTTON_GUIDE,
    GAMEPAD_BUTTON_GUIDE as GAMEPAD_BUTTON_GUIDE,
    CONTROLLER_BUTTON_START as CONTROLLER_BUTTON_START,
    GAMEPAD_BUTTON_START as GAMEPAD_BUTTON_START,
    CONTROLLER_BUTTON_LEFT_STICK as CONTROLLER_BUTTON_LEFT_STICK,
    GAMEPAD_BUTTON_LEFT_STICK as GAMEPAD_BUTTON_LEFT_STICK,
    CONTROLLER_BUTTON_RIGHT_STICK as CONTROLLER_BUTTON_RIGHT_STICK,
    GAMEPAD_BUTTON_RIGHT_STICK as GAMEPAD_BUTTON_RIGHT_STICK,
    CONTROLLER_BUTTON_LEFT_SHOULDER as CONTROLLER_BUTTON_LEFT_SHOULDER,
    GAMEPAD_BUTTON_LEFT_SHOULDER as GAMEPAD_BUTTON_LEFT_SHOULDER,
    CONTROLLER_BUTTON_RIGHT_SHOULDER as CONTROLLER_BUTTON_RIGHT_SHOULDER,
    GAMEPAD_BUTTON_RIGHT_SHOULDER as GAMEPAD_BUTTON_RIGHT_SHOULDER,
    CONTROLLER_BUTTON_DPAD_UP as CONTROLLER_BUTTON_DPAD_UP,
    GAMEPAD_BUTTON_DPAD_UP as GAMEPAD_BUTTON_DPAD_UP,
    CONTROLLER_BUTTON_DPAD_DOWN as CONTROLLER_BUTTON_DPAD_DOWN,
    GAMEPAD_BUTTON_DPAD_DOWN as GAMEPAD_BUTTON_DPAD_DOWN,
    CONTROLLER_BUTTON_DPAD_LEFT as CONTROLLER_BUTTON_DPAD_LEFT,
    GAMEPAD_BUTTON_DPAD_LEFT as GAMEPAD_BUTTON_DPAD_LEFT,
    CONTROLLER_BUTTON_DPAD_RIGHT as CONTROLLER_BUTTON_DPAD_RIGHT,
    GAMEPAD_BUTTON_DPAD_RIGHT as GAMEPAD_BUTTON_DPAD_RIGHT,
    CONTROLLER_BUTTON_MISC1 as CONTROLLER_BUTTON_MISC1,
    GAMEPAD_BUTTON_MISC1 as GAMEPAD_BUTTON_MISC1,
    CONTROLLER_BUTTON_RIGHT_PADDLE1 as CONTROLLER_BUTTON_RIGHT_PADDLE1,
    GAMEPAD_BUTTON_RIGHT_PADDLE1 as GAMEPAD_BUTTON_RIGHT_PADDLE1,
    CONTROLLER_BUTTON_LEFT_PADDLE1 as CONTROLLER_BUTTON_LEFT_PADDLE1,
    GAMEPAD_BUTTON_LEFT_PADDLE1 as GAMEPAD_BUTTON_LEFT_PADDLE1,
    CONTROLLER_BUTTON_RIGHT_PADDLE2 as CONTROLLER_BUTTON_RIGHT_PADDLE2,
    GAMEPAD_BUTTON_RIGHT_PADDLE2 as GAMEPAD_BUTTON_RIGHT_PADDLE2,
    CONTROLLER_BUTTON_LEFT_PADDLE2 as CONTROLLER_BUTTON_LEFT_PADDLE2,
    GAMEPAD_BUTTON_LEFT_PADDLE2 as GAMEPAD_BUTTON_LEFT_PADDLE2,
    CONTROLLER_BUTTON_TOUCHPAD as CONTROLLER_BUTTON_TOUCHPAD,
    GAMEPAD_BUTTON_TOUCHPAD as GAMEPAD_BUTTON_TOUCHPAD,
    CONTROLLER_BUTTON_MISC2 as CONTROLLER_BUTTON_MISC2,
    GAMEPAD_BUTTON_MISC2 as GAMEPAD_BUTTON_MISC2,
    CONTROLLER_BUTTON_MISC3 as CONTROLLER_BUTTON_MISC3,
    GAMEPAD_BUTTON_MISC3 as GAMEPAD_BUTTON_MISC3,
    CONTROLLER_BUTTON_MISC4 as CONTROLLER_BUTTON_MISC4,
    GAMEPAD_BUTTON_MISC4 as GAMEPAD_BUTTON_MISC4,
    CONTROLLER_BUTTON_MISC5 as CONTROLLER_BUTTON_MISC5,
    GAMEPAD_BUTTON_MISC5 as GAMEPAD_BUTTON_MISC5,
    CONTROLLER_BUTTON_MISC6 as CONTROLLER_BUTTON_MISC6,
    GAMEPAD_BUTTON_MISC6 as GAMEPAD_BUTTON_MISC6,
    CONTROLLER_BUTTON_COUNT as CONTROLLER_BUTTON_COUNT,
    GAMEPAD_BUTTON_COUNT as GAMEPAD_BUTTON_COUNT,
    CONTROLLER_BUTTON_A as CONTROLLER_BUTTON_A,
    GAMEPAD_BUTTON_A as GAMEPAD_BUTTON_A,
    CONTROLLER_BUTTON_B as CONTROLLER_BUTTON_B,
    GAMEPAD_BUTTON_B as GAMEPAD_BUTTON_B,
    CONTROLLER_BUTTON_X as CONTROLLER_BUTTON_X,
    GAMEPAD_BUTTON_X as GAMEPAD_BUTTON_X,
    CONTROLLER_BUTTON_Y as CONTROLLER_BUTTON_Y,
    GAMEPAD_BUTTON_Y as GAMEPAD_BUTTON_Y,
    CONTROLLER_AXIS_INVALID as CONTROLLER_AXIS_INVALID,
    GAMEPAD_AXIS_INVALID as GAMEPAD_AXIS_INVALID,
    CONTROLLER_AXIS_LEFTX as CONTROLLER_AXIS_LEFTX,
    GAMEPAD_AXIS_LEFTX as GAMEPAD_AXIS_LEFTX,
    CONTROLLER_AXIS_LEFTY as CONTROLLER_AXIS_LEFTY,
    GAMEPAD_AXIS_LEFTY as GAMEPAD_AXIS_LEFTY,
    CONTROLLER_AXIS_RIGHTX as CONTROLLER_AXIS_RIGHTX,
    GAMEPAD_AXIS_RIGHTX as GAMEPAD_AXIS_RIGHTX,
    CONTROLLER_AXIS_RIGHTY as CONTROLLER_AXIS_RIGHTY,
    GAMEPAD_AXIS_RIGHTY as GAMEPAD_AXIS_RIGHTY,
    CONTROLLER_AXIS_LEFT_TRIGGER as CONTROLLER_AXIS_LEFT_TRIGGER,
    GAMEPAD_AXIS_LEFT_TRIGGER as GAMEPAD_AXIS_LEFT_TRIGGER,
    CONTROLLER_AXIS_RIGHT_TRIGGER as CONTROLLER_AXIS_RIGHT_TRIGGER,
    GAMEPAD_AXIS_RIGHT_TRIGGER as GAMEPAD_AXIS_RIGHT_TRIGGER,
    CONTROLLER_AXIS_COUNT as CONTROLLER_AXIS_COUNT,
    GAMEPAD_AXIS_COUNT as GAMEPAD_AXIS_COUNT,
    CONTROLLER_AXIS_TRIGGERLEFT as CONTROLLER_AXIS_TRIGGERLEFT,
    CONTROLLER_AXIS_TRIGGERRIGHT as CONTROLLER_AXIS_TRIGGERRIGHT,
)

from .surface import Surface as Surface
from .rect import Rect as Rect

from . import (
    rect as rect,
    surface as surface,
    color as color,
    display as display,
    event as event,
    key as key,
    locals as locals,
    time as time,
    locals as constants,
    controller as controller,
    draw as draw,
    image as image,
    joystick as joystick,
    mouse as mouse,
    power as power,
    transform as transform,
    scrap as scrap,
)


# Fill this module with locals.
from .locals import *
from .locals import LIL_ENDIAN, SDL_VERSION_TUPLE

# Add init functions.

init_functions = [
    display.init,
    event.init,
    time.init,
    controller.init,
    joystick.init,
    mouse.init,
    scrap.init,
]


quit_functions = [
    scrap.quit,
    mouse.quit,
    joystick.quit,
    controller.quit,
    display.quit,
]


def import_as_pygame():
    """
    Imports pygame_sdl2 as pygame, so that running the 'import pygame.whatever'
    statement will import renpy.pygame.whatever instead.
    """

    import warnings

    if "pygame" in sys.modules:
        warnings.warn("Pygame has already been imported, import_as_pygame may not work.", stacklevel=2)

    if "pygame_sdl2" in sys.modules:
        warnings.warn("Pygame SDL2 has already been imported, import_as_pygame may not work.", stacklevel=2)

    for name, mod in list(sys.modules.items()):
        if name.startswith("renpy.pygame"):
            suffix = name[len("renpy.pygame") :]
        else:
            continue

        sys.modules["pygame" + suffix] = mod
        sys.modules["pygame_sdl2" + suffix] = mod

    sys.modules["pygame.constants"] = constants
    sys.modules["pygame_sdl2.constants"] = constants


def get_sdl_byteorder():
    return LIL_ENDIAN


def get_sdl_version():
    return SDL_VERSION_TUPLE


def get_platform() -> str:
    return display.get_platform()


# We have new-style buffers, but not the pygame.newbuffer module.
HAVE_NEWBUF = False


# Generated by scripts/relative_imports.py, do not edit below this line.
import typing
