<commit_before>from rpython.rlib.rarithmetic import r_uint, intmask
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib.runicode import unicode_encode_utf_8
from rpython.rlib import jit

from rsdl import RSDL, RSDL_helper
import key_constants


# EventSensorConstants
RedButtonBit = 4
BlueButtonBit = 2
YellowButtonBit = 1

ShiftKeyBit = 1
CtrlKeyBit = 2
OptionKeyBit = 4
CommandKeyBit = 8

EventTypeNone = 0
EventTypeMouse = 1
EventTypeKeyboard = 2
EventTypeDragDropFiles = 3
EventTypeMenu = 4
EventTypeWindow = 5
EventTypeComplex = 6

EventKeyChar = 0
EventKeyDown = 1
EventKeyUp = 2

WindowEventMetricChange = 1
WindowEventClose = 2
WindowEventIconise = 3
WindowEventActivated = 4
WindowEventPaint = 5
WindowEventStinks = 6

MINIMUM_DEPTH = 8

class SqueakInterrupt(Exception):
    pass


class SDLDisplay(object):
    _attrs_ = ["window", "title", "renderer", "screen_texture",
               "width", "height", "depth", "screen_surface", "has_surface",
               "mouse_position", "button", "key", "interrupt_key", "_defer_updates",
               "_deferred_events", "bpp", "pitch", "highdpi"]

    def __init__(self, title, highdpi):
        self._init_sdl()
        self.title = title
        self.highdpi = highdpi
        SDLCursor.has_display = True
        self.window = lltype.nullptr(RSDL.WindowPtr.TO)
        self.renderer = lltype.nullptr(RSDL.RendererPtr.TO)
        self.screen_texture = lltype.nullptr(RSDL.TexturePtr.TO)
        self.screen_surface = lltype.nullptr(RSDL.Surface)
        self.has_surface = False
        self.mouse_position = [0, 0]
        self.interrupt_key = 15 << 8 # pushing all four meta keys, of which we support three...
        self.button = 0
        self.key = 0
        self.width = 0
        self.height = 0
        self.depth = 32
        self._deferred_events = []
        self._defer_updates = False

    def _init_sdl(self):
        from rpython.rlib.objectmodel import we_are_translated
        if we_are_translated():
            assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
        else:
            if RSDL.Init(RSDL.INIT_VIDEO) < 0:
                print RSDL.GetError()
                assert False

    def close(self):
        RSDL.Quit()

    def create_window_and_renderer(self, x, y, width, height):
        flags = RSDL.WINDOW_RESIZABLE
        if self.highdpi:
            flags |= RSDL.WINDOW_ALLOW_HIGHDPI
        self.window = RSDL.CreateWindow(self.title, x, y, width, height, flags)
        self.renderer = RSDL.CreateRenderer(self.window, -1,
                RSDL.RENDERER_ACCELERATED)

    def set_video_mode(self, w, h, d):
        if not (w > 0 and h > 0):
            return
        assert d in [1, 2, 4, 8, 16, 32]
        if d < MINIMUM_DEPTH:
            d = MINIMUM_DEPTH
        self.width = w
        self.height = h
        self.depth = d
        if self.window == lltype.nullptr(RSDL.WindowPtr.TO):<commit_msg>don't force an accellerated renderer, because the DUMMYVIDEODRIVER doesn't support that<commit_after>from rpython.rlib.rarithmetic import r_uint, intmask
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib.runicode import unicode_encode_utf_8
from rpython.rlib import jit

from rsdl import RSDL, RSDL_helper
import key_constants


# EventSensorConstants
RedButtonBit = 4
BlueButtonBit = 2
YellowButtonBit = 1

ShiftKeyBit = 1
CtrlKeyBit = 2
OptionKeyBit = 4
CommandKeyBit = 8

EventTypeNone = 0
EventTypeMouse = 1
EventTypeKeyboard = 2
EventTypeDragDropFiles = 3
EventTypeMenu = 4
EventTypeWindow = 5
EventTypeComplex = 6

EventKeyChar = 0
EventKeyDown = 1
EventKeyUp = 2

WindowEventMetricChange = 1
WindowEventClose = 2
WindowEventIconise = 3
WindowEventActivated = 4
WindowEventPaint = 5
WindowEventStinks = 6

MINIMUM_DEPTH = 8

class SqueakInterrupt(Exception):
    pass


class SDLDisplay(object):
    _attrs_ = ["window", "title", "renderer", "screen_texture",
               "width", "height", "depth", "screen_surface", "has_surface",
               "mouse_position", "button", "key", "interrupt_key", "_defer_updates",
               "_deferred_events", "bpp", "pitch", "highdpi"]

    def __init__(self, title, highdpi):
        self._init_sdl()
        self.title = title
        self.highdpi = highdpi
        SDLCursor.has_display = True
        self.window = lltype.nullptr(RSDL.WindowPtr.TO)
        self.renderer = lltype.nullptr(RSDL.RendererPtr.TO)
        self.screen_texture = lltype.nullptr(RSDL.TexturePtr.TO)
        self.screen_surface = lltype.nullptr(RSDL.Surface)
        self.has_surface = False
        self.mouse_position = [0, 0]
        self.interrupt_key = 15 << 8 # pushing all four meta keys, of which we support three...
        self.button = 0
        self.key = 0
        self.width = 0
        self.height = 0
        self.depth = 32
        self._deferred_events = []
        self._defer_updates = False

    def _init_sdl(self):
        from rpython.rlib.objectmodel import we_are_translated
        if we_are_translated():
            assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
        else:
            if RSDL.Init(RSDL.INIT_VIDEO) < 0:
                print RSDL.GetError()
                assert False

    def close(self):
        RSDL.Quit()

    def create_window_and_renderer(self, x, y, width, height):
        flags = RSDL.WINDOW_RESIZABLE
        if self.highdpi:
            flags |= RSDL.WINDOW_ALLOW_HIGHDPI
        self.window = RSDL.CreateWindow(self.title, x, y, width, height, flags)
        # https://wiki.libsdl.org/SDL_CreateRenderer#flags: "Note that providing
        # no flags gives priority to available SDL_RENDERER_ACCELERATED
        # renderers."
        self.renderer = RSDL.CreateRenderer(self.window, -1, 0)

    def set_video_mode(self, w, h, d):
        if not (w > 0 and h > 0):
            return
        assert d in [1, 2, 4, 8, 16, 32]
        if d < MINIMUM_DEPTH:
            d = MINIMUM_DEPTH
        self.width = w
        self.height = h
        self.depth = d
        if self.window == lltype.nullptr(RSDL.WindowPtr.TO):
{'fraction_non_alphanumeric': 0.09342388603611065, 'fraction_numerical': 0.016398873612721552, 'mean_word_length': 2.6220755848830235, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '573042', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1942, 'n_words': 479}