Don't are working Window Event

Issue #79 invalid
Paul Rodrigues created an issue

Hello, i have a problem on Window Event, don't are working nothing Window Event.

MyScript Example:

from sdl2 import *

class Window(object):

def __init__(self, title="Window", height=600, width=600, background=( 0, 0, 0)):
        global isClosed

        # Init SDL Everything
        if SDL_Init(SDL_INIT_EVERYTHING) != 0:
            print("Erro Init SDL")

        #Create Window
        self.window = SDL_CreateWindow(title.encode(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height,
            SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)

        #Check is Window None
        if self.window is None:
            print("Error Init Window SDL")

        #Create Renderer
        self.renderer = SDL_CreateRenderer(self.window, -1, SDL_RENDERER_ACCELERATED)

        #Check is Window Renderer
        if self.renderer is None:
            print("Error Create Renderer")

        #Creating Context Opengl
        self.context = SDL_GL_CreateContext(self.window)
        SDL_GL_MakeCurrent(self.window, self.context)

        #Check Context
        if self.context is None:
            print("Error Creating Context Opengl")

        #Set Closed
        isClosed = False

        #Set Viewport
        self.width = width
        self.height = height
        self.__viewportUpdate()

        #Calling Start
        self.Start()

        #Initing Main Threading
        while isClosed is False:
            #Selection Events
            if SDL_PollEvent(self.event) != 0:
                if self.event.type == SDL_QUIT:
                    print("Quit Window %s" % title)
                    isClosed = True
                    break


                #DONT WORK
                if self.event.window.type == SDL_WINDOWEVENT_MOVED:
                    print("MOVED")

                #DONT WORK
                if self.event.window.type == SDL_WINDOWEVENT_SIZE_CHANGED:
                    SDL_GetWindowSize(self.window, self.width, self.height)
                    print("Resized")

            #Selection Functions Execute
            glClearColor(background[0], background[1], background[2], 0)
            glClear(GL_COLOR_BUFFER_BIT)

            #Calling Update
            self.Update()

            SDL_GL_SwapWindow(self.window)

        SDL_DestroyRenderer(self.renderer)
        SDL_GL_DeleteContext(self.context)
        SDL_DestroyWindow(self.window)
        SDL_Quit()

Well I do not know if it's a bug in pysdl, but in C ++ code that works perfectly

Comments (2)

  1. Marcus von Appen repo owner

    Window events are encoded in the event field of the SDL_WindowEvent, not in type:

    if self.event.window.event == SDL_WINDOWEVENT_MOVED:
        print("MOVED")
    if self.event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED:
        ...
    
  2. Log in to comment