예제 #1
0
 def getCachedFont(self, bold, font, italic, size):
     fontSignature = (font, size, bold, italic)
     if fontSignature not in self.fonts:
         fontpath, size, bold, italic = pygame_sysfont.lookup_sys(font, size, bold, italic)
         font = sdl2.sdlttf.TTF_OpenFont(py3compat.to_bin(fontpath), size)
         assert font is not None, "Could not open font: %s" % sdl2.SDL_GetError()
         style = sdl2.sdlttf.TTF_STYLE_NORMAL
         if bold:
             style |= sdl2.sdlttf.TTF_STYLE_BOLD
         if italic:
             style |= sdl2.sdlttf.TTF_STYLE_ITALIC
         sdl2.sdlttf.TTF_SetFontStyle(font, style)
         self.fonts[fontSignature] = font
     return self.fonts[fontSignature]
예제 #2
0
 def setGraphicsMode(self, width, height, fullscreen=False, title="graphics.py"):
     self.windowWidth, self.windowHeight = width, height
     title = py3compat.to_bin(title)
     if fullscreen:
         self.window = sdl2.SDL_CreateWindow(title, sdl2.SDL_WINDOWPOS_UNDEFINED,
                                             sdl2.SDL_WINDOWPOS_UNDEFINED, 0, 0, sdl2.SDL_WINDOW_FULLSCREEN_DESKTOP)
     else:
         self.window = sdl2.SDL_CreateWindow(title, sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED,
                                             width, height, 0)
     assert self.window is not None, "Could not create window: %s" % sdl2.SDL_GetError()
     self.renderer = sdl2.SDL_CreateRenderer(self.window, -1, 0)
     assert self.renderer is not None, "Could not create renderer: %s" % sdl2.SDL_GetError()
     if fullscreen:
         assert sdl2.SDL_RenderSetLogicalSize(self.renderer, width,
                                              height) == 0, "Could not set logical size: %s" % sdl2.SDL_GetError()