<commit_before>#--
#	Rubygame -- Ruby code and bindings to SDL to facilitate game creation
#	Copyright (C) 2004-2007  <NAME>
#
#	This library is free software; you can redistribute it and/or
#	modify it under the terms of the GNU Lesser General Public
#	License as published by the Free Software Foundation; either
#	version 2.1 of the License, or (at your option) any later version.
#
#	This library 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
#	Lesser General Public License for more details.
#
#	You should have received a copy of the GNU Lesser General Public
#	License along with this library; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#++

module Rubygame

	# List of all Rubygame hardware event classes. *Do not modify!*
	SDL_EVENTS = [ActiveEvent, KeyDownEvent, KeyUpEvent,\
		MouseMotionEvent,MouseDownEvent,MouseUpEvent,JoyAxisEvent,\
		JoyBallEvent, JoyHatEvent,JoyDownEvent, JoyUpEvent,\
		ResizeEvent, QuitEvent]
  
	# The parent class for all event classes. You can make custom event classes,
  # if desired; inheriting this class is not necessary, but makes it easier
  # to check if an object is an event or not.
	class Event
		
		# Return a :symbol for the given key integer. For internal use.
		def self.key_symbol( integer )
			return Event.key_name(integer).downcase.gsub(" ","_").intern
		end
		
		# Converts a keyboard symbol (keysym) into a human-readable text string.
		# If either Shift key was being pressed, alphanumeric or punctuation keys 
		# will be made uppercase or alternate, based on U.S. keyboard layout.
		# E.g. "a" becomes "A", "1" becomes "!", and "/" becomes "?".
		def self.key2str( sym, mods )
			if (mods.include? K_LSHIFT) or (mods.include? K_RSHIFT)
				return (Rubygame::Key::KEY2UPPER[sym]\
				        or Rubygame::Key::KEY2ASCII[sym] or "")
			else
				return (Rubygame::Key::KEY2LOWER[sym]\
				        or Rubygame::Key::KEY2ASCII[sym] or "")
			end
		end
	end

	# Indicates that the Rubygame window has gained or lost focus from the
	# window manager.
	# 
	# This event has these attributes:
	# gain::  true if the window gained focus, and false if it lost focus.
	# state:: symbol indicating what type of focus was gained or lost: 
	#         :mouse::    the mouse entered/exited the window
	#         :keyboard:: the window gained or lost input focus
	#         :active::   the window was minimized/iconified.
	class ActiveEvent < Event
		attr_accessor :gain, :state
		def initialize(gain,state)
			@gain = gain
			@state = state 
		end
	end

	# Indicates that a keyboard key was pressed.
	# 
	# This event has these attributes:
	# string:: a human-readable string telling what key was pressed, or nil.
	#          See Event.key2str.
	# key::    the integer keysym for the key. These can be compared with the
	#          K_* constants in the Rubygame module, e.g. Rubygame::K_A.
	# mods::   an Array of zero or more keysyms indicating which modifier keys
	#          were being pressed when the key was pressed. You can compare
	#          with these constants in the Rubygame module:
	#          K_RSHIFT::    shift key (right side)
	#          K_LSHIFT::    shift key (left side)
	#          K_RCTRL::     ctrl key (right side)
	#          K_LCTRL::     ctrl key (left side)
	#          K_RALT::      alt key (right side)
	#          K_LALT::      alt key (left side)
	#          K_RMETA::     meta key (right side)
	#          K_LMETA::     meta key (left side)
	#          K_RSUPER::    super key, aka. Windows key (right side)
	#          K_LSUPER::    super key, aka. Windows key (left side)
	#          K_RALT::      alt key (right side)
	#          K_NUMLOCK::   num lock
	#          K_CAPSLOCK::  caps lock
	#          K_MODE::      mode key
	#          
	#          
	class KeyDownEvent < Event
		attr_accessor :string,:key,:mods

		# Create a new KeyDownEvent.
		# 
		# key::  a symbol representing the key pressed. (Symbol, required)
		# mods:: Array of modifier key symbols. (Array of Symbols, optional)
		# 
		# Example::
		#   KeyDownEvent.new( :a, [:shift] )     # uppercase A
		#   KeyDownEvent.new( :"." )             # period / dot
		#   KeyDownEvent.new( :"\"" )            # double-quote (")
		#   KeyDownEvent.new( :up, [:ctrl] )     # ctrl + up-arrow
		#   KeyDownEvent.new( :backspace )       # backspace key
		# 
		def initialize(key,mods=[])
			@key = key
			@mods = mods
			# @string = Event.key2str(key, mods) #a string or nil
		end
	end

	# Indicates that a keyboard key was released.
	# 
	# Please refer to KeyDownEvent for use and examples.
	class KeyUpEvent < Event
		attr_accessor :string,:key,:mods
		def initialize(key,mods)
			@key = key
			@mods = mods
			# @string = Event.key2str(key, mods) #a string or nil
		end
	end

	# Indicates that the mouse cursor moved.
	# 
	# This event has these attributes:
	# pos::       the new position of the cursor on the screen.
	# world_pos:: like _pos_, but converted into world coordinates based on the Scene's camera.
	#             By default, the same as _pos_, but may be set by the Scene.
	# rel::       the relative movement of the cursor since the last update, [x,y].
	# world_rel:: like _rel_, but converted into world coordinates based on the Scene's camera.
	#             By default, the same as _rel_, but may be set by the Scene.
	# buttons::   the mouse buttons that were being held during the movement,
	#             an Array of zero or more of these constants in module Rubygame
	#             (or the corresponding button number):
	#             MOUSE_LEFT::      1; left mouse button
	#             MOUSE_MIDDLE::    2; middle mouse button
	#             MOUSE_RIGHT::     3; right mouse button
  #             MOUSE_WHEELUP::   4; mouse wheel up (may also be a real button)
  #             MOUSE_WHEELDOWN:: 5; mouse wheel down (may also be a real button)
	class MouseMotionEvent < Event
		attr_accessor :pos,:rel,:buttons
		attr_accessor :world_pos, :world_rel
		def initialize(pos, rel, buttons, world_pos=nil, world_rel=nil)
			@pos, @rel, @buttons = pos, rel, buttons
			@world_pos = world_pos or pos
			@world_rel = world_rel or rel
		end
	end

	# Indicates that a mouse button was pressed.
	# 
	# This event has these attributes:
	# string::    string indicating the button that was pressed ("left","middle", or
	#             "right").
	# pos::       the position of the mouse cursor when the button was pressed,
	#             in the form [x,y].
	# world_pos:: like _pos_, but converted into world coordinates based on the Scene's camera.
	#             By default, the same as _pos_, but may be set by the Scene.
	# button::    the mouse button that was pressed; one of these constants in
	#             module Rubygame (or the corresponding button number):
	#             MOUSE_LEFT::      1; left mouse button
	#             MOUSE_MIDDLE::    2; middle mouse button
	#             MOUSE_RIGHT::     3; right mouse button
  #             MOUSE_WHEELUP::   4; mouse wheel up (may also be a real button)
  #             MOUSE_WHEELDOWN:: 5; mouse wheel down (may also be a real button)
	class MouseDownEvent < Event
		attr_accessor :string,:pos,:button
		attr_accessor :world_pos
		def initialize(pos, button, world_pos=nil)
			
			@pos = pos
			@world_pos = world_pos or pos
			
			if button.kind_of? Integer
				@button = button
				@string = Rubygame::Mouse::MOUSE2STR[button] #a string or nil
			elsif key.kind_of? String
				@button = Rubygame::Mouse::STR2MOUSE[key]
				if @button != nil
					@string = button
				else
					raise(ArgumentError,"First argument of MouseDownEvent.new() must be an Integer Mouse button indentifier (like MOUSE_LEFT) or a String (like \"left\"). Got %s (%s)"%[button,button.class])
				end<commit_msg>Reordered docs for Mouse events to put world_pos and world_rel last, to be consistent with argument order.<commit_after>#--
#	Rubygame -- Ruby code and bindings to SDL to facilitate game creation
#	Copyright (C) 2004-2007  <NAME>
#
#	This library is free software; you can redistribute it and/or
#	modify it under the terms of the GNU Lesser General Public
#	License as published by the Free Software Foundation; either
#	version 2.1 of the License, or (at your option) any later version.
#
#	This library 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
#	Lesser General Public License for more details.
#
#	You should have received a copy of the GNU Lesser General Public
#	License along with this library; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#++

module Rubygame

	# List of all Rubygame hardware event classes. *Do not modify!*
	SDL_EVENTS = [ActiveEvent, KeyDownEvent, KeyUpEvent,\
		MouseMotionEvent,MouseDownEvent,MouseUpEvent,JoyAxisEvent,\
		JoyBallEvent, JoyHatEvent,JoyDownEvent, JoyUpEvent,\
		ResizeEvent, QuitEvent]
  
	# The parent class for all event classes. You can make custom event classes,
  # if desired; inheriting this class is not necessary, but makes it easier
  # to check if an object is an event or not.
	class Event
		
		# Return a :symbol for the given key integer. For internal use.
		def self.key_symbol( integer )
			return Event.key_name(integer).downcase.gsub(" ","_").intern
		end
		
		# Converts a keyboard symbol (keysym) into a human-readable text string.
		# If either Shift key was being pressed, alphanumeric or punctuation keys 
		# will be made uppercase or alternate, based on U.S. keyboard layout.
		# E.g. "a" becomes "A", "1" becomes "!", and "/" becomes "?".
		def self.key2str( sym, mods )
			if (mods.include? K_LSHIFT) or (mods.include? K_RSHIFT)
				return (Rubygame::Key::KEY2UPPER[sym]\
				        or Rubygame::Key::KEY2ASCII[sym] or "")
			else
				return (Rubygame::Key::KEY2LOWER[sym]\
				        or Rubygame::Key::KEY2ASCII[sym] or "")
			end
		end
	end

	# Indicates that the Rubygame window has gained or lost focus from the
	# window manager.
	# 
	# This event has these attributes:
	# gain::  true if the window gained focus, and false if it lost focus.
	# state:: symbol indicating what type of focus was gained or lost: 
	#         :mouse::    the mouse entered/exited the window
	#         :keyboard:: the window gained or lost input focus
	#         :active::   the window was minimized/iconified.
	class ActiveEvent < Event
		attr_accessor :gain, :state
		def initialize(gain,state)
			@gain = gain
			@state = state 
		end
	end

	# Indicates that a keyboard key was pressed.
	# 
	# This event has these attributes:
	# string:: a human-readable string telling what key was pressed, or nil.
	#          See Event.key2str.
	# key::    the integer keysym for the key. These can be compared with the
	#          K_* constants in the Rubygame module, e.g. Rubygame::K_A.
	# mods::   an Array of zero or more keysyms indicating which modifier keys
	#          were being pressed when the key was pressed. You can compare
	#          with these constants in the Rubygame module:
	#          K_RSHIFT::    shift key (right side)
	#          K_LSHIFT::    shift key (left side)
	#          K_RCTRL::     ctrl key (right side)
	#          K_LCTRL::     ctrl key (left side)
	#          K_RALT::      alt key (right side)
	#          K_LALT::      alt key (left side)
	#          K_RMETA::     meta key (right side)
	#          K_LMETA::     meta key (left side)
	#          K_RSUPER::    super key, aka. Windows key (right side)
	#          K_LSUPER::    super key, aka. Windows key (left side)
	#          K_RALT::      alt key (right side)
	#          K_NUMLOCK::   num lock
	#          K_CAPSLOCK::  caps lock
	#          K_MODE::      mode key
	#          
	#          
	class KeyDownEvent < Event
		attr_accessor :string,:key,:mods

		# Create a new KeyDownEvent.
		# 
		# key::  a symbol representing the key pressed. (Symbol, required)
		# mods:: Array of modifier key symbols. (Array of Symbols, optional)
		# 
		# Example::
		#   KeyDownEvent.new( :a, [:shift] )     # uppercase A
		#   KeyDownEvent.new( :"." )             # period / dot
		#   KeyDownEvent.new( :"\"" )            # double-quote (")
		#   KeyDownEvent.new( :up, [:ctrl] )     # ctrl + up-arrow
		#   KeyDownEvent.new( :backspace )       # backspace key
		# 
		def initialize(key,mods=[])
			@key = key
			@mods = mods
			# @string = Event.key2str(key, mods) #a string or nil
		end
	end

	# Indicates that a keyboard key was released.
	# 
	# Please refer to KeyDownEvent for use and examples.
	class KeyUpEvent < Event
		attr_accessor :string,:key,:mods
		def initialize(key,mods)
			@key = key
			@mods = mods
			# @string = Event.key2str(key, mods) #a string or nil
		end
	end

	# Indicates that the mouse cursor moved.
	# 
	# This event has these attributes:
	# pos::       the new position of the cursor on the screen.
	# rel::       the relative movement of the cursor since the last update, [x,y].
	# buttons::   the mouse buttons that were being held during the movement,
	#             an Array of zero or more of these constants in module Rubygame
	#             (or the corresponding button number):
	#             MOUSE_LEFT::      1; left mouse button
	#             MOUSE_MIDDLE::    2; middle mouse button
	#             MOUSE_RIGHT::     3; right mouse button
  #             MOUSE_WHEELUP::   4; mouse wheel up (may also be a real button)
  #             MOUSE_WHEELDOWN:: 5; mouse wheel down (may also be a real button)
	# world_pos:: like _pos_, but converted into world coordinates based on the Scene's camera.
	#             By default, the same as _pos_, but may be set by the Scene.
	# world_rel:: like _rel_, but converted into world coordinates based on the Scene's camera.
	#             By default, the same as _rel_, but may be set by the Scene.
	class MouseMotionEvent < Event
		attr_accessor :pos,:rel,:buttons
		attr_accessor :world_pos, :world_rel
		def initialize(pos, rel, buttons, world_pos=nil, world_rel=nil)
			@pos, @rel, @buttons = pos, rel, buttons
			@world_pos = world_pos or pos
			@world_rel = world_rel or rel
		end
	end

	# Indicates that a mouse button was pressed.
	# 
	# This event has these attributes:
	# string::    string indicating the button that was pressed ("left","middle", or
	#             "right").
	# pos::       the position of the mouse cursor when the button was pressed,
	#             in the form [x,y].
	# button::    the mouse button that was pressed; one of these constants in
	#             module Rubygame (or the corresponding button number):
	#             MOUSE_LEFT::      1; left mouse button
	#             MOUSE_MIDDLE::    2; middle mouse button
	#             MOUSE_RIGHT::     3; right mouse button
  #             MOUSE_WHEELUP::   4; mouse wheel up (may also be a real button)
  #             MOUSE_WHEELDOWN:: 5; mouse wheel down (may also be a real button)
	# world_pos:: like _pos_, but converted into world coordinates based on the Scene's camera.
	#             By default, the same as _pos_, but may be set by the Scene.
	class MouseDownEvent < Event
		attr_accessor :string,:pos,:button
		attr_accessor :world_pos
		def initialize(pos, button, world_pos=nil)
			
			@pos = pos
			@world_pos = world_pos or pos
			
			if button.kind_of? Integer
				@button = button
				@string = Rubygame::Mouse::MOUSE2STR[button] #a string or nil
			elsif key.kind_of? String
				@button = Rubygame::Mouse::STR2MOUSE[key]
				if @button != nil
					@string = button
				else
					raise(ArgumentError,"First argument of MouseDownEvent.new() must be an Integer Mouse button indentifier (like MOUSE_LEFT) or a String (like \"left\"). Got %s (%s)"%[button,button.class])
				end
{'fraction_non_alphanumeric': 0.08704949996855148, 'fraction_numerical': 0.005660733379457827, 'mean_word_length': 2.7236533957845435, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '7352400', 'n_tokens_mistral': 5192, 'n_tokens_neox': 4848, 'n_words': 1925}