Files
Aerofoil/GpApp/Coordinates.cpp

201 lines
5.1 KiB
C++
Raw Permalink Normal View History

2019-11-11 00:11:59 -05:00
//============================================================================
//----------------------------------------------------------------------------
// Coordinates.c
//----------------------------------------------------------------------------
//============================================================================
#include "PLNumberFormatting.h"
#include "PLPasStr.h"
2019-12-30 20:53:11 -05:00
#include "PLStandardColors.h"
2019-11-11 00:11:59 -05:00
#include "Externs.h"
#include "Environ.h"
#include "Marquee.h"
#include "ObjectEdit.h"
#include "RectUtils.h"
2020-05-21 03:30:11 -04:00
#include "ResolveCachingColor.h"
#include "WindowDef.h"
2020-01-05 02:33:03 -05:00
#include "WindowManager.h"
2019-11-11 00:11:59 -05:00
Rect coordWindowRect;
WindowPtr coordWindow;
short isCoordH, isCoordV;
short coordH, coordV, coordD;
Boolean isCoordOpen;
//============================================================== Functions
//-------------------------------------------------------------- SetCoordinateHVD
// Given a horizontal, vertical and distance value, this function<6F>
// displays these values in the Coordinates window.
void SetCoordinateHVD (short h, short v, short d)
{
#ifndef COMPILEDEMO
if (h != -2)
coordH = h;
if (v != -2)
coordV = v;
if (d != -2)
coordD = d;
UpdateCoordWindow();
#endif
}
//-------------------------------------------------------------- DeltaCoordinateD
// When the user is dragging a handle (such as the height of a blower)<29>
// this function can be called and passed the amount by which the user<65>
// has changed the height (delta). This function then displays it in<69>
// the Coordinate window.
void DeltaCoordinateD (short d)
{
#ifndef COMPILEDEMO
coordD = d;
UpdateCoordWindow();
#endif
}
//-------------------------------------------------------------- UpdateCoordWindow
// Completely redraws and updates the Coordinate window.
void UpdateCoordWindow (void)
{
#ifndef COMPILEDEMO
Str255 tempStr, numStr;
if (coordWindow == nil)
return;
2019-12-30 20:53:11 -05:00
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White();
PortabilityLayer::ResolveCachingColor blueColor = StdColors::Blue();
PortabilityLayer::RenderedFont *appFont = GetFont(PortabilityLayer::FontPresets::kApplication9);
2020-05-21 05:01:16 -04:00
2019-12-30 20:53:11 -05:00
DrawSurface *surface = coordWindow->GetDrawSurface();
2020-05-21 03:30:11 -04:00
surface->FillRect(coordWindowRect, whiteColor);
2019-12-30 20:53:11 -05:00
2019-11-11 00:11:59 -05:00
PasStringCopy(PSTR("h: "), tempStr);
if (coordH != -1)
{
NumToString((long)coordH, numStr);
PasStringConcat(tempStr, numStr);
}
else
PasStringConcat(tempStr, PSTR("-"));
2019-12-30 20:53:11 -05:00
2020-05-21 05:01:16 -04:00
surface->DrawString(Point::Create(5, 12), tempStr, blackColor, appFont);
2019-11-11 00:11:59 -05:00
PasStringCopy(PSTR("v: "), tempStr);
if (coordV != -1)
{
NumToString((long)coordV, numStr);
PasStringConcat(tempStr, numStr);
}
else
PasStringConcat(tempStr, PSTR("-"));
2019-12-30 20:53:11 -05:00
2020-05-21 05:01:16 -04:00
surface->DrawString(Point::Create(4, 22), tempStr, blackColor, appFont);
2019-11-11 00:11:59 -05:00
PasStringCopy(PSTR("d: "), tempStr);
if (coordD != -1)
{
NumToString((long)coordD, numStr);
PasStringConcat(tempStr, numStr);
}
else
PasStringConcat(tempStr, PSTR("-"));
2019-12-30 20:53:11 -05:00
2020-05-21 05:01:16 -04:00
surface->DrawString(Point::Create(5, 32), tempStr, blueColor, appFont);
2019-11-11 00:11:59 -05:00
#endif
}
//-------------------------------------------------------------- OpenCoordWindow
// Brings up the Coordinate window.
void OpenCoordWindow (void)
{
#ifndef COMPILEDEMO
Rect src, dest;
Point globalMouse;
short direction, dist;
2020-03-01 17:01:35 -05:00
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
2019-11-11 00:11:59 -05:00
if (coordWindow == nil)
{
2020-02-23 20:21:04 -05:00
const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar | PortabilityLayer::WindowStyleFlags::kMiniBar | PortabilityLayer::WindowStyleFlags::kCloseBox;
2019-11-11 00:11:59 -05:00
QSetRect(&coordWindowRect, 0, 0, 50, 38);
2020-03-01 17:01:35 -05:00
{
PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(coordWindowRect, windowStyle, true, 0, 0, PSTR("Tools"));
coordWindow = wm->CreateWindow(wdef);
}
2019-11-11 00:11:59 -05:00
if (coordWindow == nil)
RedAlert(kErrNoMemory);
// if (OptionKeyDown())
// {
// isCoordH = qd.screenBits.bounds.right - 55;
// isCoordV = 204;
// }
MoveWindow(coordWindow, isCoordH, isCoordV, true);
2020-01-05 02:33:03 -05:00
2019-11-11 00:11:59 -05:00
GetWindowRect(coordWindow, &dest);
2020-03-01 17:01:35 -05:00
wm->PutWindowBehind(coordWindow, wm->GetPutInFrontSentinel());
2020-01-05 02:33:03 -05:00
PortabilityLayer::WindowManager::GetInstance()->ShowWindow(coordWindow);
2019-11-11 00:11:59 -05:00
// FlagWindowFloating(coordWindow); TEMP - use flaoting windows
coordH = -1;
coordV = -1;
coordD = -1;
2019-12-30 20:53:11 -05:00
2019-11-11 00:11:59 -05:00
if (objActive != kNoObjectSelected)
{
if (ObjectHasHandle(&direction, &dist))
coordD = dist;
SetCoordinateHVD(theMarquee.bounds.left, theMarquee.bounds.top, coordD);
}
}
UpdateCoordinateCheckmark(true);
#endif
}
//-------------------------------------------------------------- CloseCoordWindow
// Closes and disposes of the Coordinate window.
void CloseCoordWindow (void)
{
CloseThisWindow(&coordWindow);
UpdateCoordinateCheckmark(false);
}
//-------------------------------------------------------------- ToggleCoordinateWindow
// Toggles the Coordinate windows state between open and closed.
void ToggleCoordinateWindow (void)
{
#ifndef COMPILEDEMO
if (coordWindow == nil)
{
OpenCoordWindow();
isCoordOpen = true;
}
else
{
CloseCoordWindow();
isCoordOpen = false;
}
#endif
}