Rendering Text Indiscriminately over the Screen

Started by Scavenger, Wed 10/07/2013 10:25:46

Previous topic - Next topic

Scavenger

I'm trying to make a way of rendering indiscriminate error messages onto the screen, like this: Example here, but typed over the top of the game's screen, with a black background. If you've ever played a DOS game and it's suddenly booted you to the DOS prompt at 320x200 and printed a whole load of bytecodes at you written directly over the top of the video buffer, that's exactly what I'm going for.

So far I've tried:
Code: AGS
  function Print_ErrorText (String text, int x, int y)
{
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground(); // I'm just testing here, obviously it won't work with characters over the top or with scrolling rooms. Probably should go with making one from a Screenshot and putting it on an Overlay.
  surface.DrawingColor = 255;  // True Black
  surface.DrawRectangle (x, y, GetTextWidth (text, eFontMetaverseText) + 1,  GetTextHeight (text,eFontMetaverseText, GetTextWidth (text,eFontMetaverseText) + 1));
  surface.DrawingColor = 15; // True White
  surface.DrawString (x, y, eFontMetaverseText, text);
  surface.Release ();
}

But it doesn't seem to work right at all, and I have to manually specify where I want the text to go. Ideally, I'd want to be able to just print a bunch of garbage to the screen line by line with it wrapping round and leaving the underlying image intact. But the black boxes I draw don't line up with the text I've drawn /at all/. I'm not sure what I'm doing wrong here - the boxes and the text will misalign vertically and often the boxes will be twice to three times the size of the text (again, vertically only). I've tried to fix it several times but every time it just comes out.... wrong. I'm probably being stupid and missing something simple, but I probably need a fresh pair of eyes to look at it.

Thankyou for the help!

Crimson Wizard

DrawRectangle specification is:
Code: ags

DrawingSurface.DrawRectangle(int x1, int y1, int x2, int y2)

The last two parameters are Right and Bottom coordinates, while you are sending Width and Height there.

Maybe this will work better:
Code: ags

int text_width = GetTextWidth (text, eFontMetaverseText);
int text_height = GetTextHeight (text, eFontMetaverseText, text_width  + 1);
surface.DrawRectangle (x, y, x + text_width, y + text_height);


Also pay attention to the note:
Quote
NOTE: The X and Y co-ordinates given are ROOM co-ordinates, not SCREEN co-ordinates. This means that in a scrolling room you can draw outside the current visible area.

Scavenger

Quote from: Crimson Wizard on Wed 10/07/2013 10:48:49
The last two parameters are Right and Bottom coordinates, while you are sending Width and Height there.

Oh man, I why didn't I see that before? Thankyou! It was something stupid!

Crimson Wizard

Quote from: Scavenger on Wed 10/07/2013 10:54:12It was something stupid!

I don't agree ;). This x1,y1,x2,y2 form of defining rectangles does not work well for the games, in my opinion. In most cases you want a rect of fixed size, not the one defined by two points, and it is more intuitive thing to do.

selmiak

@Scavenger: I should stop reading your technical questions or I know how death wore endless feathers plays before even playing it... :P

Crimson Wizard

Quote from: selmiak on Tue 16/07/2013 18:33:00
@Scavenger: I should stop reading your technical questions or I know how death wore endless feathers plays before even playing it... :P
Yeah, that could be frightening to know what @#$% are all famous games inside.

Err... nevermind, nevermind, j/k  (laugh)

Scavenger

Quote from: selmiak on Tue 16/07/2013 18:33:00
@Scavenger: I should stop reading your technical questions or I know how death wore endless feathers plays before even playing it... :P

Unless you count "Scavenger is a very poor programmer" as a spoiler, I'm not sure what exclusive gameplay leaks I'm going to have in my tech threads. x3

selmiak

nah, no real leaks, it's just that I'm reading snow crash atm and then your nice pics of the metaverse and then this thread about displaying errormessages and my imagination goes wild ;)

SMF spam blocked by CleanTalk