Announcement

Collapse
No announcement yet.

Horizontal Text On Canvas

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Horizontal Text On Canvas

    I have this HUD that draws a beacon over a persons head but i wanted it horizontal and beside the pawn.

    Ii just need to know:

    How Do I Draw Horizontal Text On A Canvas???
    ME AND MY DAMM TYPOS! I ment Verticaly
    Thanks For Any Offered Help In Advance

    #2
    Hmm. Canvas drawing is fun.

    I'm going to assume you want to use DrawText(), because thats what you said. If not, you'll have to adapt it for your own needs.

    Essentially, you'll want to do this:

    Load your font...
    Canvas.Font = MyFont;

    Font color...
    Canvas.DrawColor = MyFontColor;

    Now for the meat and 'taters....

    Get the HEIGHT of a line of text drawn in your font (X and Y are floats that will recieve the height and length of the string we use, but we only need the height. It's very important to load the font first, because the canvas uses the current font in it's calculations and loading it afterwards makes the length and height wrong)...
    Canvas.StrLen("Q|",X,Y);

    Get the length of text you want to draw vertically...
    j = Len(SomeText);

    If you want to scale the text size down a bit, you can use this before you draw...
    Canvas.FontScaleX=1.0;
    Canvas.FontScaleY=1.0;

    Then set the canvas position to where you want to start drawing (you'll have to decide where yourself, I'm not here to do it all for you), and use the Y we got before as a line height, and iterate through the string drawing each character on a new line (PosY + Y * i)...
    for (i=0,i<j;i++)
    {
    Canvas.SetPos(PosX,PosY + Y * i);
    Canvas.DrawText(Mid(SomeText,i,1));
    }

    Note the variable names, I kept them the same so you could understand how it works. Again, I'm not going to do it for you, but you now know how to draw vertical text. :bulb:

    Bow down to those who do HUD work.

    Comment


      #3
      **** i just realized i had a typo! i want it vertically as in:

      B
      1
      G
      4


      now will that code do it or did my typo mess up ur answer?

      Comment


        #4
        No, I assumed you meant vertically, lol.

        Comment


          #5
          SW33TN3SS Thanks, now constantly changing the pos and redraw more will not creat anylagg at all will it? just a thaught

          Comment


            #6
            You'll be drawing each time a frame is rendered anyway, so you can set to any position each time you draw it, and it wont have any effect on performance compared to drawing it in the exact same place every time.

            HUD drawing accounts for about 60% of the execution time for a game anyway (at least for uscript execution time).

            Comment


              #7
              Well Thx Man Im Gana Try It

              Comment


                #8
                Uhhh ok i got confuzed, how would i fix this?
                Code:
                simulated function RenderOneBeacon (Canvas C, vector TrgLocation, string s, color BeaconColor, color BeaconNameColor, int ExtraHeight, bool DrawTile, string Nick)
                {
                	local Vector HUDCoords, v, l;
                	local rotator r;
                	local float xp, yp, scale;
                
                	C.DrawColor = BeaconColor;
                	C.Font = GetFontSizeIndex(C,-4);
                	HUDCoords=TrgLocation;
                	HUDCoords.Z += ExtraHeight;
                	l = HUDCoords;
                	HUDCoords=C.WorldToScreen(HUDCoords);
                	if ( HUDCoords.Z >= 1.00 )
                		return;
                	C.GetCameraLocation(v,r);
                	scale=fclamp(45.0/sqrt(vsize(l-v)*tan(level.GetLocalPlayerController().FovAngle*pi/360)),0.5,1.0);
                	C.SetPos( HUDCoords.X - (RXSize / 2)*scale, HUDCoords.Y - RYSize*scale);
                	if (DrawTile)
                		C.DrawTile( BeaconMat, RXSize*scale, RYSize*scale, 0.0, 0.0, BeaconMat.USize, BeaconMat.VSize);
                
                	// Draw Vertical Text //
                	if (s != "")
                	{
                		C.StrLen(s,xp,yp);	
                		xp *= 0.5;			
                		if (HUDCoords.X + xp < C.ClipX) 
                		{     
                			C.DrawColor = WhiteColor;
                			C.SetPos( HUDCoords.X - xp, HUDCoords.Y - RYSize*scale - yp);
                			C.DrawTextClipped(s);
                		}     
                	}
                	C.curx = HUDCoords.X;
                }

                Comment


                  #9
                  Actally i think i got it

                  SWEET I GOT IT MAN ITS PERFECT THX!

                  Comment


                    #10
                    Nice.

                    :up:

                    Comment

                    Working...
                    X