Drawing Surface Help [SOLVED]

Started by Atelier, Sun 30/10/2011 17:39:46

Previous topic - Next topic

Atelier

I want to adapt some code originally donated to me, to draw text onto a surface. As you know one can't draw anti-alised text onto an invisible surface (or is that possible now)? So what I do is create the text on a dynamic sprite, then put the text on top of a background of sprite slot 2.

Code: ags

DynamicSprite*Beta;
DynamicSprite*Gamma;
DynamicSprite*Final;
DrawingSurface*Surface;
bool FirstPrint = true;

function Print(String text, int colour, bool space)
{
     if (space) Print(" ", 0);   //just add an empty line to separate two paragraphs

     if (FirstPrint) {
     Beta = DynamicSprite.Create(DisplayBox.Width, DisplayBox.Height, true);
     Gamma = DynamicSprite.Create(DisplayBox.Width, DisplayBox.Height, true);       //have to define the sprites, and only once otherwise they are reset.
     Final = DynamicSprite.CreateFromExistingSprite(2);
     FirstPrint = false;
     }


     Surface = Beta.GetDrawingSurface();
     Surface.Clear();
     
     //draw new text
     Surface.DrawingColor = colour;
     int y = DisplayBox.Height - GetTextHeight(text, DisplayBox.Font, DisplayBox.Width)-2;
     Surface.DrawStringWrapped(10, y, DisplayBox.Width-10, DisplayBox.Font, eAlignLeft, text);        //draw new text at very bottom, minus however high the new text is

     //draw old text (shift current text up)
     Surface.DrawImage(0, 0 - GetTextHeight(text, DisplayBox.Font, DisplayBox.Width)-2, Gamma.Graphic);   //shift old text up by however high new text is

     Surface.Release();

     Gamma = Beta;


     Surface = Final.GetDrawingSurface();
     Surface.Clear();
     Surface.DrawImage(0, 0, 2);                       //draw a wood panel
     Surface.DrawImage(0, 0, Beta.Graphic);      //draw final text on top
     Surface.Release();

     DisplayBox.NormalGraphic = Final.Graphic;

}


Bottom line is, I understand what is happening, but I don't get why it's not working. Obviously the text ends up being anti-aliased, because it's drawn on top of a non-transparent sprite. However, it only shows the new text, and not the text that should be shifted up. It must be an obvious solution... Do I have my dynamic sprites mixed up, or is there a step I'm missing out? etc

Thanks
Atelier

Khris

I guess the problem is this line:
Code: ags
     Gamma = Beta;


This won't create a copy; all it does is that Gamma and Beta now point to the same, single sprite.

I probably should be:
Code: ags
     Gamma = DynamicSprite.CreateFromExistingSprite(Beta.Graphic);

Atelier

Woo thanks Khris, it works now :)

Just one little question. I'm guessing the sprite is auto cropped when it's set as the button graphic?

Khris

Yes, the default setting is to clip an image to the dimensions of the button.

Snarky

Really? The way I remember it, if the graphic is larger than the button, the button changes its size to fit it. Took me ages to understand what was going on and why it wasn't doing the cropping as expected.

Khris

Right, I should look at the manual first :)

Set GUIButton.ClipImage to true, it's false by default. According to the manual, the image spills over the edge of the button otherwise (as opposed to the button getting bigger).

SMF spam blocked by CleanTalk