Welcome, Guest | Home | Search | Login | Register
Author Recommended drawing text (from external file even)? (Read 25720 times)
Bolkonskij
Administrator
1024 MB
*****
Posts: 2023
View Profile Cornica - Video Entertainment for Mac OS users
on: June 19, 2024, 11:24

Guys, your discussion in the PETSCII Robots thread is inspiring and I sure hope you'll continue it. Opening this thread here for not cluttering it. Jatoba is pretty much where I was at when I last dropped everything, so this is really informative for me as well as we're moving past the usual Hello World stuff but having not yet reached the crazy C coders levels ...

I wonder what you guys figure is the most elegant way to draw text in a Window ? DrawChar() ? DrawString()? DrawText ()?

You're "layouting" text (size, shape etc.) using the Toolbox functions with stuff like TextFace(), TextFont() etc. or some other way?

Asking rather aside from the setPort / moving the Pen stuff and more wondering about the what routine do you actually use for printing and/or layouting and why?

Anyone knowing of an elegant way of fopen and fsread() an external file with chunks of text and displaying that ? Any format that is recommended on classic Macs for speedy reading? (I'm coming to this thinking in terms of what XML and lately JSON serves for in modern dev)


Quote from: lauland
Dangit!  I'd typed up a nice explanation of double buffering but then system7today went down and ate my comment.

Damn, that's bad and shouldn't happen! I had this before once where it basically timed out, but I figured it might have been my connection. Anyone else having such troubles lately?
Last Edit: June 20, 2024, 11:13 by Bolkonskij
lauland
512 MB
*****
Posts: 674
Symtes 7 Mewconer!
View Profile
Reply #1 on: June 19, 2024, 19:05

First, it depends on which system you're aiming to run on.  Since this is System7Today, and I know we all love old machines, I think assuming pre-MacOS X (6-9) is safe, eh?  So we'd just be using what is in the toolbox, and no third-party layout libraries...  (Spoiler, there is NO real layout in the toolbox, although you might consider TextEdit to be one).

Second, it depends on if you want to use proportional fonts vs fixed width...this being on Macs, I think proportional is a given, but I do mention it because if you limit yourself to fixed width, some things are trivial compared to calculating text widths, spacing, etc.  I might suggest the first version of whatever you are doing would use Monaco for the font, just to get started...

Third, in the context of games, you usually want colored and/or very fancy text...in those cases you usually end up writing your own text drawing routines and have the "font" as a bitmap file.  I know you're not talking about a game, but I wanted to mention this for completeness.

(Text "style", such as italic, bold, underline, etc is yet another thing, but we'll skip it for now).

----

Several decades ago, I was primarily an Amiga person and was very jealous of Macs.  The Amiga's default system font was fixed width, so even Infocom interactive fiction adventure games looked very bad, compared to the Mac, which was one of the few systems of the time that used proportional fonts.

So I took an existing open source Infocom interpreter that just used the terminal for input/output, and wrote a front end that opened a window and drew everything there using whatever font you wanted.

It was more painful than I naively expected. It was key to calculate the width of everything I drew before drawing it, and, obviously, if it would go off the right edge of the window, I'd need to do a newline first...go back to left side, move down a line.  And it took a lot of tweaking for line height also!  (A "fixed height" font, without decenders/etc, which most fixed width ones are, avoids a lot of this too).

I then noticed the difference between doing it by string vs by character (don't get me started about "kerning"!!!).  Drawing a string always looked better than individual characters one at a time (ie the system would decide how close the characters would be next to each other, how wide a space between words was, etc etc etc).

I never QUITE got it looking perfect to my satisfaction...but it was a real eye opener that something so simple as "just drawing text" had so many moving parts behind it.

----

What I'd suggest you do is make things as simple as possible for the start.  It doesn't really matter which toolbox call you end up using, they all do roughly the same.  Use Monaco or another fixed width font...it will make layout SO much simpler, and save a lot of frustration in your 1.0 version.

You can also make assumptions about the source text...such as that it will all fit into memory, not change (like a webpage could), or move on the screen, etc etc. 

----

Now one real pain is scrollbars, and what you do when you get to the bottom of the window...which is a whole can of worms.  Actually having a scrollable window can change everything about how you do it, you're not just drawing in the window, and will need to keep track of a LOT of things you otherwise wouldn't.  For now, on your first try, you might just let the text scroll off the top of the screen (which you'll ALSO have to handle yourself in this scenario).

Last Edit: June 19, 2024, 19:13 by lauland
Bolkonskij
Administrator
1024 MB
*****
Posts: 2023
View Profile Cornica - Video Entertainment for Mac OS users
Reply #2 on: July 24, 2025, 12:52

Kinda found an answer to my own question since posting (but thanks @lauland for your excellent advice / considerations on the matter!). Perhaps this helps somebody else looking for this:

Quote
If the intention is to draw directly to the screen (using QuickDraw), there are two routines for the job.

1.) DrawChar draws a single character.
2.) DrawString draws up to 255 at a time.

DrawString is MUCH faster than multiple "DrawChar"s.

The fastest drawing is done when the TextMode (for copying text) is set to srcOr.  This means that the fastest way to get the ROM to print text is to EraseRect an area of the screen and then to DrawString into that area in srcOr mode.


Still wondering about the fastest / easiest way to read from a "text file" and print that to the screen, ideally using only Toolbox routines.
Last Edit: July 24, 2025, 12:54 by Bolkonskij
lauland
512 MB
*****
Posts: 674
Symtes 7 Mewconer!
View Profile
Reply #3 on: July 25, 2025, 15:20

If you're talking about the reading from the file part, my advice is to use the standard lib that comes with the compiler you're using, and not the toolbox.  The toolbox routines aren't very friendly, and a bit obstuse, and the standard lib ones are dead easy to use.

If you REALLY insist on learning toolbox file routines there are more than one level of them.  The original ways using Parameter Blocks are a real pain, but then there are higher level FSSpec and FSRef ones Apple added over the years to make things much nicer.

Let me know if you really really really want to learn them, but, seriously, if you are using C, then fopen and fread are your good friends.  The equiv in Pascal are just as amicable.  Now, if you're using assembly, there isn't a standard lib...

If you're concerned with speed and the actual file reading, don't be.  The overhead of using these functions is trivial compared to the time it takes for the hardware to physically access the disk.

And if you learned how to use the standard lib, that knowledge is transferable to more "modern" systems.  If you learn the toolbox way...well...it may be "interesting" and a challenge, but I think there are more fun ways to spend time.
Pages: [1]

© 2021 System7Today.com.
The Apple Logo, Macintosh™, Mac OS™, and others property of Apple Computer, Inc.
This site is in no way affiliated with Apple Computer, Inc.