Mundo Maker
¡Bienvenid@ a Mundo Maker!

¿Quieres aprender todo sobre el RPG Maker?



Regístrate y forma parte de Mundo Maker.

[Ayuda] Problema con ShowCursor (module Mouse)

Ver el tema anterior Ver el tema siguiente Ir abajo

RPG Maker XP [Ayuda] Problema con ShowCursor (module Mouse)

Mensaje por Wecoc el 2015-08-04, 05:11

Estoy usando un script de Mouse y tengo un problema con el cursor (hablo de la flechita del ratón, no del cursor de ventana del maker).
El cursor en sí se ve bien; es el cursor por defecto y no quiero que tenga ningún Sprite personalizado. Pero al igual que pasa sin el script de Mouse, si no mueves el ratón durante un segundo, desaparece hasta que lo vuelves a mover... y necesito que se mantenga visible siempre.

He intentado arreglar el script de Mouse pero creo que nisiquiera está configurado ahí porque con todos los scripts de Mouse (con cursor por defecto) pasa lo mismo. Creo que es algo de Win32API, por la prioridad/tipo de ventana del RGSS Player o alguna mandanga así.

¿Alguien podría hacerme un script para XP que lo solucione, porfa? O si hay alguna dll que lo solucione o algo... Mis conocimientos con Win32API son nulos.

Entonces si es eso creo que no importa mucho en éste caso, pero igualmente pongo el script de Mouse que uso para que podáis probarlo.
Es un edit del Glitchfinder's Mouse Input Module:

Scripts:

Código:
#==============================================================================
# ** Glitchfinder's Mouse Input Module
#    Version 3.00 # (Edit)
#------------------------------------------------------------------------------
#  This script helps scripters to use the mouse, without being limited by the
#  default Input Module.
#==============================================================================

#==============================================================================
# * Method List
#==============================================================================
#  Mouse.update
#    Updates mouse input. Calls to this method are not necessary unless the
#    default Input module is not being updated.
#
#  Mouse.press?(key)
#    Determines whether the button determined by key is currently being
#    pressed. If the button is being pressed, returns true. If not, returns
#    false.
#
#  Mouse.trigger?(key)
#    Determines whether the button determined by key is being pressed again.
#    "Pressed again" is seen as time having passed between the button being not
#    pressed and being pressed. If the button is being pressed, returns true.
#    If not, returns false.
#
#  Mouse.repeat?(key)
#    Determines whether the button determined by key is being pressed again.
#    Unlike trigger?(), this takes into account the repeat input of a button
#    being held down continuously. If the button is being pressed, returns
#    true. If not, returns false.
#
#  Mouse.release?(key)
#    Determines whether the button determined by key has just been released. If
#    the button has been released, returns true. If not, returns false.
#
#  Mouse.in_screen?
#    This method returns true if the mouse is over the game window, and false if
#    not. (The function returns false if the mouse is currently over the window
#    title or edge, instead of the client area)
#
#  Mouse.pos
#    This method returns an array containing the current mouse position, in the
#    following format: [x, y]
#
#  Mouse.x
#    Returns the current mouse x position. If the mouse is to the left of the
#    game screen, returns 0. If the mouse is to the right of the game window,
#    returns the width of the window minus one.
#
#  Mouse.y
#    Returns the current mouse y position. If the mouse is above the game
#    screen, returns 0. If the mouse is below the game window, returns the
#    height of the window minus one.
#
#  Mouse.dragging?
#  Mouse.dragging?(button)
#    Checks to see if the mouse is currently dragging. (The primary button is
#    being held while the mouse moves across the screen) Returns true if the
#    mouse is dragging, false if the mouse is not. If an argument is supplied,
#    this will check the dragging status of the button in question. Otherwise,
#    the check will supply the status of the primary mouse key.
#
#  Mouse.drag_rect
#  Mouse.drag_rect(button)
#    Checks to see if the mouse is dragging, and returns the rect of the drag
#    area. If the mouse is not currently dragging, returns an empty rect. If
#    the mouse is dragging, returns a screen rect that covers the current drag
#    area. If an argument is supplied, this will check the dragging status of
#    the button in question. Otherwise, the check will supply the status of the
#    primary mouse key.
#
#  Mouse.drag_coor
#  Mouse.drag_coor(button)
#    Checks to see if the mouse is dragging, and returns the starting
#    coordinates. If the mouse is not dragging, returns the current mouse
#    position.  If an argument is supplied, this will check the dragging status
#    of the button in question. Otherwise, the check will supply the status of
#    the primary mouse key.The return data is in the following format: [x, y]
#
#  Mouse.in_area?(Rect)
#  Mouse.in_area?(x, y, width, height)
#    Determines if the mouse is within the specified area. You can input either
#    a rect or the x, y, width, and height of the area. If the mouse is
#    currently within that area, returns true. Otherwise, returns false.
#
#  Mouse.hide_cursor
#
#  Mouse.show_cursor
#
#  Mouse.double_click?(button)
#    Returns true if the specified button is pressed twice within a short time.
#
#  Mouse.last_click_x(button)
#  Mouse.last_click_y(button)
#    Returns the coordinate of the last location at which the supplied mouse
#    button was pressed.
#
#  Mouse.set_x(coordinate)
#  Mouse.set_y(coordinate)
#  Mouse.set_pos(x, y)
#    Sets the mouse location.
#
#==============================================================================
# *Glitchfinder's Advice
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script is meant for people with a medium or advanced level of scripting
#  knowledge and ability, or for those using scripts that require this module.
#==============================================================================
# * License
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script is licensed under the MIT License:
#
#  Copyright (c) 2010-2014 Sean Porter (Glitchfinder) <glitchkey@gmail.com>
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.
#==============================================================================
 
#==============================================================================
# ** Mouse
#------------------------------------------------------------------------------
#  This module performs mouse input processing
#==============================================================================
 
module Mouse
  #--------------------------------------------------------------------------
  # * Declare Module Variables
  #--------------------------------------------------------------------------
  # Declare API calls
  @metrics       = Win32API.new('user32', 'GetSystemMetrics', 'i' , 'i')
  @getCursorPos  = Win32API.new('user32', 'GetCursorPos'    , 'p' , 'v')
  @getWindowRect = Win32API.new('user32', 'GetWindowRect'   , 'lp', 'v')
  @showCursor    = Win32API.new('user32', 'ShowCursor'      , 'i' , 'i')
  @setCursorPos  = Win32API.new('user32', 'SetCursorPos'    , 'ii', 'i')
  # Get window thread
  findWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
  @window      = findWindowEx.call(0, 0, "RGSS Player", 0)
  
  $mouse_sprite = Sprite.new
  $mouse_sprite.z = 1000000000
  $mouse_sprite.bitmap = Bitmap.new(1, 1)
  
  # Set up double click
  @double_click         = Array.new(7, false)
  @double_click_counter = Array.new(7, 0)
  @double_click_frames  = 20
  @double_click_pixels  = 4
  # Set up drag
  @mouse_drag  = Array.new(7) {Array.new([false, 0, 0, 0, 0])}
  @drag_pixels = 4
  # Set up last click
  @last_click_x = Array.new(7, 0)
  @last_click_y = Array.new(7, 0)
  # Set mouse to visible
  @hidden = false
  #--------------------------------------------------------------------------
  # * Mouse Keys
  #--------------------------------------------------------------------------
  SWAPBUTTON = @metrics.call(23) == 0 ? false : true # Buttons Swapped
  LBUTTON    = 0x01 # Physical Left Button
  RBUTTON    = 0x02 # Physical Right Button
  MBUTTON    = 0x04 # Middle Mouse Button
  XBUTTON1   = 0x05 # X1 Mouse Button
  XBUTTON2   = 0x06 # X2 Mouse Button
  PRIMARY    = !SWAPBUTTON ? 0x01 : 0x02 # Primary Mouse Button
  SECONDARY  = !SWAPBUTTON ? 0x02 : 0x01 # Secondary Mouse Button
  #--------------------------------------------------------------------------
  # * Special Keys
  #--------------------------------------------------------------------------
  ANYKEY     = 0x100 # Any Key
  ANYBUTTON  = [0x01, 0x02, 0x04, 0x05, 0x06]
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def self.update
    # Update Sprite
    $mouse_sprite.update
    # create blank rect
    rect = '0' * 16
    # Get window rect
    @getWindowRect.call(@window, rect)
    # Unpack rect data
    left, top, right, bottom = rect.unpack("LLLL")
    # Get window coordinates
    # @window_x = left
    # @window_y = top
    @window_x = left + @metrics.call(5) + @metrics.call(45)
    @window_y = top + @metrics.call(6) + @metrics.call(46) + @metrics.call(4)
    # Get window dimensions
    @window_width  = right  - left
    @window_width -= (@metrics.call(5) + @metrics.call(45)) * 2
    @window_height = bottom - top
    @window_height -= @metrics.call(4)
    # If the game is not fullscreen
    cursor_position = '0' * 8
    # Get cursor position
    @getCursorPos.call(cursor_position)
    # Unpack cursor position data
    @mouse_x, @mouse_y = cursor_position.unpack('LL')
    # Set cursor position relative to the window
    @mouse_x -= @window_x
    @mouse_y -= @window_y
    # If the cursor is not over the window
    if (@mouse_x < 0 || @mouse_y < 0 || @mouse_x >= @window_width ||
      @mouse_y >= @window_height)
      # Set the mouse to off screen
      @in_screen = false
    # If the cursor is over the window
    else
      # Set the mouse to on screen
      @in_screen = true
    end
    # Clear double click flags
    @double_click = Array.new(6, false)
    # Iterate the mouse buttons
    for i in ANYBUTTON
      # Set up mouse deviance
      x_deviance = (@last_click_x[i] - @mouse_x).abs
      y_deviance = (@last_click_y[i] - @mouse_y).abs
      # Correct mouse deviance
      x_deviance *= -1 if x_deviance < 0
      y_deviance *= -1 if y_deviance < 0
      # If the button is triggered
      if Keys.trigger?(i)
        # Set allowed deviance
        deviance = @double_click_pixels
        # Get the double click counter
        counter = @double_click_counter[i]
        # If double click counter is active and deviance is within allowed range
        if (counter > 0 && x_deviance <= deviance && y_deviance <= deviance)
          # Set double click flag to true
          @double_click[i] = true
        # If double click counter is not running or the cursor is out of bounds
        else
          # Reset double click counter
          @double_click_counter[i] = @double_click_frames
        end
        # Set drag start coordinates
        @mouse_drag[i][1] = @mouse_x
        @mouse_drag[i][2] = @mouse_y
        # Set last click coordinates
        @last_click_x[i]  = @mouse_x
        @last_click_y[i]  = @mouse_y
      # If the button is pressed
      elsif Keys.press?(i)
        # If the mouse has moved beyond the required deviance
        if x_deviance >= @drag_pixels && y_deviance >= @drag_pixels
          # Set the mouse to dragging
          @mouse_drag[i][0] = true
        end
        # If the mouse is dragging
        if @mouse_drag[i][0] == true
          # Set current dragging corrdinates
          @mouse_drag[i][3] = @mouse_x
          @mouse_drag[i][4] = @mouse_y
        end
      # If the button is released
      else
        # Reset drag data
        @mouse_drag[i][0] = false
        @mouse_drag[i][1] = 0
        @mouse_drag[i][2] = 0
        @mouse_drag[i][3] = 0
        @mouse_drag[i][4] = 0
      end
      # If the double click counter is running
      if @double_click_counter[i] > 0
        # Cycle the double click counter down one frame
        @double_click_counter[i] -= 1
      end
    end
    $mouse_sprite.x = Mouse.x
    $mouse_sprite.y = Mouse.y
    # Set hidden feature
    if !$game_temp.nil?
      Mouse_Sprite.id = $game_temp.mouse_cursor_id
      if $game_temp.mouse_cursor_id > 0
        @hidden = true
      else
        @hidden = false
      end
    end
    # If the cursor is in the screen and it is set to hidden
    if @in_screen && @hidden
      # Hide the mouse cursor
      hide_cursor
    # If the cursor is not set to hidden or is not on screen
    else
      # Set the mouse to visible
      show_cursor
    end
  end
  #--------------------------------------------------------------------------
  # * Get Key Pressed State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.press?(key)
    # Return key pressed state
    return Keys.press?(key)
  end
  #--------------------------------------------------------------------------
  # * Get Key Triggered State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.trigger?(key)
    # Return key triggered state
    return Keys.trigger?(key)
  end
  #--------------------------------------------------------------------------
  # * Get Key Repeated State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.repeat?(key)
    # Return key repeated state
    return Keys.repeat?(key)
  end
  #--------------------------------------------------------------------------
  # * Get Key Released State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.release?(key)
    # Return key released state
    return Keys.release?(key)
  end
  #--------------------------------------------------------------------------
  # * Is the Mouse on Screen?
  #--------------------------------------------------------------------------
  def self.in_screen?
    # Return mouse in screen flag
    return @in_screen
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Position
  #--------------------------------------------------------------------------
  def self.pos
    # Return mouse position array
    return [@mouse_x, @mouse_y]
  end
  #--------------------------------------------------------------------------
  # * Get Mouse X Position
  #--------------------------------------------------------------------------
  def self.x
    # Return mouse x position
    return @mouse_x
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Y Position
  #--------------------------------------------------------------------------
  def self.y
    # Return mouse y position
    return @mouse_y
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Dragging Boolean
  #     args : the mouse button to check
  #--------------------------------------------------------------------------
  def self.dragging?(*args)
    # Get the button
    if args.is_a?(NilClass) || args[0].is_a?(NilClass)
      button = PRIMARY
    else
      button = args[0]
    end
    # Validate button
    return false if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
    # Return mouse dragging flag
    return @mouse_drag[button][0]
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Drag Rect
  #     args : the mouse button to check
  #--------------------------------------------------------------------------
  def self.drag_rect(*args)
    # Get the button
    if args.is_a?(NilClass) || args[0].is_a?(NilClass)
      button = PRIMARY
    else
      button = args[0]
    end
    # Validate button
    if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
      return Rect.new(0, 0, 0, 0)
    end
    # Return blank rect if the mouse is not dragging
    return Rect.new(0, 0, 0, 0) if !@mouse_drag[i][0]
    # Get drag rect coordinates
    x = @mouse_drag[i][1]
    y = @mouse_drag[i][2]
    # Correct drag rect coordinates
    x = @mouse_drag[i][3] if x > @mouse_drag[i][3]
    y = @mouse_drag[i][4] if y > @mouse_drag[i][4]
    # Get drag rect dimensions
    width  = @mouse_drag[i][1]
    height = @mouse_drag[i][2]
    # Correct drag rect dimensions
    width  = @mouse_drag[i][3] if x == width
    height = @mouse_drag[i][4] if y == height
    width  -= x
    height -= y
    # Return drag rect
    return Rect.new(x, y, width, height)
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Drag Coordinates
  #     args : the mouse button to check
  #--------------------------------------------------------------------------
  def self.drag_coor(*args)
    # Get the button
    if args.is_a?(NilClass) || args[0].is_a?(NilClass)
      button = PRIMARY
    else
      button = args[0]
    end
    # Validate button
    if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
      return [@mouse_x, @mouse_y] if (button < 1 || button > 6)
    end
    # Return current coordinates if the mouse isn't dragging
    return [@mouse_x, @mouse_y] if !@mouse_drag[button][0]
    # return mouse drag starting coordinates
    return [@mouse_drag[button][1], @mouse_drag[button][2]]
  end
  #--------------------------------------------------------------------------
  # * Get Mouse in Area Flag
  #--------------------------------------------------------------------------
  def self.in_area?(*args)
    # return false if the mouse is not on screen
    return false if !@in_screen
    # If the argument is a rect
    if args[0].is_a?(Rect)
      # Return if the mouse is within the rect
      return (@mouse_x >= args[0].x && @mouse_y >= args[0].y &&
        @mouse_x < args[0].x + args[0].width &&
        @mouse_y < args[0].y + args[0].height)
    # If the arguments are separate
    else
      # Return if the mouse is within the specified coordinates
      return (@mouse_x >= args[0] && @mouse_y >= args[1] &&
        @mouse_x < args[0] + args[2] && @mouse_y < args[1] + args[3])
    end
  end
  
  def self.over_sprite?(sprite)
    return self.in_area?(sprite.x, sprite.y,
    sprite.bitmap.width, sprite.bitmap.height)
  end
  
  def self.inside_window?(window)
    return self.in_area?(window.x, window.y,
    window.width, window.height)
  end  

  def self.result_mouse_gesture(result)
    Mouse.save_gesture
    return
  end

  def self.update_mouse_gestures
    # return if forbid_mouse_gestures
    Mouse.clear_mouse_gesture if @mouse_gesture.nil?
    $game_temp.temp_gesture = {} if !$game_temp.temp_gesture
        
    if Mouse.dragging?
      point = @mouse_gesture[0][@mouse_gesture[4]]
      if point == nil ||  point.disposed?
        @mouse_gesture[0][@mouse_gesture[4]] = Sprite.new
      end
      @mouse_gesture[0][@mouse_gesture[4]].x = @mouse_gesture[4] == 0 ?
      Mouse.drag_coor[0] : Mouse.x
      @mouse_gesture[0][@mouse_gesture[4]].y = @mouse_gesture[4] == 0 ?
      Mouse.drag_coor[1] : Mouse.y
      Mouse.recog_mouse_gesture # if @mouse_gesture[6] == Mouse.pos
      @mouse_gesture[6] = Mouse.pos if @mouse_gesture[6] != Mouse.pos
      @mouse_gesture[4] += 1
    else
      if !@mouse_gesture[0].empty?
        @mouse_gesture[1].each_with_index { |s,i|
        @mouse_gesture[1][i-1] = nil if i > 0 && s == @mouse_gesture[1][i-1] }
        Mouse.result_mouse_gesture(@mouse_gesture[1].compact)
        @mouse_gesture[0].each {|i| i.dispose }
        @mouse_gesture[2].each {|i| i.dispose }
        Mouse.clear_mouse_gesture
      end
    end
  end
  
  def self.save_gesture
    return if @mouse_gesture[2][0].nil?
    index = ($game_temp.saved_index || 1).abs
    $game_temp.temp_gesture[index] = @mouse_gesture[2][0].bitmap.clone
  end
  
  def self.clear_mouse_gesture()
    @mouse_gesture = [[],[],[],0,0,0]
  end
  
  def self.draw_mouse_line(start_x, start_y, end_x, end_y, color, width=1)
    point = @mouse_gesture[2][0]
    if point == nil || point.disposed?
      @mouse_gesture[2][0] = Sprite.new
      @mouse_gesture[2][0].bitmap = Bitmap.new(*Resolution.window_size)
      @mouse_gesture[2][0].z = 9999
    end
    distance = (start_x - end_x).abs + (start_y - end_y).abs
    (1..distance).each do |i|
      x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
      y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
      @mouse_gesture[2][0].bitmap.fill_rect(x, y, width, width, color)
      index = ($game_temp.saved_index || 1).abs
      $game_temp.temp_gesture[index.to_s] = [] if !$game_temp.temp_gesture[index.to_s]
      $game_temp.temp_gesture[index.to_s] << [x,y]
    end
    @mouse_gesture[3] += 1
  end
  
  def self.recog_mouse_gesture
    awal = @mouse_gesture[0][@mouse_gesture[5]]
    akhir = @mouse_gesture[0][@mouse_gesture[4]]
    
    sensitivity = 1
    
    draw_mouse_line(awal.x, awal.y, akhir.x, akhir.y, Color.new(0, 0, 0, 0), 3)
    
    if awal.x - akhir.x > sensitivity && (awal.y - akhir.y).abs < sensitivity
      @mouse_gesture[1] << 'left'
    end
    if awal.x - akhir.x < -sensitivity && (awal.y - akhir.y).abs < sensitivity
      @mouse_gesture[1] << 'right'
    end
    if awal.y - akhir.y > sensitivity && (awal.x - akhir.x).abs < sensitivity
      @mouse_gesture[1] << 'up'
    end
    if awal.y - akhir.y < -sensitivity && (awal.x - akhir.x).abs < sensitivity
      @mouse_gesture[1] << 'down'
    end
    if awal.x - akhir.x > sensitivity && awal.y - akhir.y > sensitivity
      @mouse_gesture[1] << 'upleft'
    end
    if awal.x - akhir.x < -sensitivity && awal.y - akhir.y > sensitivity
      @mouse_gesture[1] << 'upright'
    end
    if awal.x - akhir.x > sensitivity && awal.y - akhir.y < -sensitivity
      @mouse_gesture[1] << 'downleft'
    end
    if awal.x - akhir.x < -sensitivity && awal.y - akhir.y < -sensitivity
      @mouse_gesture[1] << 'downright'
    end
    @mouse_gesture[5] = @mouse_gesture[4]
  end
  
  Get_Message = Win32API.new('User32','GetMessage','plll','l')
  Point = Struct.new(:x, :y)
  Param = Struct.new(:x, :y, :scroll)
  Message = Struct.new(:message, :wparam, :lparam, :pt)
  
  def self.scroll
    msg= "\0" * 32
    Get_Message.call(msg,0,0,0)
    r = wmcallback(unpack_msg(msg))
    return r if !r.nil?
  end
  
  def self.word2signed_short(value)
    return value if (value & 0x8000) == 0
    return -1 * ((~value & 0x7fff)+1)
  end

  def self.hiword(dword)
    return ((dword & 0xffff0000) >> 16) & 0x0000ffff
  end
  
  def self.wmcallback(msg)
    return unless msg.message == 0x0000020A
    param = Param.new
    param.scroll = Mouse.word2signed_short(Mouse.hiword(msg.wparam))
    return (param.scroll < 0 ? -1 : 1)
  end
  
  def self.unpack_dword(buffer,offset=0)
    ret = buffer[offset+0] & 0x000000ff
    ret |= (buffer[offset+1] << (8*1)) & 0x0000ff00
    ret |= (buffer[offset+2] << (8*2)) & 0x00ff0000
    ret |= (buffer[offset+3] << (8*3)) & 0xff000000
    return ret
  end
  
  def self.unpack_msg(buffer)
    msg = Message.new
    msg.pt = Point.new
    msg.message = Mouse.unpack_dword(buffer,4 * 1)
    msg.wparam = Mouse.unpack_dword(buffer,4 * 2)
    msg.lparam = Mouse.unpack_dword(buffer,4 * 3)
    msg.pt.x = Mouse.unpack_dword(buffer,4 * 5)
    msg.pt.y = Mouse.unpack_dword(buffer,4 * 6)
    return msg
  end
  
  #--------------------------------------------------------------------------
  # * Hide Cursor
  #--------------------------------------------------------------------------
  def self.hide_cursor
    # Hide the mouse cursor
    success = @showCursor.call(0)
    # If the display counter is less than negative one
    if success < -1
      # Loop until the display counter is negative one
      until success == -1
        # Increment the mouse display count
        success = @showCursor.call(1)
      end
    # If the display counter is zero or greater
    elsif success >= 0
      # Loop until the display counter is netagive one
      until success == -1
        # Decrement the mouse display count
        success = @showCursor.call(0)
      end
    end
    @hidden = true
  end
  #--------------------------------------------------------------------------
  # * Show Cursor
  #--------------------------------------------------------------------------
  def self.show_cursor
    @hidden = false
    # Show the mouse cursor
    success = @showCursor.call(1)
    # If the display counter is less than negative one
    if success < 15
      # Loop until the display counter is negative one
      until success == 15
        # Increment the mouse display count
        success = @showCursor.call(1)
      end
    # If the display counter is zero or greater
    elsif success > 15
      # Loop until the display counter is netagive one
      until success == 15
        # Decrement the mouse display count
        success = @showCursor.call(0)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Set Mouse X
  #     coord : the x coordinate to move the mouse to
  #--------------------------------------------------------------------------
  def self.set_x(coord)
    # Validate the argument
    return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    # Set the coordinate
    @mouse_x = coord.to_i
  end
  #--------------------------------------------------------------------------
  # * Set Mouse Y
  #     coord : the y coordinate to move the mouse to
  #--------------------------------------------------------------------------
  def self.set_y(coord)
    # Validate the argument
    return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    # Set the coordinate
    @mouse_y = coord.to_i
  end
  #--------------------------------------------------------------------------
  # * Set Mouse Position
  #     x : the x coordinate to move the mouse to
  #     y : the y coordinate to move the mouse to
  #--------------------------------------------------------------------------
  def self.set_pos(x, y)
    # Validate the arguments
    return false if (x.is_a?(NilClass)) || !(x.to_i.is_a?(Integer))
    return false if (y.is_a?(NilClass)) || !(y.to_i.is_a?(Integer))
    # Correct the coordinates
    self.set_x(x)
    self.set_y(y)
  end
  #--------------------------------------------------------------------------
  # * Get Button Double-Click State
  #     button : the button to check
  #--------------------------------------------------------------------------
  def self.double_click?(button)
    # Validate button
    return false if (button < 1 || button > 6)
    # Return the double click state
    return @double_click[button]
  end
  #--------------------------------------------------------------------------
  # * Get Last Click X
  #     button : the button to check
  #--------------------------------------------------------------------------
  def self.last_click_x(button)
    # Validate button
    return false if (button < 1 || button > 6)
    # Return the double click state
    return @last_click_x[button]
  end
  #--------------------------------------------------------------------------
  # * Get Last Click Y
  #     button : the button to check
  #--------------------------------------------------------------------------
  def self.last_click_y(button)
    # Validate button
    return false if (button < 1 || button > 6)
    # Return the double click state
    return @last_click_y[button]
  end
  #--------------------------------------------------------------------------
  # * Initialize Module
  #--------------------------------------------------------------------------
  begin
    self.update
  end
end
 
#==============================================================================
# ** Mouse_Sprite
#==============================================================================

module Mouse_Sprite
  def self.id=(id)
    case id
    when 0
      $mouse_sprite.bitmap = Bitmap.new(1, 1)
      $mouse_sprite.blend_type = 0
      $mouse_sprite.ox = 0
      $mouse_sprite.oy = 0
    when 1
      $mouse_sprite.bitmap = RPG::Cache.icon("beam")
      $mouse_sprite.blend_type = 1
      $mouse_sprite.ox = 8
      $mouse_sprite.oy = 8
    end
  end
end

#==============================================================================
# ** Keys
#------------------------------------------------------------------------------
#  This module performs key input processing
#==============================================================================
 
module Keys
  # Add class data
  class << self
    #------------------------------------------------------------------------
    # * Alias Methods
    #------------------------------------------------------------------------
    # If the update method has not been aliased
    unless method_defined?(:mouseinputmodule_keys_update)
      # Alias the update method
      alias mouseinputmodule_keys_update update
    end
    #------------------------------------------------------------------------
    # * Frame Update
    #------------------------------------------------------------------------
    def update
      # Call original method
      mouseinputmodule_keys_update
      # Update Keys module
      Mouse.update
    end
  end
end

Requiere el Keyboard module también:
http://glitchkey.com/scripts/kim_xpvx_1_00.html

Y aquí un script de prueba necesario porque el Mouse usa algunas variables de Game_Temp:
Código:
class Game_Temp
  attr_accessor :saved_gesture
  attr_accessor :temp_gesture
  attr_accessor :saved_index
  attr_accessor :mouse_cursor_id
  
  alias mouse_test_ini initialize unless $@
  def initialize
    mouse_test_ini()
    @saved_gesture = {}
    @temp_gesture = {}
    @saved_index = 0
    @mouse_cursor_id = 0
  end
end

class Scene_Title
  alias mouse_test_upd update unless $@
  def update
    if Mouse.trigger?(Mouse::LBUTTON)
      p "Mouse Trigger (L) - X = #{Mouse.x}, Y = #{Mouse.y}"
    end
  end
end
avatar
Wecoc
Administrador
Administrador



Créditos 12284

Gracias : 645

Volver arriba Ir abajo

RPG Maker XP Re: [Ayuda] Problema con ShowCursor (module Mouse)

Mensaje por Metalero el 2015-08-05, 02:30

Ufff...

Bueno, estuve a punto de rendirme, pero creo que lo logre, usando un poco de magia negra.

Código:

#==============================================================================
# ** Glitchfinder's Mouse Input Module
#    Version 3.00 # (Edit)
#------------------------------------------------------------------------------
#  This script helps scripters to use the mouse, without being limited by the
#  default Input Module.
#==============================================================================

#==============================================================================
# * Method List
#==============================================================================
#  Mouse.update
#    Updates mouse input. Calls to this method are not necessary unless the
#    default Input module is not being updated.
#
#  Mouse.press?(key)
#    Determines whether the button determined by key is currently being
#    pressed. If the button is being pressed, returns true. If not, returns
#    false.
#
#  Mouse.trigger?(key)
#    Determines whether the button determined by key is being pressed again.
#    "Pressed again" is seen as time having passed between the button being not
#    pressed and being pressed. If the button is being pressed, returns true.
#    If not, returns false.
#
#  Mouse.repeat?(key)
#    Determines whether the button determined by key is being pressed again.
#    Unlike trigger?(), this takes into account the repeat input of a button
#    being held down continuously. If the button is being pressed, returns
#    true. If not, returns false.
#
#  Mouse.release?(key)
#    Determines whether the button determined by key has just been released. If
#    the button has been released, returns true. If not, returns false.
#
#  Mouse.in_screen?
#    This method returns true if the mouse is over the game window, and false if
#    not. (The function returns false if the mouse is currently over the window
#    title or edge, instead of the client area)
#
#  Mouse.pos
#    This method returns an array containing the current mouse position, in the
#    following format: [x, y]
#
#  Mouse.x
#    Returns the current mouse x position. If the mouse is to the left of the
#    game screen, returns 0. If the mouse is to the right of the game window,
#    returns the width of the window minus one.
#
#  Mouse.y
#    Returns the current mouse y position. If the mouse is above the game
#    screen, returns 0. If the mouse is below the game window, returns the
#    height of the window minus one.
#
#  Mouse.dragging?
#  Mouse.dragging?(button)
#    Checks to see if the mouse is currently dragging. (The primary button is
#    being held while the mouse moves across the screen) Returns true if the
#    mouse is dragging, false if the mouse is not. If an argument is supplied,
#    this will check the dragging status of the button in question. Otherwise,
#    the check will supply the status of the primary mouse key.
#
#  Mouse.drag_rect
#  Mouse.drag_rect(button)
#    Checks to see if the mouse is dragging, and returns the rect of the drag
#    area. If the mouse is not currently dragging, returns an empty rect. If
#    the mouse is dragging, returns a screen rect that covers the current drag
#    area. If an argument is supplied, this will check the dragging status of
#    the button in question. Otherwise, the check will supply the status of the
#    primary mouse key.
#
#  Mouse.drag_coor
#  Mouse.drag_coor(button)
#    Checks to see if the mouse is dragging, and returns the starting
#    coordinates. If the mouse is not dragging, returns the current mouse
#    position.  If an argument is supplied, this will check the dragging status
#    of the button in question. Otherwise, the check will supply the status of
#    the primary mouse key.The return data is in the following format: [x, y]
#
#  Mouse.in_area?(Rect)
#  Mouse.in_area?(x, y, width, height)
#    Determines if the mouse is within the specified area. You can input either
#    a rect or the x, y, width, and height of the area. If the mouse is
#    currently within that area, returns true. Otherwise, returns false.
#
#  Mouse.hide_cursor
#
#  Mouse.show_cursor
#
#  Mouse.double_click?(button)
#    Returns true if the specified button is pressed twice within a short time.
#
#  Mouse.last_click_x(button)
#  Mouse.last_click_y(button)
#    Returns the coordinate of the last location at which the supplied mouse
#    button was pressed.
#
#  Mouse.set_x(coordinate)
#  Mouse.set_y(coordinate)
#  Mouse.set_pos(x, y)
#    Sets the mouse location.
#
#==============================================================================
# *Glitchfinder's Advice
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script is meant for people with a medium or advanced level of scripting
#  knowledge and ability, or for those using scripts that require this module.
#==============================================================================
# * License
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script is licensed under the MIT License:
#
#  Copyright (c) 2010-2014 Sean Porter (Glitchfinder) <glitchkey@gmail.com>
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.
#==============================================================================
 
#==============================================================================
# ** Mouse
#------------------------------------------------------------------------------
#  This module performs mouse input processing
#==============================================================================
 
module Mouse
  #--------------------------------------------------------------------------
  # * Declare Module Variables
  #--------------------------------------------------------------------------
  # Declare API calls
  @metrics       = Win32API.new('user32', 'GetSystemMetrics', 'i' , 'i')
  @getCursorPos  = Win32API.new('user32', 'GetCursorPos'    , 'p' , 'v')
  @getWindowRect = Win32API.new('user32', 'GetWindowRect'   , 'lp', 'v')
  @showCursor    = Win32API.new('user32', 'ShowCursor'      , 'i' , 'i')
  @setCursorPos  = Win32API.new('user32', 'SetCursorPos'    , 'ii', 'i')
  @getCursor     = Win32API.new('user32', 'SetCursor'    , 'v', 'i')
  @setCursor     = Win32API.new('user32', 'GetCursor'    , 'i', 'i')
  # Get window thread
  findWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
  @window      = findWindowEx.call(0, 0, "RGSS Player", 0)
  @cursor = @getCursor.call()
  
  $mouse_sprite = Sprite.new
  $mouse_sprite.z = 1000000000
  $mouse_sprite.bitmap = Bitmap.new(1, 1)
  
  # Set up double click
  @double_click         = Array.new(7, false)
  @double_click_counter = Array.new(7, 0)
  @double_click_frames  = 20
  @double_click_pixels  = 4
  # Set up drag
  @mouse_drag  = Array.new(7) {Array.new([false, 0, 0, 0, 0])}
  @drag_pixels = 4
  # Set up last click
  @last_click_x = Array.new(7, 0)
  @last_click_y = Array.new(7, 0)
  # Set mouse to visible
  @hidden = false
  #--------------------------------------------------------------------------
  # * Mouse Keys
  #--------------------------------------------------------------------------
  SWAPBUTTON = @metrics.call(23) == 0 ? false : true # Buttons Swapped
  LBUTTON    = 0x01 # Physical Left Button
  RBUTTON    = 0x02 # Physical Right Button
  MBUTTON    = 0x04 # Middle Mouse Button
  XBUTTON1   = 0x05 # X1 Mouse Button
  XBUTTON2   = 0x06 # X2 Mouse Button
  PRIMARY    = !SWAPBUTTON ? 0x01 : 0x02 # Primary Mouse Button
  SECONDARY  = !SWAPBUTTON ? 0x02 : 0x01 # Secondary Mouse Button
  #--------------------------------------------------------------------------
  # * Special Keys
  #--------------------------------------------------------------------------
  ANYKEY     = 0x100 # Any Key
  ANYBUTTON  = [0x01, 0x02, 0x04, 0x05, 0x06]
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def self.update
    # Update Sprite
    $mouse_sprite.update
    # create blank rect
    rect = '0' * 16
    # Get window rect
    @getWindowRect.call(@window, rect)
    # Unpack rect data
    left, top, right, bottom = rect.unpack("LLLL")
    # Get window coordinates
    # @window_x = left
    # @window_y = top
    @window_x = left + @metrics.call(5) + @metrics.call(45)
    @window_y = top + @metrics.call(6) + @metrics.call(46) + @metrics.call(4)
    # Get window dimensions
    @window_width  = right  - left
    @window_width -= (@metrics.call(5) + @metrics.call(45)) * 2
    @window_height = bottom - top
    @window_height -= @metrics.call(4)
    # If the game is not fullscreen
    cursor_position = '0' * 8
    # Get cursor position
    @getCursorPos.call(cursor_position)
    # Unpack cursor position data
    @mouse_x, @mouse_y = cursor_position.unpack('LL')
    # Set cursor position relative to the window
    @mouse_x -= @window_x
    @mouse_y -= @window_y
    # If the cursor is not over the window
    if (@mouse_x < 0 || @mouse_y < 0 || @mouse_x >= @window_width ||
      @mouse_y >= @window_height)
      # Set the mouse to off screen
      @in_screen = false
    # If the cursor is over the window
    else
      # Set the mouse to on screen
      @in_screen = true
    end
    # Clear double click flags
    @double_click = Array.new(6, false)
    # Iterate the mouse buttons
    for i in ANYBUTTON
      # Set up mouse deviance
      x_deviance = (@last_click_x[i] - @mouse_x).abs
      y_deviance = (@last_click_y[i] - @mouse_y).abs
      # Correct mouse deviance
      x_deviance *= -1 if x_deviance < 0
      y_deviance *= -1 if y_deviance < 0
      # If the button is triggered
      if Keys.trigger?(i)
        # Set allowed deviance
        deviance = @double_click_pixels
        # Get the double click counter
        counter = @double_click_counter[i]
        # If double click counter is active and deviance is within allowed range
        if (counter > 0 && x_deviance <= deviance && y_deviance <= deviance)
          # Set double click flag to true
          @double_click[i] = true
        # If double click counter is not running or the cursor is out of bounds
        else
          # Reset double click counter
          @double_click_counter[i] = @double_click_frames
        end
        # Set drag start coordinates
        @mouse_drag[i][1] = @mouse_x
        @mouse_drag[i][2] = @mouse_y
        # Set last click coordinates
        @last_click_x[i]  = @mouse_x
        @last_click_y[i]  = @mouse_y
      # If the button is pressed
      elsif Keys.press?(i)
        # If the mouse has moved beyond the required deviance
        if x_deviance >= @drag_pixels && y_deviance >= @drag_pixels
          # Set the mouse to dragging
          @mouse_drag[i][0] = true
        end
        # If the mouse is dragging
        if @mouse_drag[i][0] == true
          # Set current dragging corrdinates
          @mouse_drag[i][3] = @mouse_x
          @mouse_drag[i][4] = @mouse_y
        end
      # If the button is released
      else
        # Reset drag data
        @mouse_drag[i][0] = false
        @mouse_drag[i][1] = 0
        @mouse_drag[i][2] = 0
        @mouse_drag[i][3] = 0
        @mouse_drag[i][4] = 0
      end
      # If the double click counter is running
      if @double_click_counter[i] > 0
        # Cycle the double click counter down one frame
        @double_click_counter[i] -= 1
      end
    end
    $mouse_sprite.x = Mouse.x
    $mouse_sprite.y = Mouse.y
    # Set hidden feature
    if !$game_temp.nil?
      Mouse_Sprite.id = $game_temp.mouse_cursor_id
      if $game_temp.mouse_cursor_id > 0
        @hidden = true
      else
        @hidden = false
      end
    end
    # If the cursor is in the screen and it is set to hidden
    if @in_screen && @hidden
      # Hide the mouse cursor
      hide_cursor
    # If the cursor is not set to hidden or is not on screen
    else
      # Set the mouse to visible
      show_cursor
    end
  end
  #--------------------------------------------------------------------------
  # * Get Key Pressed State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.press?(key)
    # Return key pressed state
    return Keys.press?(key)
  end
  #--------------------------------------------------------------------------
  # * Get Key Triggered State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.trigger?(key)
    # Return key triggered state
    return Keys.trigger?(key)
  end
  #--------------------------------------------------------------------------
  # * Get Key Repeated State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.repeat?(key)
    # Return key repeated state
    return Keys.repeat?(key)
  end
  #--------------------------------------------------------------------------
  # * Get Key Released State
  #     key : key index
  #--------------------------------------------------------------------------
  def self.release?(key)
    # Return key released state
    return Keys.release?(key)
  end
  #--------------------------------------------------------------------------
  # * Is the Mouse on Screen?
  #--------------------------------------------------------------------------
  def self.in_screen?
    # Return mouse in screen flag
    return @in_screen
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Position
  #--------------------------------------------------------------------------
  def self.pos
    # Return mouse position array
    return [@mouse_x, @mouse_y]
  end
  #--------------------------------------------------------------------------
  # * Get Mouse X Position
  #--------------------------------------------------------------------------
  def self.x
    # Return mouse x position
    return @mouse_x
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Y Position
  #--------------------------------------------------------------------------
  def self.y
    # Return mouse y position
    return @mouse_y
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Dragging Boolean
  #     args : the mouse button to check
  #--------------------------------------------------------------------------
  def self.dragging?(*args)
    # Get the button
    if args.is_a?(NilClass) || args[0].is_a?(NilClass)
      button = PRIMARY
    else
      button = args[0]
    end
    # Validate button
    return false if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
    # Return mouse dragging flag
    return @mouse_drag[button][0]
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Drag Rect
  #     args : the mouse button to check
  #--------------------------------------------------------------------------
  def self.drag_rect(*args)
    # Get the button
    if args.is_a?(NilClass) || args[0].is_a?(NilClass)
      button = PRIMARY
    else
      button = args[0]
    end
    # Validate button
    if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
      return Rect.new(0, 0, 0, 0)
    end
    # Return blank rect if the mouse is not dragging
    return Rect.new(0, 0, 0, 0) if !@mouse_drag[i][0]
    # Get drag rect coordinates
    x = @mouse_drag[i][1]
    y = @mouse_drag[i][2]
    # Correct drag rect coordinates
    x = @mouse_drag[i][3] if x > @mouse_drag[i][3]
    y = @mouse_drag[i][4] if y > @mouse_drag[i][4]
    # Get drag rect dimensions
    width  = @mouse_drag[i][1]
    height = @mouse_drag[i][2]
    # Correct drag rect dimensions
    width  = @mouse_drag[i][3] if x == width
    height = @mouse_drag[i][4] if y == height
    width  -= x
    height -= y
    # Return drag rect
    return Rect.new(x, y, width, height)
  end
  #--------------------------------------------------------------------------
  # * Get Mouse Drag Coordinates
  #     args : the mouse button to check
  #--------------------------------------------------------------------------
  def self.drag_coor(*args)
    # Get the button
    if args.is_a?(NilClass) || args[0].is_a?(NilClass)
      button = PRIMARY
    else
      button = args[0]
    end
    # Validate button
    if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
      return [@mouse_x, @mouse_y] if (button < 1 || button > 6)
    end
    # Return current coordinates if the mouse isn't dragging
    return [@mouse_x, @mouse_y] if !@mouse_drag[button][0]
    # return mouse drag starting coordinates
    return [@mouse_drag[button][1], @mouse_drag[button][2]]
  end
  #--------------------------------------------------------------------------
  # * Get Mouse in Area Flag
  #--------------------------------------------------------------------------
  def self.in_area?(*args)
    # return false if the mouse is not on screen
    return false if !@in_screen
    # If the argument is a rect
    if args[0].is_a?(Rect)
      # Return if the mouse is within the rect
      return (@mouse_x >= args[0].x && @mouse_y >= args[0].y &&
        @mouse_x < args[0].x + args[0].width &&
        @mouse_y < args[0].y + args[0].height)
    # If the arguments are separate
    else
      # Return if the mouse is within the specified coordinates
      return (@mouse_x >= args[0] && @mouse_y >= args[1] &&
        @mouse_x < args[0] + args[2] && @mouse_y < args[1] + args[3])
    end
  end
  
  def self.over_sprite?(sprite)
    return self.in_area?(sprite.x, sprite.y,
    sprite.bitmap.width, sprite.bitmap.height)
  end
  
  def self.inside_window?(window)
    return self.in_area?(window.x, window.y,
    window.width, window.height)
  end  

  def self.result_mouse_gesture(result)
    Mouse.save_gesture
    return
  end

  def self.update_mouse_gestures
    # return if forbid_mouse_gestures
    Mouse.clear_mouse_gesture if @mouse_gesture.nil?
    $game_temp.temp_gesture = {} if !$game_temp.temp_gesture
        
    if Mouse.dragging?
      point = @mouse_gesture[0][@mouse_gesture[4]]
      if point == nil ||  point.disposed?
        @mouse_gesture[0][@mouse_gesture[4]] = Sprite.new
      end
      @mouse_gesture[0][@mouse_gesture[4]].x = @mouse_gesture[4] == 0 ? 
      Mouse.drag_coor[0] : Mouse.x
      @mouse_gesture[0][@mouse_gesture[4]].y = @mouse_gesture[4] == 0 ? 
      Mouse.drag_coor[1] : Mouse.y
      Mouse.recog_mouse_gesture # if @mouse_gesture[6] == Mouse.pos
      @mouse_gesture[6] = Mouse.pos if @mouse_gesture[6] != Mouse.pos
      @mouse_gesture[4] += 1 
    else
      if !@mouse_gesture[0].empty?
        @mouse_gesture[1].each_with_index { |s,i| 
        @mouse_gesture[1][i-1] = nil if i > 0 && s == @mouse_gesture[1][i-1] }
        Mouse.result_mouse_gesture(@mouse_gesture[1].compact)
        @mouse_gesture[0].each {|i| i.dispose }
        @mouse_gesture[2].each {|i| i.dispose }
        Mouse.clear_mouse_gesture
      end
    end
  end
  
  def self.save_gesture
    return if @mouse_gesture[2][0].nil?
    index = ($game_temp.saved_index || 1).abs
    $game_temp.temp_gesture[index] = @mouse_gesture[2][0].bitmap.clone
  end
  
  def self.clear_mouse_gesture()
    @mouse_gesture = [[],[],[],0,0,0]
  end
  
  def self.draw_mouse_line(start_x, start_y, end_x, end_y, color, width=1)
    point = @mouse_gesture[2][0]
    if point == nil || point.disposed?
      @mouse_gesture[2][0] = Sprite.new
      @mouse_gesture[2][0].bitmap = Bitmap.new(*Resolution.window_size)
      @mouse_gesture[2][0].z = 9999
    end
    distance = (start_x - end_x).abs + (start_y - end_y).abs
    (1..distance).each do |i|
      x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
      y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
      @mouse_gesture[2][0].bitmap.fill_rect(x, y, width, width, color)
      index = ($game_temp.saved_index || 1).abs
      $game_temp.temp_gesture[index.to_s] = [] if !$game_temp.temp_gesture[index.to_s]
      $game_temp.temp_gesture[index.to_s] << [x,y]
    end
    @mouse_gesture[3] += 1
  end
  
  def self.recog_mouse_gesture
    awal = @mouse_gesture[0][@mouse_gesture[5]]
    akhir = @mouse_gesture[0][@mouse_gesture[4]]
    
    sensitivity = 1
    
    draw_mouse_line(awal.x, awal.y, akhir.x, akhir.y, Color.new(0, 0, 0, 0), 3)
    
    if awal.x - akhir.x > sensitivity && (awal.y - akhir.y).abs < sensitivity 
      @mouse_gesture[1] << 'left'
    end
    if awal.x - akhir.x < -sensitivity && (awal.y - akhir.y).abs < sensitivity
      @mouse_gesture[1] << 'right'
    end
    if awal.y - akhir.y > sensitivity && (awal.x - akhir.x).abs < sensitivity
      @mouse_gesture[1] << 'up'
    end
    if awal.y - akhir.y < -sensitivity && (awal.x - akhir.x).abs < sensitivity 
      @mouse_gesture[1] << 'down'
    end
    if awal.x - akhir.x > sensitivity && awal.y - akhir.y > sensitivity
      @mouse_gesture[1] << 'upleft'
    end
    if awal.x - akhir.x < -sensitivity && awal.y - akhir.y > sensitivity
      @mouse_gesture[1] << 'upright'
    end
    if awal.x - akhir.x > sensitivity && awal.y - akhir.y < -sensitivity
      @mouse_gesture[1] << 'downleft'
    end
    if awal.x - akhir.x < -sensitivity && awal.y - akhir.y < -sensitivity
      @mouse_gesture[1] << 'downright'
    end
    @mouse_gesture[5] = @mouse_gesture[4]
  end
  
  Get_Message = Win32API.new('User32','GetMessage','plll','l')
  Point = Struct.new(:x, :y)
  Param = Struct.new(:x, :y, :scroll)
  Message = Struct.new(:message, :wparam, :lparam, :pt)
  
  def self.scroll
    msg= "\0" * 32
    Get_Message.call(msg,0,0,0)
    r = wmcallback(unpack_msg(msg))
    return r if !r.nil?
  end
  
  def self.word2signed_short(value)
    return value if (value & 0x8000) == 0
    return -1 * ((~value & 0x7fff)+1)
  end

  def self.hiword(dword)
    return ((dword & 0xffff0000) >> 16) & 0x0000ffff
  end
  
  def self.wmcallback(msg)
    return unless msg.message == 0x0000020A
    param = Param.new
    param.scroll = Mouse.word2signed_short(Mouse.hiword(msg.wparam))
    return (param.scroll < 0 ? -1 : 1)
  end
  
  def self.unpack_dword(buffer,offset=0)
    ret = buffer[offset+0] & 0x000000ff
    ret |= (buffer[offset+1] << (8*1)) & 0x0000ff00
    ret |= (buffer[offset+2] << (8*2)) & 0x00ff0000
    ret |= (buffer[offset+3] << (8*3)) & 0xff000000
    return ret
  end
  
  def self.unpack_msg(buffer)
    msg = Message.new
    msg.pt = Point.new
    msg.message = Mouse.unpack_dword(buffer,4 * 1)
    msg.wparam = Mouse.unpack_dword(buffer,4 * 2)
    msg.lparam = Mouse.unpack_dword(buffer,4 * 3)
    msg.pt.x = Mouse.unpack_dword(buffer,4 * 5)
    msg.pt.y = Mouse.unpack_dword(buffer,4 * 6)
    return msg
  end
  
  #--------------------------------------------------------------------------
  # * Hide Cursor
  #--------------------------------------------------------------------------
  def self.hide_cursor
    # Hide the mouse cursor
    success = @showCursor.call(0)
    # If the display counter is less than negative one
    if success < -1
      # Loop until the display counter is negative one
      until success == -1
        # Increment the mouse display count
        success = @showCursor.call(1)
      end
    # If the display counter is zero or greater
    elsif success >= 0
      # Loop until the display counter is netagive one
      until success == -1
        # Decrement the mouse display count
        success = @showCursor.call(0)
      end
    end
    @hidden = true
  end
  #--------------------------------------------------------------------------
  # * Show Cursor
  #--------------------------------------------------------------------------
  def self.show_cursor
    @hidden = false
    # Show the mouse cursor
    success = @showCursor.call(1)
    # If the display counter is less than negative one
    if success < 15
      # Loop until the display counter is negative one
      until success == 15
        # Increment the mouse display count
        success = @showCursor.call(1)
      end
      
      #@setCursor.call(@cursor)
      
    # If the display counter is zero or greater
    elsif success > 15
      # Loop until the display counter is netagive one
      until success == 15
        # Decrement the mouse display count
        success = @showCursor.call(0)
      end
    end
    @setCursorPos.call(@mouse_x + @window_x, @mouse_y + @window_y)
  end
  #--------------------------------------------------------------------------
  # * Set Mouse X
  #     coord : the x coordinate to move the mouse to
  #--------------------------------------------------------------------------
  def self.set_x(coord)
    # Validate the argument
    return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    # Set the coordinate
    @mouse_x = coord.to_i
  end
  #--------------------------------------------------------------------------
  # * Set Mouse Y
  #     coord : the y coordinate to move the mouse to
  #--------------------------------------------------------------------------
  def self.set_y(coord)
    # Validate the argument
    return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    # Set the coordinate
    @mouse_y = coord.to_i
  end
  #--------------------------------------------------------------------------
  # * Set Mouse Position
  #     x : the x coordinate to move the mouse to
  #     y : the y coordinate to move the mouse to
  #--------------------------------------------------------------------------
  def self.set_pos(x, y)
    # Validate the arguments
    return false if (x.is_a?(NilClass)) || !(x.to_i.is_a?(Integer))
    return false if (y.is_a?(NilClass)) || !(y.to_i.is_a?(Integer))
    # Correct the coordinates
    self.set_x(x)
    self.set_y(y)
  end
  #--------------------------------------------------------------------------
  # * Get Button Double-Click State
  #     button : the button to check
  #--------------------------------------------------------------------------
  def self.double_click?(button)
    # Validate button
    return false if (button < 1 || button > 6)
    # Return the double click state
    return @double_click[button]
  end
  #--------------------------------------------------------------------------
  # * Get Last Click X
  #     button : the button to check
  #--------------------------------------------------------------------------
  def self.last_click_x(button)
    # Validate button
    return false if (button < 1 || button > 6)
    # Return the double click state
    return @last_click_x[button]
  end
  #--------------------------------------------------------------------------
  # * Get Last Click Y
  #     button : the button to check
  #--------------------------------------------------------------------------
  def self.last_click_y(button)
    # Validate button
    return false if (button < 1 || button > 6)
    # Return the double click state
    return @last_click_y[button]
  end
  #--------------------------------------------------------------------------
  # * Initialize Module
  #--------------------------------------------------------------------------
  begin
    self.update
  end
end
 
#==============================================================================
# ** Mouse_Sprite
#==============================================================================

module Mouse_Sprite
  def self.id=(id)
    case id
    when 0
      $mouse_sprite.bitmap = Bitmap.new(1, 1)
      $mouse_sprite.blend_type = 0
      $mouse_sprite.ox = 0
      $mouse_sprite.oy = 0
    when 1
      $mouse_sprite.bitmap = RPG::Cache.icon("beam")
      $mouse_sprite.blend_type = 1
      $mouse_sprite.ox = 8
      $mouse_sprite.oy = 8
    end
  end
end

#==============================================================================
# ** Keys
#------------------------------------------------------------------------------
#  This module performs key input processing
#==============================================================================
 
module Keys
  # Add class data
  class << self
    #------------------------------------------------------------------------
    # * Alias Methods
    #------------------------------------------------------------------------
    # If the update method has not been aliased
    unless method_defined?(:mouseinputmodule_keys_update)
      # Alias the update method
      alias mouseinputmodule_keys_update update
    end
    #------------------------------------------------------------------------
    # * Frame Update
    #------------------------------------------------------------------------
    def update
      # Call original method
      mouseinputmodule_keys_update
      # Update Keys module
      Mouse.update
    end
  end
end

El secreto estuvo en: 

Código:

@setCursorPos.call(@mouse_x + @window_x, @mouse_y + @window_y)

Si si si, ya se, es basura. Basicamente le esta seteando la posición del cursor en cada frame, en la misma posicion que ya tenia.

Yo ya hice la parte dificil de encontrarle una vuelta (probe formas mas lindas, pero ninguna funcionó), ahora vos ya podes solito optimizarlo un poco para que no se llame en cada frame (tranquilamente se podria llamar cada 20 o 40 frames)

_________________
avatar
Metalero
Administrador
Administrador



Créditos 1709

Gracias : 100

Volver arriba Ir abajo

RPG Maker XP Re: [Ayuda] Problema con ShowCursor (module Mouse)

Mensaje por Wecoc el 2015-08-05, 05:07

¡Funciona genial! Debí prestar más atención al @setCursorPos que al @showCursor xDD

No me da ningún lag aunque se updatee cada frame, magias del API. Aún así lo he restringido con @in_screen == true y $game_temp.mouse_cursor_id == 0 (si es más de 0 no se muestra el cursor así que no tiene sentido) y solo funciona si una variable de $game_system está activada, aunque por defecto siempre lo estará.

Muchas gracias.
avatar
Wecoc
Administrador
Administrador



Créditos 12284

Gracias : 645

Volver arriba Ir abajo

RPG Maker XP Re: [Ayuda] Problema con ShowCursor (module Mouse)

Mensaje por Contenido patrocinado


Contenido patrocinado


Volver arriba Ir abajo

Ver el tema anterior Ver el tema siguiente Volver arriba


Permisos de este foro:
No puedes responder a temas en este foro.