Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved] Changing Cursor Graphic.

Hello There.

I would like to know what I could do to possibly change the graphic of the cursor/clicker/pointer within RPG Maker XP. I know it would have something to do with Win32API, but I don't know what I'm to do with that. I'm sorry if this topic is a little vague, because it is, but if you need anymore information, all you have to do is ask for the information you want/need.

Thank You,
~CottonJ
 
My bad. Well, you can turn it off (via API), and control with a RMXP Sprite. (I will look into changing the windows sprite API call)

Let me dig it up, as I have the API in one of my scripts.

....

Code:
module Show_Mouse
  Show_Cursor   = Win32API.new('user32',    'ShowCursor',       'l',     'l')
  def self.hide
    Show_Cursor.call(0)
  end
  def self.show
    Show_Cursor.call(0)
  end
end

Now you can show/hide the mouse with Show_Mouse.hide

I'm looking up the API to changed the mouse cursor, but I may not find it right away.


Looking in the user32 lib, of the API module I helped create, I have this list for cursor functions.
Code:
#==============================================================================
# ** API
#==============================================================================

module API
  #-------------------------------------------------------------------------
  # * Name      : Current API Module Version
  #   Author    : SephirothSpawn
  #   Call Info : API Arguments, Function Arguments
  #-------------------------------------------------------------------------
  def self.call(api_arguments, function_arguments)
    # Gets instance name
    instance_name = "@#{api_arguments[1]}"
    # Gets instance variable
    instance = eval instance_name
    # If nil instance variable
    if instance.nil?
      p 'create'
      # Create instance variable
      eval "#{instance_name} = Win32API.new(*api_arguments)"
    end
    # Get instance variable
    instance = eval instance_name
    # Call Instance
    instance.call(*function_arguments)
  end
end

#==============================================================================
# ** API::User32
#==============================================================================

module API::User32
  #-------------------------------------------------------------------------
  # * Name      : ClipCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : lpRectAsAny)AsLong
  #-------------------------------------------------------------------------
  def self.ClipCursor(*args)
    API.call(['user32', 'ClipCursor', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : CopyCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByValhcurAsLong)AsLong
  #-------------------------------------------------------------------------
  def self.CopyCursor(*args)
    API.call(['user32', 'CopyCursor', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : CreateCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByValhInstanceAsLong
  #               ByValnXhotspotAsLong
  #               ByValnYhotspotAsLong
  #               ByValnWidthAsLong
  #               ByValnHeightAsLong
  #               lpANDbitPlaneAsAny
  #               lpXORbitPlaneAsAny)AsLong
  #-------------------------------------------------------------------------
  def self.CreateCursor(*args)
    API.call(['user32', 'CreateCursor', 'PPPPPPP', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : DestroyCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByValhCursorAsLong)AsLong
  #-------------------------------------------------------------------------
  def self.DestroyCursor(*args)
    API.call(['user32', 'DestroyCursor', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : GetClipCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : lprcAsRECT)AsLong
  #-------------------------------------------------------------------------
  def self.GetClipCursor(*args)
    API.call(['user32', 'GetClipCursor', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : GetCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : )AsLong
  #-------------------------------------------------------------------------
  def self.GetCursor(*args)
    API.call(['user32', 'GetCursor', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : GetCursorInfo
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByRefpciAsPCURSORINFO)AsLong
  #-------------------------------------------------------------------------
  def self.GetCursorInfo(*args)
    API.call(['user32', 'GetCursorInfo', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : GetCursorPos
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : lpPointAsPOINTAPI)AsLong
  #-------------------------------------------------------------------------
  def self.GetCursorPos(*args)
    API.call(['user32', 'GetCursorPos', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : LoadCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : Alias"LoadCursorA"ByValhInstanceAsLong
  #               ByVallpCursorNameAsString)AsLong
  #-------------------------------------------------------------------------
  def self.LoadCursor(*args)
    API.call(['user32', 'LoadCursor', 'PP', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : LoadCursorFromFile
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : Alias"LoadCursorFromFileA"ByVallpFileNameAsString)AsLong
  #-------------------------------------------------------------------------
  def self.LoadCursorFromFile(*args)
    API.call(['user32', 'LoadCursorFromFile', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : SetCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByValhCursorAsLong)AsLong
  #-------------------------------------------------------------------------
  def self.SetCursor(*args)
    API.call(['user32', 'SetCursor', 'P', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : SetCursorPos
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByValxAsLong
  #               ByValyAsLong)AsLong
  #-------------------------------------------------------------------------
  def self.SetCursorPos(*args)
    API.call(['user32', 'SetCursorPos', 'PP', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : SetSystemCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByValhcurAsLong
  #               ByValidAsLong)AsLong
  #-------------------------------------------------------------------------
  def self.SetSystemCursor(*args)
    API.call(['user32', 'SetSystemCursor', 'PP', 'L'], args)
  end
  #-------------------------------------------------------------------------
  # * Name      : ShowCursor
  #   Author    : SephirothSpawn & rpgmaker
  #   Call Info : ByValbShowAsLong)AsLong
  #-------------------------------------------------------------------------
  def self.ShowCursor(*args)
    API.call(['user32', 'ShowCursor', 'P', 'L'], args)
  end
end

I'm working on a module that makes setting and changing cursors a little easier but calling API parameters.
 
I was saying you could do that, but there is actually a way to change it to a windows cursor. This may be off request, but I am looking into it anyway as it interest me. :tongue:

Code:
module Mouse
  IDC_ARROW = 32512        # Standard arrow
  IDC_IBEAM = 32513        # Text I-beam
  IDC_WAIT = 32514         # Hourglass
  IDC_CROSS = 32515        # Crosshair
  IDC_UPARROW = 32516      # Vertical arrow
  IDC_SIZE = 32640         # Four-pointed arrow
  IDC_ICON = 32641         # Obsolete for applications marked version 4.0 or later.
  IDC_SIZENWSE = 32642     # Double-pointed arrow pointing northwest and southeast
  IDC_SIZENESW = 32643     # Double-pointed arrow pointing northeast and southwest
  IDC_SIZEWE = 32644       # Double-pointed arrow pointing west and east
  IDC_SIZENS = 32645       # Double-pointed arrow pointing north and south
  IDC_SIZEALL = 32646      # Four-pointed arrow
  IDC_NO = 32648           # Slashed circle
  IDC_APPSTARTING = 32650  # Standard arrow and small hourglass
  def self.set_cursor(constant = IDC_ARROW, system = IDC_ARROW)
    return if @last_cursor == constant
    if @last_cursor != nil
      hcursor = API::User32::LoadCursor(0, @last_cursor)
      API::User32::SetSystemCursor(hcursor, system)
      API::User32::DestroyCursor(hcursor)
      @last_cursor = nil
    end
    @last_cursor = constant
    hcursor = API::User32::LoadCursor(0, constant)
    API::User32::SetSystemCursor(hcursor, system)
    API::User32::DestroyCursor(hcursor)
  end
  def self.hide
    API::User32.Show_Cursor(0)
  end
  def self.show
    API::User32.Show_Cursor(1)
  end
  def self.restore_cursor
    Mouse.set_cursor(IDC_ARROW, IDC_ARROW)
  end
  Mouse.set_cursor(IDC_NO)
end

I got that so far, to change the system cursor to a list of IDC arrows. You call it with:
Code:
Mouse.set_cursor(constant)

You can add another argument, to assign it to a id, but thats only when the mouse turns to other ids (starting apps, etc. that match the constants above).

You also have to modify Main with this, so when you close RMXP, it restores the default mouse cursor.
Code:
rescue SystemExit => e
  # Restore Cursor
  Mouse.restore_cursor
end
# Restore Cursor
Mouse.restore_cursor if e.nil?

I am working on making it so you can change a cursor by a bitmap or file (CreateCursor, LoadIcon, etc.)
 
So yeah, here's my attempt on it...

Code:
#==============================================================================
# Cursor Sprite
#------------------------------------------------------------------------------
# Script by BlueScope, based on a script by berka
#==============================================================================

module Graphics
  class << self
    alias graphics_update update
    def update
      graphics_update
      Cursor.update
    end
  end
end


class Sprite_Cursor < Sprite_Base
  #--------------------------------------------------------------------------
  attr_accessor :type
  #--------------------------------------------------------------------------
  def initialize
    Win32API.new('user32','ShowCursor','i','i').call(0)
    super
    @type = 1
    self.z = 10015
    draw_cursor
    update
  end
  #--------------------------------------------------------------------------
  def draw_cursor
    self.bitmap = Bitmap.new(32, 32)
    bitmap = Cache.system('WhiteCursor')
    rect = Rect.new((@type-1) * 32, 0, 32, 32)
    self.bitmap.blt(0, 0, bitmap, rect)
  end
  #--------------------------------------------------------------------------
  def update
    super
    draw_cursor
    self.x, self.y = Mouse.screen_to_client(*Mouse.global_pos)
    self.x -= 4
    self.y -= 27
  end
  #--------------------------------------------------------------------------
  def dispose
    super
  end
  #--------------------------------------------------------------------------
end


Cursor = Sprite_Cursor.new

You can use this script with graphics that are build with (32*x) * 32 pixels, for example something like this:

whitecursorex9.png


This is from my peripherals engine, so you might not have any use for the latter two icons, but yeah... just to show ya.

You use it by setting Cursor.type, like this:

Code:
Cursor.type = 1

0 disposes the cursor, 1 to infinite is the index for your graphics in the system file.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top