Difference between revisions of "DrawIcon"

From King Arthur's Gold Wiki
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<onlyinclude>
 
<onlyinclude>
Draws an icon.
+
Draws an icon from the given file.
 
</onlyinclude>
 
</onlyinclude>
 +
 +
As this is GUI-related it is client only - it should be wrapped in "if ( getNet().isClient() )" or be in a client-only script.
 +
 +
This method is part of the GUI namespace so you need to prefix calls to it with 'GUI::'.
  
 
There are 4 variants of this method.
 
There are 4 variants of this method.
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
void DrawIcon( const string &textureFilename, int iconFrame, dimension2di frameDimension, position2di pos )
+
void GUI::DrawIcon( const string &textureFilename, int iconFrame, dimension2di frameDimension, position2di pos )
void DrawIcon( const string &textureFilename, int iconFrame, dimension2di frameDimension, position2di pos, f32 scale )
+
void GUI::DrawIcon( const string &textureFilename, int iconFrame, dimension2di frameDimension, position2di pos, f32 scale )
void DrawIcon( const string &textureFilename, position2di pos )
+
void GUI::DrawIcon( const string &textureFilename, position2di pos )
void DrawIcon( const string &textureFilename, position2di pos, f32 scale )
+
void GUI::DrawIcon( const string &textureFilename, position2di pos, f32 scale )
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Latest revision as of 22:18, 6 September 2012

Draws an icon from the given file.


As this is GUI-related it is client only - it should be wrapped in "if ( getNet().isClient() )" or be in a client-only script.

This method is part of the GUI namespace so you need to prefix calls to it with 'GUI::'.

There are 4 variants of this method.

void GUI::DrawIcon( const string &textureFilename, int iconFrame, dimension2di frameDimension, position2di pos )
void GUI::DrawIcon( const string &textureFilename, int iconFrame, dimension2di frameDimension, position2di pos, f32 scale )
void GUI::DrawIcon( const string &textureFilename, position2di pos )
void GUI::DrawIcon( const string &textureFilename, position2di pos, f32 scale )

Example from Entities/Workshops/Scripts/DrawTasks.as:

if ((getControls().getMouseScreenPos() - pos2d).getLength() < 2*this.getBlob().getRadius())
{
  CProperties @prop = this.getBlob().getProperties();
  int tasksCount = prop.getScriptObjectGroupSize( "running_tasks" );
  for (int i = 0; i < tasksCount; i++)
  {
    WorkshopTask @task = cast<WorkshopTask@>(prop.getScriptObject( "running_tasks", i));
 
    int width = 92;
    int height = 32;
    int top = pos2d.Y - this.getBlob().getHeight();
    int margin = 4;
    recti rect( position2di(pos2d.X-width/2, top-height - i*height),
    position2di(pos2d.X+width/2, top - i*height) );
 
    f32 progress = float(task.timeCurrent) / float(task.timeEnd);
 
    GUI::DrawSunkenPane( rect );
    GUI::DrawProgressBar( recti( position2di(rect.UpperLeftCorner.X+margin, rect.UpperLeftCorner.Y+margin),
      position2di(rect.LowerRightCorner.X-32-margin, rect.LowerRightCorner.Y-margin) ), progress );
    GUI::DrawIcon( task.iconName, position2di(rect.LowerRightCorner.X-36, rect.UpperLeftCorner.Y) );  }		
}