OSRS Plugin API
    Preparing search index...

    Class Image

    A UI element that renders a sprite to the screen specified by an object Id.

    Implements

    Implemented by

    Index

    Constructors

    Properties

    height: number

    The height of this element, in UI coordinate space.

    -- Create a window that has a set height
    local window = osrs.Ui.window({title = "Example Window", sizeMode = 1, height = 200})

    -- Add window to the canvas
    osrs.Ui.canvas:addChild(window)
    heightRatio: number

    The percentage height of the screen this element should take up when sizeMode is set to LayoutMode.PROPORTIONAL. The number needs to be a decimal.

    -- Create new container with a set widthRatio and heightRatio
    local newWindow = osrs.Ui.window({title = "Example Window", sizeMode = 2, widthRatio = 0.7, heightRatio = .2})

    -- Add container to the canvas
    osrs.Ui.canvas:addChild(newWindow)
    positionMode: LayoutMode

    How this element should position itself.

    LayoutMode.AUTOMATIC
    
    -- Create a window that has automatic position mode, this is default
    local window1 = osrs.Ui.window({title = "Automatic Position Mode"})

    -- Create a window that has manual position mode
    local window2 = osrs.Ui.window(
    {
    title = "Manual Position Mode",
    positionMode = osrs.Ui.LayoutMode.MANUAL
    }
    )

    -- Add the windows to the canvas
    osrs.Ui.canvas:addChild(window1)
    osrs.Ui.canvas:addChild(window2)
    sameLine: boolean

    Flag to control whether this element should be placed on the same line as the previous element.

    false
    
    -- Create a container
    local window = osrs.Ui.window({title = "Example Window"})

    -- Create three buttons, with two of them on the same line
    local button1 = osrs.Ui.textButton({text = "Button 1"})
    local button2 = osrs.Ui.textButton({text = "Button 2"})
    local button3 = osrs.Ui.textButton({text = "Button 3", sameLine = true})

    -- Add buttons to the container
    window:addChild(button1)
    window:addChild(button2)
    window:addChild(button3)

    -- Add container to the canvas
    osrs.Ui.canvas:addChild(window)
    sizeMode: LayoutMode

    How this element should size itself.

    LayoutMode::AUTOMATIC
    
    -- Create a window that has automatic size mode, this is default
    local window1 = osrs.Ui.window({title = "Automatic Size Mode"})

    -- Create a window that has manual size mode
    local window2 = osrs.Ui.window(
    {
    title = "Manual Size Mode",
    sizeMode = osrs.Ui.LayoutMode.MANUAL,
    height = 200,
    width = 200
    }
    )

    -- Add the windows to the canvas
    osrs.Ui.canvas:addChild(window1)
    osrs.Ui.canvas:addChild(window2)
    style: StyleTable

    The style, if any, that should be applied to this element.

    tooltip: string

    String to display to the user when hovered over the element.

    -- Create new container
    local newWindow = osrs.Ui.window({title = "Example Window"})

    -- Create a button with a tooltip
    local button = osrs.Ui.textButton({text = "Test", tooltip = "This is a Tooltip!"})

    -- Add slider to the container
    newWindow:addChild(button)

    -- Add container to the canvas
    osrs.Ui.canvas:addChild(newWindow)
    visible: boolean

    Boolean indicating whether this UI element should draw itself.

    true
    
    -- Create new container
    local newWindow = osrs.Ui.window({title = "Example Window"})

    -- Create a button that is renderable, and one that is not
    local button1 = osrs.Ui.textButton(
    {
    text = "Peek-a-Boo",
    visible = false,
    onClick = function()
    osrs.print("BOO!")
    end
    }
    )
    local button2 = osrs.Ui.textButton(
    {
    text = "Render",
    onClick = function()
    button1.visible = not button1.visible
    end
    }
    )

    -- Add buttons to the container
    newWindow:addChild(button1)
    newWindow:addChild(button2)

    -- Add container to the canvas
    osrs.Ui.canvas:addChild(newWindow)
    width: number

    The width of this element, in UI coordinate space.

    -- Create a window that has a set width
    local window = osrs.Ui.window({title = "Example Window", sizeMode = 1, width = 200})

    -- Add window to the canvas
    osrs.Ui.canvas:addChild(window)
    widthRatio: number

    The percentage width of the screen this element should take up when sizeMode is set to LayoutMode.PROPORTIONAL. The number needs to be a decimal.

    -- Create new container with a set widthRatio and heightRatio
    local newWindow = osrs.Ui.window({title = "Example Window", sizeMode = 2, widthRatio = 0.7, heightRatio = .2})

    -- Add container to the canvas
    osrs.Ui.canvas:addChild(newWindow)
    x: number

    The horizontal component of this element's position, in UI coordinate space.

    -- Create a window with a set x position
    local window = osrs.Ui.window({title = "Example Window", positionMode = 1, x = 100})

    -- Add window to the canvas
    osrs.Ui.canvas:addChild(window)
    xRatio: number

    The percentage distance from the left side of the screen that this element's top-left corner should be placed at when positionMode is set to LayoutMode.PROPORTIONAL. The number needs to be a decimal.

    -- Create new container with a set xRatio and yRatio
    local newWindow = osrs.Ui.window({title = "Example Window", positionMode = 2, xRatio = 0.7, yRatio = .2})

    -- Add container to the canvas
    osrs.Ui.canvas:addChild(newWindow)
    y: number

    The vertical component of this element's position, in UI coordinate space.

    -- Create a window with a set y position
    local window = osrs.Ui.window({title = "Example Window", positionMode = 1, y = 100})

    -- Add window to the canvas
    osrs.Ui.canvas:addChild(window)
    yRatio: number

    The percentage distance from the top side of the screen that this element's top-left corner should be placed at when positionMode is set to LayoutMode.PROPORTIONAL. The number needs to be a decimal.

    -- Create new container with a set xRatio and yRatio
    local newWindow = osrs.Ui.window({title = "Example Window", positionMode = 2, xRatio = 0.7, yRatio = .2})

    -- Add container to the canvas
    osrs.Ui.canvas:addChild(newWindow)

    Methods

    • Adds a UI element to the pop up container.

      Parameters

      • element: UiPrimitive

        Imgui element to add to the pop up menu

        local button = osrs.Ui.textButton( { text="Clear", tooltip="Test" })

        local selectable = osrs.Ui.selectable({text = "Example", onClick = function() osrs.print("Example Print") end}) clear:addPopUpElement(test) osrs.Ui.leftPanel:addChild(button)

      Returns any

    • Clears the currently displayed image.

      Returns void

      local img = osrs.Ui.image({width = 100, height = 100, sizeMode = 1})
      local keyDown = function(keycode)
      img:clearImage();
      end
      -- Subscribe to the function
      osrs.Events.subscribe(keyDown, osrs.Events.KEY_DOWN)
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns the id of the image currently displayed, if either a sprite or object. via setSpriteId or setObjId. Otherwise, returns -1.

      Returns number

      Current id of the image, if sprite or obj.

      local img = osrs.Ui.image()
      img:setObjId(1511)
      if(img:getImageId() == 1511) then
      osrs.print("Image ID correctly pulled")
      end
      img:setSpriteId(780)
      if(img:getImageId() == 780) then
      osrs.print("Image ID correctly pulled")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns the relative path of the image currently displayed, if set via setImagePath. Otherwise, returns an empty string.

      Returns string

      Current path of the image, if currently displaying a local image.

      local img = osrs.Ui.image({width = 100, height = 100, sizeMode = 1})
      img:setImagePath("example.png")
      if(img:getImagePath() == "example.png") then
      osrs.print("Image Path correctly pulled")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns the URL of the image currently displayed, if set via setImageURL. Otherwise, returns an empty string.

      Returns string

      Current path of the image, if currently displaying an image via URL.

      local img = osrs.Ui.image({width = 100, height = 100, sizeMode = 1})
      img:setImageURL("https://assets.modcdn.io/images/placeholder/avatar.png")
      if(img:getImageURL() == "https://assets.modcdn.io/images/placeholder/avatar.png") then
      osrs.print("Image URL correctly pulled")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns the id of the object currently displayed by the image, if the most recent set call was setObjId. Otherwise, returns -1.

      Returns number

      Current id of the image, if object.

      local img = osrs.Ui.image()
      img:setObjId(1511)
      if(img:getObjId() == 1511) then
      osrs.print("Object ID correctly pulled")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns the id of the sprite currently displayed by the image, if the most recent set call was setSpriteId. Otherwise, returns -1.

      Returns number

      Current id of the image, if sprite.

      local img = osrs.Ui.image()
      img:setSpriteId(780)
      if(img:setSpriteId() == 780) then
      osrs.print("Sprite ID correctly pulled")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns true if the current image is set to display an object image.

      Returns boolean

      If current image is an object.

      local img = osrs.Ui.image()
      img:setObjId(780)
      if(img:isObjImage()) then
      osrs.print("This image is correctly recognized as an object")
      end
      img:setSpriteId(780)
      if(not img:isObjImage()) then
      osrs.print("This image is correctly recognized as not an object")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns true if the current image is set to display an image from a local path.

      Returns boolean

      If current image is from a local path

      local img = osrs.Ui.image()
      img:setImagePath("example.png")
      if(img:isPathImage()) then
      osrs.print("This image is correctly recognized as a local image")
      end
      img:setSpriteId(780)
      if(not img:isPathImage()) then
      osrs.print("This image is correctly recognized as not a local image")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns true if the current image is set to display a sprite image.

      Returns boolean

      If current image is a sprite.

      local img = osrs.Ui.image()
      img:setSpriteId(780)
      if(img:isSpriteImage()) then
      osrs.print("This image is correctly recognized as a sprite")
      end
      img:setObjId(780)
      if(not img:isSpriteImage()) then
      osrs.print("This image is correctly recognized as not a sprite")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns true if the current image is set to display an image from a URL.

      Returns boolean

      If current image is from a URL

      local img = osrs.Ui.image()
      img:setImagePath("example.png")
      if(not img:isURLImage()) then
      osrs.print("This image is correctly recognized as not a linked image")
      end
      img:setImageURL("https://assets.modcdn.io/images/placeholder/avatar.png")
      if(img:isURLImage()) then
      osrs.print("This image is correctly recognized as a linked image")
      end
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Returns whether the path set by setImagePath or the URL set via setImageURL are valid. Returns false and prints to development console if image is not currently set to path or URL. Note that due URL requests being asynchronous, URL validation can only occur after allowing time for the process to complete.

      Returns boolean

      whether an image has been correctly obtained after being set via path or URL.

      local img = osrs.Ui.image({width = 100, height = 100, sizeMode = 1})
      img:setImagePath("https://assets.modcdn.io/images/placeholder/avatar.png")
      if(img:isValid() == false) then
      osrs.print("Image URL recognized as not a path")
      end
      img:setImagePath("example.png")
      if(img:isValid() == true) then
      osrs.print("Image Path validated")
      end
      img:setObjId(780)
      if(img:isValid() == false) then
      osrs.print("Image recognized as not PATH or URL")
      end
      img:setImageURL("https://assets.modcdn.io/images/placeholder/avatar.png")
      osrs.setInterval(function()
      if(img:isValid() == true) then
      osrs.print("Image URL validated.")
      end
      end, 1)
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      osrs.Ui.canvas:addChild(newWindow)
    • Removes a UI element from the pop up container.

      Parameters

      • element: UiPrimitive

        Imgui element to remove from the pop up menu.

        local button = osrs.Ui.textButton( { text="Clear", tooltip="Test" })

        local selectable = osrs.Ui.selectable({text = "Example", onClick = function() osrs.print("Example Print") end}) clear:addPopUpElement(test) clear:removePopUpElement(test) osrs.Ui.leftPanel:addChild(button)

      Returns any

    • Sets the image to display the image pointed to by the provided path, relative to the plugin folder. Overwrites the current image, and sets isPathImage to return true. Additionally, getImagePath returns the provided path. All other getters return -1 or an empty string. Pass an empty string to clear active image.

      Parameters

      • path: string

        Relative path to image to display

      Returns void

      local img = osrs.Ui.image({width = 100, height = 100, sizeMode = 1})
      img:setImagePath("example.png")
      local imgBtn = osrs.Ui.imageButton({width = 100, height = 100, sizeMode = 1})
      imgBtn:setImagePath("example.png")
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      newWindow:addChild(imgBtn)
      osrs.Ui.canvas:addChild(newWindow)
    • Sets the image to display the image retrieved from the provided URL, if a valid png is linked. Overwrites the current image, and sets isURLImage to return true. Additionally, getImageURL returns the provided url. All other getters return -1 or an empty string. Pass an empty string to clear active image.

      Parameters

      • url: string

        URL of the image to display

      Returns void

      local img = osrs.Ui.image({width = 100, height = 100, sizeMode = 1})
      img:setImageURL("https://assets.modcdn.io/images/placeholder/avatar.png")
      local imgBtn = osrs.Ui.imageButton({width = 100, height = 100, sizeMode = 1})
      imgBtn:setImageURL("https://assets.modcdn.io/images/placeholder/avatar.png")
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      newWindow:addChild(imgBtn)
      osrs.Ui.canvas:addChild(newWindow)
    • Sets the image to display the object image of the provided Id. Overwrites the current image, and sets isObjImage to return true. Additionally, both getObjId and getImageId returns the provided id. All other getters return -1 or an empty string. Set to -1 to clear clear active image.

      Parameters

      • objId: number

        Id of the object to display

      Returns void

      local img = osrs.Ui.image()
      img:setObjId(1511)
      local imgBtn = osrs.Ui.imageButton({width = 100, height = 100, sizeMode = 1})
      imgBtn:setObjId(1511)
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      newWindow:addChild(imgBtn)
      osrs.Ui.canvas:addChild(newWindow)
    • Sets the image to display the sprite of the provided Id. Overwrites the current image, and sets isSpriteImage to return true. Additionally, both getSpriteId and getImageId returns the provided id. All other getters return -1 or an empty string. Set to -1 to clear clear active image.

      Parameters

      • spriteId: number

        Id of the object to display

      Returns void

      local img = osrs.Ui.image()
      img:setSpriteId(780)
      local imgBtn = osrs.Ui.imageButton({width = 100, height = 100, sizeMode = 1})
      imgBtn:setSpriteId(780)
      local newWindow = osrs.Ui.window({title="Test"})
      newWindow:addChild(img)
      newWindow:addChild(imgBtn)
      osrs.Ui.canvas:addChild(newWindow)