view pytouhou/lib/sdl.pxd @ 792:11bc22bad1bf default tip

python: Replace the image crate with png We weren’t using any of its features anyway, so the png crate is exactly what we need, without the many heavy dependencies of image. https://github.com/image-rs/image-png/pull/670 will eventually make it even faster to build.
author Link Mauve <linkmauve@linkmauve.fr>
date Sat, 17 Jan 2026 22:22:25 +0100
parents 7e940ebeb5fd
children
line wrap: on
line source

# -*- encoding: utf-8 -*-
##
## Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##

from pytouhou.lib._sdl cimport *
cimport pytouhou.lib.gui as gui


cdef SDL_GLattr GL_CONTEXT_MAJOR_VERSION
cdef SDL_GLattr GL_CONTEXT_MINOR_VERSION
cdef SDL_GLattr GL_CONTEXT_PROFILE_MASK
cdef SDL_GLattr GL_DOUBLEBUFFER
cdef SDL_GLattr GL_RED_SIZE
cdef SDL_GLattr GL_GREEN_SIZE
cdef SDL_GLattr GL_BLUE_SIZE
cdef SDL_GLattr GL_DEPTH_SIZE

cdef SDL_GLprofile GL_CONTEXT_PROFILE_CORE
cdef SDL_GLprofile GL_CONTEXT_PROFILE_COMPATIBILITY
cdef SDL_GLprofile GL_CONTEXT_PROFILE_ES

cdef SDL_WindowFlags WINDOWPOS_CENTERED
cdef SDL_WindowFlags WINDOW_OPENGL
cdef SDL_WindowFlags WINDOW_SHOWN
cdef SDL_WindowFlags WINDOW_RESIZABLE

#TODO: should be SDL_Scancode, but Cython doesn’t allow enum for array indexing.
cdef long SCANCODE_Z
cdef long SCANCODE_X
cdef long SCANCODE_P
cdef long SCANCODE_LSHIFT
cdef long SCANCODE_UP
cdef long SCANCODE_DOWN
cdef long SCANCODE_LEFT
cdef long SCANCODE_RIGHT
cdef long SCANCODE_LCTRL
cdef long SCANCODE_ESCAPE
cdef long SCANCODE_HOME

cdef SDL_WindowEventID WINDOWEVENT_RESIZED

cdef SDL_EventType KEYDOWN
cdef SDL_EventType QUIT
cdef SDL_EventType WINDOWEVENT

cdef const Uint8 *keyboard_state


cdef class Window(gui.Window):
    cdef SDL_Window *window
    cdef SDL_GLContext context
    cdef SDL_Renderer *renderer
    cdef bint is_fullscreen

    # The following functions are there for the pure SDL backend.
    cdef bint create_renderer(self, Uint32 flags) except True
    cpdef bint render_clear(self) except True
    cpdef bint render_copy(self, Texture texture, Rect srcrect, Rect dstrect) except True
    cpdef bint render_copy_ex(self, Texture texture, Rect srcrect, Rect dstrect, double angle, bint flip) except True
    cpdef bint render_set_clip_rect(self, Rect rect) except True
    cpdef bint render_set_viewport(self, Rect rect) except True
    cdef Texture create_texture_from_surface(self, Surface surface)


cdef class Texture:
    cdef SDL_Texture *texture

    cpdef set_color_mod(self, Uint8 r, Uint8 g, Uint8 b)
    cpdef set_alpha_mod(self, Uint8 alpha)
    cpdef set_blend_mode(self, SDL_BlendMode blend_mode)


cdef class Rect:
    cdef SDL_Rect rect


cdef class Color:
    cdef SDL_Color color


cdef class Surface:
    cdef bytes data
    cdef SDL_Surface *surface

    cdef bint blit(self, Surface other) except True
    cdef void set_alpha(self, Surface alpha_surface) nogil


cdef class Font:
    cdef TTF_Font *font

    cdef Surface render(self, unicode text)


cdef bint init(Uint32 flags) except True
cdef bint ttf_init() except True
cdef bint gl_set_attribute(SDL_GLattr attr, int value) except True
cdef Surface create_rgba_surface(bytes pixels, int width, int height)
cdef Uint32 get_ticks() nogil
cdef void delay(Uint32 ms) nogil
cpdef bint show_simple_message_box(unicode message) except True