/** ** Draw mana/working sprite. ** ** @param x X screen pixel position ** @param y Y screen pixel position ** @param type Unit type pointer ** @param full Full value ** @param ready Ready value */ local void DrawManaSprite(int x,int y,const UnitType* type,int full,int ready) { int n; if( !full ) { return; } n=VideoGraphicFrames(ManaSprite.Sprite)-1; n-=(n*ready)/full; DebugCheck( n<0 || n>=VideoGraphicFrames(ManaSprite.Sprite)) ; if( ManaSprite.HotX<0 ) { x+=ManaSprite.HotX +(type->TileWidth*TileSizeX+type->BoxWidth+1)/2; } else if( ManaSprite.HotX>0 ) { x+=1-ManaSprite.HotX +(type->TileWidth*TileSizeX-type->BoxWidth)/2; } else { x+=(type->TileWidth*TileSizeX-ManaSprite.Width+1)/2; } if( ManaSprite.HotY<0 ) { y+=ManaSprite.HotY +(type->TileHeight*TileSizeY+type->BoxHeight+1)/2; } else if( ManaSprite.HotY>0 ) { y+=1-ManaSprite.HotY +(type->TileHeight*TileSizeY-type->BoxHeight)/2; } else { y+=(type->TileHeight*TileSizeY-ManaSprite.Height+1)/2; } VideoDrawClip(ManaSprite.Sprite,n,x,y); }
/** ** Draw (sprite) cursor when visible, defined by ** OldCursorW (!=0),.. ** Pre: for this to work OldCursorW should be 0 upfront ** ** @param type Cursor-type of the cursor to draw. ** @param x Screen x pixel position. ** @param y Screen y pixel position. ** @param frame Animation frame # of the cursor. */ local void DrawCursor(const CursorType* type,int x,int y,int frame) { int size; int w; int h; int spritex; int spritey; // // Save cursor position and size, for faster cursor redraw. // spritex=(x-=type->HotX); spritey=(y-=type->HotY); w=VideoGraphicWidth(type->Sprite); h=VideoGraphicHeight(type->Sprite); //Reserve enough memory for background of sprite (also for future calls) size=w*h*MemSize; if( OldCursorSize<size ) { if( OldCursorImage ) { OldCursorImage=realloc(OldCursorImage,size); } else { OldCursorImage=malloc(size); } OldCursorSize=size; } //Save (seen) area behind sprite CLIP_RECTANGLE(x,y,w,h); SaveCursorBackground(OldCursorX=x,OldCursorY=y,OldCursorW=w,OldCursorH=h); //Draw sprite (using its own clipping) FIXME: prevent clipping twice VideoDrawClip(type->Sprite,frame,spritex,spritey); OldCursorInvalidate=1; }
/** ** Draw the sprite with the player colors ** ** @param type Unit type ** @param sprite Original sprite ** @param player Player number ** @param frame Frame number to draw. ** @param x X position. ** @param y Y position. */ void DrawUnitPlayerColor(const CUnitType *type, CGraphic *sprite, int player, int frame, int x, int y) { int f; if (type->Flip) { if (frame < 0) { f = -frame - 1; } else { f = frame; } } else { int row; row = type->NumDirections / 2 + 1; if (frame < 0) { f = ((-frame - 1) / row) * type->NumDirections + type->NumDirections - (-frame - 1) % row; } else { f = (frame / row) * type->NumDirections + frame % row; } } if (!sprite->PlayerColorTextures[player]) { MakePlayerColorTexture(sprite, player, &Players[player].UnitColors); } // FIXME: move this calculation to high level. x -= (type->Width - type->TileWidth * TileSizeX) / 2; y -= (type->Height - type->TileHeight * TileSizeY) / 2; if (type->Flip) { if (frame < 0) { VideoDrawClipX(glsprite[player], -frame - 1, x, y); } else { VideoDrawClip(glsprite[player], frame, x, y); } } else { int row; row = type->NumDirections / 2 + 1; if (frame < 0) { frame = ((-frame - 1) / row) * type->NumDirections + type->NumDirections - (-frame - 1) % row; } else { frame = (frame / row) * type->NumDirections + frame % row; } VideoDrawClip(glsprite[player], frame, x, y); } }
/** ** Draw construction. ** ** @param construction Construction pointer. ** @param frame Frame number to draw. ** @param x X position. ** @param y Y position. */ global void DrawConstruction(const Construction* construction,int frame, int x,int y) { // FIXME: This should be moved to caller/init... x-=construction->Width/2; y-=construction->Height/2; VideoDrawClip(construction->Sprite,frame,x,y); }