displaying image

Discuss the development of Lua addons for Ashita here.
Locked
gilles
Posts: 14
Joined: Sun May 15, 2016 1:53 pm

displaying image

Post by gilles » Sun May 15, 2016 1:59 pm

is there some code to display an image ?
i didn't get much result with this :

Code: Select all

local f = AshitaCore:GetFontManager():CreateFontObject( '__addon' );
local prim = f:GetBackground();
prim:SetPositionX( 0 );
prim:SetPositionY( 0 );
prim:SetWidth( 5 );
prim:SetHeight( 5 );
prim:SetColor( 0xFF080808 );
prim:SetTextureFromFile('d:\\haste.png');
prim:SetVisibility( true );

f:SetPosition( 50, 50 );
f:SetText( '         ' );
f:SetVisibility( true );
also, what are image format supported ? bmp, jpg... ?
User avatar
atom0s
Site Admin
Posts: 304
Joined: Sat May 14, 2016 5:13 pm

Re: displaying image

Post by atom0s » Mon May 16, 2016 12:04 am

Your code is fine, just keep in mind the color is handled as a mask. So if you want the image to render the way it is on disk, just use the color 0xFFFFFFFF. Then you can adjust it as desired to mask it how you want.

In terms of bare-minimum, this is all you need to just display an image at the given location:
  1. local f = AshitaCore:GetFontManager():CreateFontObject('testObject');
  2. f:SetVisibility(true);
  3. f:SetPosition( 50, 50 );
  4.  
  5. local p = f:GetBackground();
  6. p:SetTextureFromFile('C:\\derp.png');
  7. p:SetColor(0xFFFFFFFF);
  8. p:SetWidth(100);
  9. p:SetHeight(95);
  10. p:SetVisibility(true);
I also recommend that you make use of the 'SetLockPosition' function on the font objects if you plan to do this to prevent people from moving them with their mouse by accident.

Code: Select all

f:SetLockPosition(true);
Lead Ashita Developer
Locked