<commit_before># -*- coding: utf-8 -*-

require 'dxruby_sdl/window/fpstimer'
require 'set'

module DXRubySDL
  module Window
    module_function

    def width
      @width ||= DEFAULTS[:width]
      return @width
    end

    def height
      @height ||= DEFAULTS[:height]
      return @height
    end

    def scale
      @scale ||= DEFAULTS[:scale]
      return @scale
    end

    def caption
      return SDL::WM.caption[0]
    end

    def caption=(val)
      SDL::WM.set_caption(val, '')
    end

    def fps=(val)
      FPSTimer.instance.fps = val
    end

    def loop(&block)
      timer = FPSTimer.instance
      timer.reset

      Kernel.loop do
        timer.wait_frame do
          while (event = SDL::Event.poll)
            case event
            when SDL::Event::Quit
              exit
            end
          end

          screen.fill_rect(0, 0, width, height, DEFAULTS[:background_color])

          yield

          screen.flip

          Input.send(:store_last_state)
        end
      end
    end

    def draw(x, y, image, z = 0)
      if z != 0
        raise NotImplementedError, 'Window.draw(x, y, image, z != 0)'
      end
      screen.put(image._surface, x, y)
    end

    def draw_ex(x, y, image, hash = {})
      if hash[:z] && hash[:z] != 0
        raise NotImplementedError, 'Window.draw_ex(x, y, image, z: != 0)'
      end
      option = {
        angle: 0,
        scale_x: 1,
        scale_y: 1,
      }.merge(hash)
      SDL::Surface.transform_draw(image._surface, screen,
                                  option[:angle], option[:scale_x],
                                  option[:scale_y],
                                  0, 0, x, y,
                                  SDL::Surface::TRANSFORM_SAFE)
    end

    def draw_font(x, y, string, font, hash = {})
      if string.empty?
        return
      end
      if hash[:color]
        r, g, b = *hash[:color]
      else
        r, g, b = 255, 255, 255<commit_msg>use SDL::Surface.transform_blit in Window.draw_ex.<commit_after># -*- coding: utf-8 -*-

require 'dxruby_sdl/window/fpstimer'
require 'set'

module DXRubySDL
  module Window
    module_function

    def width
      @width ||= DEFAULTS[:width]
      return @width
    end

    def height
      @height ||= DEFAULTS[:height]
      return @height
    end

    def scale
      @scale ||= DEFAULTS[:scale]
      return @scale
    end

    def caption
      return SDL::WM.caption[0]
    end

    def caption=(val)
      SDL::WM.set_caption(val, '')
    end

    def fps=(val)
      FPSTimer.instance.fps = val
    end

    def loop(&block)
      timer = FPSTimer.instance
      timer.reset

      Kernel.loop do
        timer.wait_frame do
          while (event = SDL::Event.poll)
            case event
            when SDL::Event::Quit
              exit
            end
          end

          screen.fill_rect(0, 0, width, height, DEFAULTS[:background_color])

          yield

          screen.flip

          Input.send(:store_last_state)
        end
      end
    end

    def draw(x, y, image, z = 0)
      if z != 0
        raise NotImplementedError, 'Window.draw(x, y, image, z != 0)'
      end
      screen.put(image._surface, x, y)
    end

    def draw_ex(x, y, image, hash = {})
      if hash[:z] && hash[:z] != 0
        raise NotImplementedError, 'Window.draw_ex(x, y, image, z: != 0)'
      end
      option = {
        angle: 0,
        scale_x: 1,
        scale_y: 1,
      }.merge(hash)
      SDL::Surface.transform_blit(image._surface, screen,
                                  option[:angle], option[:scale_x],
                                  option[:scale_y],
                                  0, 0, x, y,
                                  SDL::Surface::TRANSFORM_SAFE)
    end

    def draw_font(x, y, string, font, hash = {})
      if string.empty?
        return
      end
      if hash[:color]
        r, g, b = *hash[:color]
      else
        r, g, b = 255, 255, 255
{'fraction_non_alphanumeric': 0.11161731207289294, 'fraction_numerical': 0.01164262212098203, 'mean_word_length': 1.5188017845761632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1040101', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1217, 'n_words': 316}