Skip to content
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ let package = Package(
),
.target(
name: "GraphiteControls",
dependencies: ["GraphiteCore"]
dependencies: ["GraphiteCore", "Graphite2D"]
),
.target(
name: "GraphiteDialogs",
Expand Down Expand Up @@ -231,15 +231,15 @@ let package = Package(
),
.testTarget(
name: "GraphiteWindowsTests",
dependencies: ["GraphiteWindows", "Graphite2D"]
dependencies: ["GraphiteWindows", "GraphiteControls", "Graphite2D"]
),
.testTarget(
name: "GraphiteMenusTests",
dependencies: ["GraphiteMenus"]
),
.testTarget(
name: "GraphiteControlsTests",
dependencies: ["GraphiteControls"]
dependencies: ["GraphiteControls", "Graphite2D"]
),
.testTarget(
name: "GraphiteDialogsTests",
Expand Down
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ add_application(AEDescLayoutCapture AEDescLayoutCapture.c)
add_application(ControlRecordCapture ControlRecordCapture.c)
add_application(ObjectSpecifierCapture ObjectSpecifierCapture.c)
target_link_libraries(ObjectSpecifierCapture ObjectSupportLib)
add_application(WindowFrameCapture WindowFrameCapture.c)
25 changes: 25 additions & 0 deletions ReferenceTests/Retro68/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,31 @@ window. The output is `ObjectSpecifier-macos-9.2.2-ppc.txt` (CR line endings).
`Descriptor.objectSpecifier(desiredClass:container:keyForm:keyData:)` builds
one, and `ObjectSpecifierTests` compares its bytes with the capture.

## Window frames

`WindowFrameCapture.c` draws a zoomable document window with a close box
(procID 8, as BBEdit Lite 6.1 opens) and its two scroll bars on a 32-bit
screen, and reads the screen back: two sizes, each active with the bars
highlighted 254, with nothing to scroll, at two thumb positions, and
inactive. The output is `WindowFrame-macos-9.2.2-ppc.txt` (CR line endings):
each picture's structure and content boxes, then a line of `count*rrggbb`
runs per row of pixels, from two pixels outside the structure.

- The structure is 22 pixels above the content, 6 left and 7 right and below,
as the window record capture found.
- The pictures include what was behind the window where the structure box
does not cover it, and its shadow.
- The VM keeps both scroll arrows together at the end of each bar.
- `PlatinumDocumentFrame` and `PlatinumScrollBar` draw all ten pictures pixel
for pixel (`WindowFrameDrawingTests`), apart from the title's text, which is
in Charcoal.
- A horizontal scroll bar was a vertical one on its side, and the edges of the
frame repeated along their length.
- Not captured: a window without a close or zoom box, pressed boxes and parts,
an active bar highlighted 255, a proportional thumb, how wide a break a title
gets in the stripes (56 pixels for "untitled"), and where a thumb goes when
its place isn't a whole pixel.

## Control records

`ControlRecordCapture.c` makes two scroll bars in a window of its own, the
Expand Down
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/WindowFrame-macos-9.2.2-ppc.txt

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions ReferenceTests/Retro68/WindowFrameCapture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Captures, pixel for pixel, a zoomable document window and its scroll bars:
* the window BBEdit Lite 6.1 opens (procID 8 with a close box). It draws on
* the main screen, which must be 32 bits deep, and reads the screen back.
*
* It writes "WindowFrame.txt" in its own folder, and refuses to run if that
* is already there. Each picture is a line naming it with the window's content
* and structure boxes, then one line of hex per row of pixels, a set bit
* black, from two pixels outside the structure.
*/
#include <Quickdraw.h>
#include <MacMemory.h>
#include <Windows.h>
#include <Files.h>
#include <Fonts.h>
#include <Menus.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <Events.h>
#include <Gestalt.h>
#include <stdio.h>
#include <string.h>

static short out;
static GDHandle screen;

static void line(const char *text)
{
long count = strlen(text);
FSWrite(out, &count, text);
count = 1;
FSWrite(out, &count, "\r");
FlushVol(0, 0);
}

static void settle(void)
{
EventRecord event;
long until = TickCount() + 30;
while (TickCount() < until)
if (WaitNextEvent(everyEvent, &event, 5, 0) && event.what == updateEvt) {
BeginUpdate((WindowPtr)event.message);
EndUpdate((WindowPtr)event.message);
}
}

/* One row of text per row of pixels: runs of "count*rrggbb". */
static void picture(const char *label, WindowPtr window)
{
static char text[4000];
WindowPeek peek = (WindowPeek)window;
Rect structure = (**peek->strucRgn).rgnBBox, content = (**peek->contRgn).rgnBBox;
Rect area = structure;
PixMapPtr map = *(**screen).gdPMap;
long rowBytes = map->rowBytes & 0x3FFF;
short x, y;

InsetRect(&area, -2, -2);
sprintf(text, "%s: structure (%d,%d,%d,%d) content (%d,%d,%d,%d) size %d %d", label,
structure.top, structure.left, structure.bottom, structure.right,
content.top, content.left, content.bottom, content.right,
area.right - area.left, area.bottom - area.top);
line(text);

for (y = area.top; y < area.bottom; ++y) {
const unsigned long *row = (const unsigned long *)
(map->baseAddr + (y - map->bounds.top) * rowBytes) - map->bounds.left;
unsigned long run = 0, value = 0;
int used = 0;
for (x = area.left; x <= area.right; ++x) {
unsigned long pixel = x < area.right ? row[x] & 0xFFFFFF : 0xFF000000;
if (run && pixel != value) {
if (used < sizeof text - 20) used += sprintf(text + used, "%lu*%06lx ", run, value);
run = 0;
}
value = pixel;
++run;
}
text[used] = 0;
line(text);
}
}

static void make(const char *name, short height, short width, ConstStr255Param title)
{
Rect bounds, vertical, horizontal;
WindowPtr window;
ControlHandle down, across;
char label[100];

SetRect(&bounds, 100, 80, 100 + width, 80 + height);
window = NewWindow(0, &bounds, title, true, 8 /* zoomDocProc */, (WindowPtr)-1L, true, 0);
SetPort(window);
/* Where a document window keeps its scroll bars. */
SetRect(&vertical, width - 15, -1, width + 1, height - 14);
SetRect(&horizontal, -1, height - 15, width - 14, height + 1);
down = NewControl(window, &vertical, "\p", true, 0, 0, 0, scrollBarProc, 0);
across = NewControl(window, &horizontal, "\p", true, 0, 0, 0, scrollBarProc, 0);

#define SHOW(what) \
do { DrawControls(window); DrawGrowIcon(window); settle(); \
sprintf(label, "%s %s", name, what); picture(label, window); } while (0)

HiliteControl(down, 254);
HiliteControl(across, 254);
SHOW("active, bars 254");

HiliteControl(down, 0);
HiliteControl(across, 0);
SHOW("active, nothing to scroll");

SetControlMaximum(down, 100);
SetControlMaximum(across, 100);
SHOW("active, at the start of 100");

SetControlValue(down, 50);
SetControlValue(across, 100);
SHOW("active, down at 50 and across at 100");

HiliteWindow(window, false);
HiliteControl(down, 255);
HiliteControl(across, 255);
SHOW("inactive, bars 255");

DisposeWindow(window);
settle();
}

int main(void)
{
static const unsigned char file[] = { 15, 'W','i','n','d','o','w','F','r','a','m','e','.','t','x','t' };
short depth, ref;
char text[100];


if (FSOpen(file, 0, &ref) == noErr) { FSClose(ref); return 1; }
if (Create(file, 0, 'Grph', 'TEXT') != noErr) return 2;
if (FSOpen(file, 0, &out) != noErr) return 3;

InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0);
InitCursor();

screen = GetMainDevice();
depth = (**(**screen).gdPMap).pixelSize;
sprintf(text, "depth before -> %d", depth);
line(text);
if (depth == 32) {
long qd = 0;
Gestalt('qd ', &qd);
sprintf(text, "gestalt qd -> %lx", qd);
line(text);
HideCursor();
settle();
make("untitled 200x320", 200, 320, "\puntitled");
make("empty title 120x240", 120, 240, "\p");
ShowCursor();
}

line("done");
FSClose(out);
FlushVol(0, 0);
return 0;
}
31 changes: 31 additions & 0 deletions Sources/Graphite2D/PixelArt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// What drawing a window's frame and its controls takes: flat colors and the
// small pictures of boxes and arrows, drawn in a port within what it can draw.

import GraphiteCore

public extension Port {

/// Fills a rectangle with a color, whatever the port's colors, pattern and
/// pen, which are left as they were.
func paint(_ rect: Rect, color: RGBColor) {
guard !rect.isEmpty else { return }
let saved = foreColor
foreColor = color
draw(Region(rect: rect), pattern: .black, mode: .patCopy)
foreColor = saved
}

/// Draws a picture written as rows of characters, its top left at
/// `origin`: each character `colors` has paints a pixel, the others none.
/// Transposed, the rows are columns.
func paint(_ rows: [String], at origin: Point, colors: [Character: RGBColor], isTransposed: Bool = false) {
for (v, row) in rows.enumerated() {
for (h, character) in row.enumerated() {
guard let color = colors[character] else { continue }
let top = origin.v &+ Int16(isTransposed ? h : v)
let left = origin.h &+ Int16(isTransposed ? v : h)
paint(Rect(top: top, left: left, bottom: top &+ 1, right: left &+ 1), color: color)
}
}
}
}
Loading
Loading