ThinkC [Study Group 1] Drawing on the Macintosh

Relating to ThinkC Development

BFEXTU

Tinkerer
Jul 15, 2022
177
147
43
I just looked at Inside Mac 1, and was reminded of another fun use of the command key when dragging windows. Doing a command+drag lets you move a window without making it the active window.

Oh, also, you may or may not know that if you hold down command key and click on the window title, it gives you a pop-up of the navigation hierarchy -- at least in System 6 and later.
 

OneGeekArmy

Tinkerer
Oct 31, 2021
95
246
33
Belgium
diskjockey.onegeekarmy.eu
I just looked at Inside Mac 1, and was reminded of another fun use of the command key when dragging windows. Doing a command+drag lets you move a window without making it the active window.

Oh, also, you may or may not know that if you hold down command key and click on the window title, it gives you a pop-up of the navigation hierarchy -- at least in System 6 and later.

It still does in the latest version of macOS. I've been using the same keyboard shortcuts for over 30 years and that's kind of amazing (and this works also from a Terminal window title, which is neat).
 
  • Like
Reactions: BFEXTU

Mu0n

Active Tinkerer
Oct 29, 2021
609
560
93
Quebec
www.youtube.com
Went through the examples to make sure there was no typo in the manual fairly quickly, there are lots of recycling for many of those functions across the four examples of that chapter:

1662049780165.png


1662049812839.png


1662049834185.png


1662049855667.png



I found a typo in FlyingLines, page 116, in the MainLoop
Code:
for(i=kNumLines-1; i>0; i-)

should be instead
Code:
for(i=kNumLines-1; i>0; i--)

they forgot one - symbol in the decrementation of the i variable


I'll post my own derivative program based on the teachings of this chapter in a few days.
 

Eric's Edge

Tinkerer
Oct 31, 2021
121
87
28
Went through the examples to make sure there was no typo in the manual fairly quickly, there are lots of recycling for many of those functions across the four examples of that chapter:

View attachment 8457

View attachment 8458

View attachment 8459

View attachment 8460


I found a typo in FlyingLines, page 116, in the MainLoop
Code:
for(i=kNumLines-1; i>0; i-)

should be instead
Code:
for(i=kNumLines-1; i>0; i--)

they forgot one - symbol in the decrementation of the i variable


I'll post my own derivative program based on the teachings of this chapter in a few days.
I just looked at my physical copy of the book, I penciled in the correction so well I didn't notice it.
 

atariorbit

Tinkerer
Nov 1, 2021
27
25
13
OK for this week I was able to brute force a mock up of the main UI. Glancing ahead esp with Dialogs, I'm thinking that a dialog would be used to edit each of these fields and writing out the strings to the rsrc file will save them (the "working with dialogs chapter"). I'm looking around to how to define and make a button to lauch the dialog and allow me to edit, but for now this is good practise with playing with the coordinate system in the apps....

Here is what the FujiNet CONFIG screen looks like (on an atari) https://www.ataridude.net/images/fujinet-config.jpg

This project will recreate that for the Mac. Of course I need to connect to the OS and send SmartPort commands down via the floppy device in order to manipulate the FujiNet connected to it.. but that will come in time.

Now I'm going to use amend to save this project and figure out the easiest way to get from my vMac over to a real SE for continued development.
 

Attachments

  • Screen Shot 2022-09-03 at 3.49.05 PM.png
    Screen Shot 2022-09-03 at 3.49.05 PM.png
    22.4 KB · Views: 76
  • Screen Shot 2022-09-03 at 3.51.59 PM.png
    Screen Shot 2022-09-03 at 3.51.59 PM.png
    18 KB · Views: 77
  • Like
Reactions: Patrick and eric

Crutch

Tinkerer
Jul 10, 2022
293
228
43
Chicago
Nice setup! If you aren’t already, you can use GetFontInfo() to obtain text line height for a font and advance the appropriate amount rather than storing each line’s position in a constant.
C:
FontInfo fInfo;
short lineHeight;
...
GetFontInfo(&fInfo);
lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
...
MoveTo(x, y);
DrawString("\pLine 1");
MoveTo(x, y + lineHeight);
DrawString("\pLine 2");
 

pfuentes69

Active Tinkerer
Oct 27, 2021
380
293
63
Switzerland
Hi guys,
I'd appreciate if some of you can try to run something in a real Mac.
These days I'm travelling and using Basilisk to follow the study group, and I have very weird behaviours, and I'd like to know if it's because the emulation, or is the compiler, or it's my code.

I'm trying to apply the concepts to build an interactive 3D viewer, starting by the basics. I made an app that should show a cube and slightly rotate it when redrawing the window.

Screenshot 2022-09-05 at 00.10.04.png


To test it, please download the SIT in this link. Then open the app and go to "File" / "New Scene". It should show a cube that rotates if you click in the window or if you resize the window to force a redraw.

This works, but it does funky things. For example, when opening the window, it won't show the cube, only after resizing it will start showing it. In some cases the cube will disappear or show weird lines.

Please let me know if you can run this in a real machine and if it does also those weird things.

Thanks!
 

jenna32bit

New Tinkerer
Aug 19, 2022
13
7
3
United States
On my IIfx I get pretty much a blank screen. Are any of the drop down menus meant to be working? I can get a new scene, it shows a couple specks, when I click on that they go away. None of the menus seem to do much of anything.
 
Last edited:
  • Like
Reactions: atariorbit

Crutch

Tinkerer
Jul 10, 2022
293
228
43
Chicago
Suggestion: If you want to share code for thoughts or feedback just linking the .c text file would be helpful and allow more people to instantly take a look while using their phone, iPad etc.
 
  • Like
Reactions: jenna32bit

pfuentes69

Active Tinkerer
Oct 27, 2021
380
293
63
Switzerland
On my IIfx I get pretty much a blank screen. Are any of the drop down menus meant to be working? I can get a new scene, it shows a couple specks, when I click on that they go away. None of the menus seem to do much of anything.
Thanks.
Only the File/New option should work by now.
What happens if you resize the window several times? Does it show something like the capture above?
 

pfuentes69

Active Tinkerer
Oct 27, 2021
380
293
63
Switzerland
Suggestion: If you want to share code for thoughts or feedback just linking the .c text file would be helpful and allow more people to instantly take a look while using their phone, iPad etc.
Yes, but it’s OOP and this involves several files… sharing only a part of the code would be confusing.
if I don’t identify the issue I’ll extract the code and make a simpler demo that only draws the cube.
 

jenna32bit

New Tinkerer
Aug 19, 2022
13
7
3
United States
Nope, still a blank. Sometimes a single pixel or line at most. Not sure where this relates to the current chapter without sharing code. Maybe better in its own thread?
 

pfuentes69

Active Tinkerer
Oct 27, 2021
380
293
63
Switzerland
Nope, still a blank. Sometimes a single pixel or line at most. Not sure where this relates to the current chapter without sharing code. Maybe better in its own thread?
Thanks.

I think I know what's going on. It's some problem with variable initialisation. I'll open a new thread if I keep having issues.
 

atariorbit

Tinkerer
Nov 1, 2021
27
25
13
Nice setup! If you aren’t already, you can use GetFontInfo() to obtain text line height for a font and advance the appropriate amount rather than storing each line’s position in a constant.
C:
FontInfo fInfo;
short lineHeight;
...
GetFontInfo(&fInfo);
lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
...
MoveTo(x, y);
DrawString("\pLine 1");
MoveTo(x, y + lineHeight);
DrawString("\pLine 2");

Thanks- this is exaclty what I was hoping with for this collab. I'll add some logic into my massively hardcoded project!
 

atariorbit

Tinkerer
Nov 1, 2021
27
25
13
So I've been jumping around, way ahead in the textbook- and took the time to look at the 'big' project in a few chapters- the Reminder App. I really love the 'Going thru the code line by line' portions from Mark as he really breaks this down into small parts to think about.

Point is- wow, you have to handle a lot when you reach any level of complexity in an app. I mean, of course you do, but I tend not to think into the details - esp since I really don't do any C programming for the mac lol.. But wow, you have to handle everything- but on the other side there is an incredible amount that the System ROM (ToolBox) is doing for you even at this level (System 6 and 7). The applications on the classic mac are really a concert between your app and pushing and getting events to and from the OS, and using the ToolBox for all the low-level grphical stuff for the UI. Handling mouse clicks, sending them off, checking Event queues- it's all interesting since it makes way more sense to me now than it did years ago when I looked at these things (again, not as a dev but as a tinkerer). It seems almost doable now with that 90's level of System OS tech.



One question I'll throw out for the more experienced people, since I have read zero of the Inside the mac esp none of VI -- I have nothing to draw on for the proper UI ways other than using a Mac for many years....

If I have this App I'm designing (see above) which has say 8 editable fields - I'm trying to decide how to manage a user editing them. At first I thought they'd be editable fields and as a user clicks in they become editable, clicking away saves them- but there are no examples of this in the book, and therefore probably quite complex to handle at this point.

Should they be handled by a Menu Item? Choosing a menu item can launch a Dialog which then allows editing...

Or should there be a small edit button by each field, clicking launches a dialog to edit?


Also I will handle key presses to launch dialogs for user interaction, but clearly the Mac way is probably the Menu and creating my own entries there.

-andy
 

Crutch

Tinkerer
Jul 10, 2022
293
228
43
Chicago
@atariorbit You have spotlighted something that I’ve always found a little awkward in coming up a Mac “configs” type dialog … there is actually no (supported) way to change a static text item to editable text and back. I always thought this feature should exist. (Clicking a static text item to make it editable would be nonstandard behavior on the Mac, but it would make sense to have a “Change” button next to a given static item that makes it editable temporarily. One could hack this up by showing/hiding items but it’s inelegant.)

Anyway the standard thing would be to have a “Preferences” option, probably under the Edit menu. Then you would pop up a dialog with a bunch of editable fields. Clicking OK validates and saves all of them at once.
 

Mu0n

Active Tinkerer
Oct 29, 2021
609
560
93
Quebec
www.youtube.com
This works, but it does funky things. For example, when opening the window, it won't show the cube, only after resizing it will start showing it. In some cases the cube will disappear or show weird lines.

Please let me know if you can run this in a real machine and if it does also those weird things.

Thanks!

Here's some straight video capture from my Mac Plus, System 6.0.8, can't get more real machine than this! (low res but you get what happens...)

 

Mu0n

Active Tinkerer
Oct 29, 2021
609
560
93
Quebec
www.youtube.com
As for my SE/30 running 7.5.3, the default window almost creates a weird single line that goes from edge of window to center, or is just a small segment to the left edge of the window. If I futz around by resizing the window, moving it and reclicking, I can get a recognizeable shape such as this. It seems to struggle between local and global coordinates, is my guess?

1662409950151.png
 

atariorbit

Tinkerer
Nov 1, 2021
27
25
13
@atariorbit You have spotlighted something that I’ve always found a little awkward in coming up a Mac “configs” type dialog … there is actually no (supported) way to change a static text item to editable text and back. I always thought this feature should exist. (Clicking a static text item to make it editable would be nonstandard behavior on the Mac, but it would make sense to have a “Change” button next to a given static item that makes it editable temporarily. One could hack this up by showing/hiding items but it’s inelegant.)

Anyway the standard thing would be to have a “Preferences” option, probably under the Edit menu. Then you would pop up a dialog with a bunch of editable fields. Clicking OK validates and saves all of them at once.

Ok, this is very helpful. So having a 'live' editable text area on a window (not a dialog) is not The Way. Fair enough. It's a modern convention that we've just become accustomed to I guess.

I'm going to play with a menu for the learning and to use it to launch a dialog that will allow me to set the hostnames for each of the remote hosts then. I'm guessing I'll just have a Menu item for each host, selecting it will launch the same dialog but allow the host name to be edited. Good practice any way to play with the Menu bar and writing out prefs into the resource file.
 

pretzelFTW

New Tinkerer
Sep 5, 2022
26
8
3
On Page 84, where it talks about changing the font:

C:
GetFNum("\pMonaco", &fontNum);

if (fontNum != 0) {
    TextFont(fontNum);
}

I’m noticing that only two fonts work – the system font (Chicago), and the application font (Geneva). Any other number I pass into TextFont() seems to result in Geneva.

Any idea why that’s not working? Is it a System 7 thing? (I’m running System 6).