mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-13 19:49:36 +00:00
Major draw code refactor
This commit is contained in:
149
PortabilityLayer/DialogManager.cpp
Normal file
149
PortabilityLayer/DialogManager.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
#include "DialogManager.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "PLDialogs.h"
|
||||
#include "PLBigEndian.h"
|
||||
#include "PLPasStr.h"
|
||||
#include "ResTypeID.h"
|
||||
#include "SharedTypes.h"
|
||||
#include "WindowDef.h"
|
||||
#include "WindowManager.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class DialogImpl final : public Dialog
|
||||
{
|
||||
public:
|
||||
void Destroy() override;
|
||||
Window *GetWindow() const override;
|
||||
|
||||
static DialogImpl *Create(Window *window);
|
||||
|
||||
private:
|
||||
explicit DialogImpl(Window *window);
|
||||
~DialogImpl();
|
||||
|
||||
Window *m_window;
|
||||
};
|
||||
|
||||
void DialogImpl::Destroy()
|
||||
{
|
||||
PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(m_window);
|
||||
|
||||
this->~DialogImpl();
|
||||
free(this);
|
||||
}
|
||||
|
||||
Window *DialogImpl::GetWindow() const
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
DialogImpl *DialogImpl::Create(Window *window)
|
||||
{
|
||||
void *storage = malloc(sizeof(DialogImpl));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
return new (storage) DialogImpl(window);
|
||||
}
|
||||
|
||||
DialogImpl::DialogImpl(Window *window)
|
||||
: m_window(window)
|
||||
{
|
||||
}
|
||||
|
||||
DialogImpl::~DialogImpl()
|
||||
{
|
||||
}
|
||||
|
||||
// DLOG resource format:
|
||||
// DialogResourceDataHeader
|
||||
// Variable-length PStr: Title
|
||||
// Optional: Positioning (2 byte mask)
|
||||
|
||||
struct DialogResourceDataHeader
|
||||
{
|
||||
BERect m_rect;
|
||||
BEInt16_t m_style;
|
||||
uint8_t m_visible;
|
||||
uint8_t m_unusedA;
|
||||
uint8_t m_hasCloseBox;
|
||||
uint8_t m_unusedB;
|
||||
BEUInt32_t m_referenceConstant;
|
||||
BEInt16_t m_itemsResID;
|
||||
};
|
||||
|
||||
class DialogManagerImpl final : public DialogManager
|
||||
{
|
||||
public:
|
||||
Dialog *LoadDialog(int16_t resID, Window *behindWindow) override;
|
||||
|
||||
static DialogManagerImpl *GetInstance();
|
||||
|
||||
private:
|
||||
static DialogManagerImpl ms_instance;
|
||||
};
|
||||
|
||||
Dialog *DialogManagerImpl::LoadDialog(int16_t resID, Window *behindWindow)
|
||||
{
|
||||
ResourceManager *rm = ResourceManager::GetInstance();
|
||||
|
||||
THandle<uint8_t> dlogH = rm->GetResource('DLOG', resID).StaticCast<uint8_t>();
|
||||
const uint8_t *dlogData = *dlogH;
|
||||
const uint8_t *dlogDataEnd = dlogData + dlogH.MMBlock()->m_size;
|
||||
|
||||
DialogResourceDataHeader header;
|
||||
memcpy(&header, dlogData, sizeof(header));
|
||||
|
||||
const uint8_t *titlePStr = dlogData + sizeof(header);
|
||||
const uint8_t *positioningData = titlePStr + 1 + titlePStr[0]; // May be OOB
|
||||
|
||||
BEUInt16_t positionSpec(0);
|
||||
if (positioningData != dlogDataEnd)
|
||||
memcpy(&positionSpec, positioningData, 2);
|
||||
|
||||
const Rect rect = header.m_rect.ToRect();
|
||||
const int16_t style = header.m_style;
|
||||
|
||||
dlogH.Dispose();
|
||||
|
||||
if (!rect.IsValid())
|
||||
return nullptr;
|
||||
|
||||
WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
|
||||
|
||||
WindowDef wdef = WindowDef::Create(rect, 0, header.m_visible != 0, header.m_hasCloseBox != 0, header.m_referenceConstant, positionSpec, PLPasStr(titlePStr));
|
||||
Window *window = wm->CreateWindow(wdef);
|
||||
if (!window)
|
||||
return nullptr;
|
||||
|
||||
wm->PutWindowBehind(window, behindWindow);
|
||||
|
||||
THandle<uint8_t> dtemplateH = rm->GetResource('DITL', header.m_itemsResID).StaticCast<uint8_t>();
|
||||
|
||||
Dialog *dialog = DialogImpl::Create(window);
|
||||
|
||||
if (!dialog)
|
||||
{
|
||||
wm->DestroyWindow(window);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
DialogManagerImpl *DialogManagerImpl::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
}
|
||||
|
||||
DialogManagerImpl DialogManagerImpl::ms_instance;
|
||||
|
||||
DialogManager *DialogManager::GetInstance()
|
||||
{
|
||||
return DialogManagerImpl::GetInstance();
|
||||
}
|
||||
}
|
||||
17
PortabilityLayer/DialogManager.h
Normal file
17
PortabilityLayer/DialogManager.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct Dialog;
|
||||
struct Window;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class DialogManager
|
||||
{
|
||||
public:
|
||||
virtual Dialog *LoadDialog(int16_t resID, Window *behindWindow) = 0;
|
||||
|
||||
static DialogManager *GetInstance();
|
||||
};
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace PortabilityLayer
|
||||
void Dismiss();
|
||||
|
||||
Menu **GetSelectedMenu() const;
|
||||
CGraf *GetRenderedMenu() const;
|
||||
DrawSurface *GetRenderedMenu() const;
|
||||
const unsigned int *GetSelectedItem() const;
|
||||
|
||||
void SelectItem(size_t item);
|
||||
@@ -156,7 +156,7 @@ namespace PortabilityLayer
|
||||
void RenderMenu(Menu *menu);
|
||||
|
||||
Menu **m_currentMenu;
|
||||
CGraf *m_menuGraf;
|
||||
DrawSurface *m_menuGraf;
|
||||
unsigned int m_itemIndex;
|
||||
bool m_haveItem;
|
||||
};
|
||||
@@ -184,7 +184,7 @@ namespace PortabilityLayer
|
||||
|
||||
static const int kMenuFontFlags = PortabilityLayer::FontFamilyFlag_Bold;
|
||||
|
||||
CGraf *m_menuBarGraf;
|
||||
DrawSurface *m_menuBarGraf;
|
||||
|
||||
Menu **m_firstMenu;
|
||||
Menu **m_lastMenu;
|
||||
@@ -555,7 +555,7 @@ namespace PortabilityLayer
|
||||
return;
|
||||
}
|
||||
|
||||
CGraf *graf = m_menuBarGraf;
|
||||
DrawSurface *graf = m_menuBarGraf;
|
||||
|
||||
assert(graf);
|
||||
|
||||
@@ -567,27 +567,26 @@ namespace PortabilityLayer
|
||||
|
||||
RefreshMenuBarLayout();
|
||||
|
||||
CGraf *oldGraf = GetGraphicsPort();
|
||||
DrawSurface *oldGraf = GetGraphicsPort();
|
||||
|
||||
SetGraphicsPort(m_menuBarGraf);
|
||||
|
||||
PortabilityLayer::QDState *qdState = qdManager->GetState();
|
||||
|
||||
qdState->SetForeColor(gs_barMidColor);
|
||||
PaintRect(&menuRect);
|
||||
|
||||
qdState->SetForeColor(gs_barBrightColor);
|
||||
graf->SetForeColor(gs_barMidColor);
|
||||
graf->FillRect(menuRect);
|
||||
graf->SetForeColor(gs_barBrightColor);
|
||||
|
||||
// Top stripe
|
||||
{
|
||||
const Rect rect = Rect::Create(0, 0, 1, static_cast<int16_t>(width) - 1);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
|
||||
// Left stripe
|
||||
{
|
||||
const Rect rect = Rect::Create(0, 0, kMenuBarHeight - 1, 1);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
|
||||
qdState->SetForeColor(gs_barDarkColor);
|
||||
@@ -595,13 +594,13 @@ namespace PortabilityLayer
|
||||
// Bottom stripe
|
||||
{
|
||||
const Rect rect = Rect::Create(kMenuBarHeight - 2, 1, kMenuBarHeight - 1, width);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
|
||||
// Right stripe
|
||||
{
|
||||
const Rect rect = Rect::Create(0, width - 1, kMenuBarHeight - 1, width);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
|
||||
qdState->SetForeColor(gs_barBottomEdgeColor);
|
||||
@@ -609,7 +608,7 @@ namespace PortabilityLayer
|
||||
// Bottom edge
|
||||
{
|
||||
const Rect rect = Rect::Create(kMenuBarHeight - 1, 0, kMenuBarHeight, width);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
|
||||
PixMapHandle pixMap = m_menuBarGraf->m_port.GetPixMap();
|
||||
@@ -634,27 +633,26 @@ namespace PortabilityLayer
|
||||
qdState->SetForeColor(gs_barHighlightBrightColor);
|
||||
{
|
||||
const Rect rect = Rect::Create(0, left, 1, right);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
|
||||
// Middle
|
||||
qdState->SetForeColor(gs_barHighlightMidColor);
|
||||
{
|
||||
const Rect rect = Rect::Create(1, left, kMenuBarHeight - 2, right);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
|
||||
qdState->SetForeColor(gs_barHighlightDarkColor);
|
||||
{
|
||||
const Rect rect = Rect::Create(kMenuBarHeight - 2, left, kMenuBarHeight - 1, right);
|
||||
PaintRect(&rect);
|
||||
m_menuBarGraf->FillRect(rect);
|
||||
}
|
||||
}
|
||||
|
||||
// Text items
|
||||
qdState->SetForeColor(gs_barNormalTextColor);
|
||||
TextFont(systemFont);
|
||||
TextSize(kMenuFontSize);
|
||||
m_menuBarGraf->SetSystemFont(kMenuFontSize, PortabilityLayer::FontFamilyFlag_Bold);
|
||||
|
||||
{
|
||||
Menu **menuHdl = m_firstMenu;
|
||||
@@ -675,9 +673,8 @@ namespace PortabilityLayer
|
||||
{
|
||||
if (menuHdl != selectedMenuHdl)
|
||||
{
|
||||
qdState->m_penPos.h = static_cast<int16_t>(xCoordinate);
|
||||
qdState->m_penPos.v = kMenuBarTextYOffset;
|
||||
DrawString(PLPasStr(static_cast<const uint8_t*>(menu->stringBlobHandle->m_contents)));
|
||||
const Point itemPos = Point::Create(static_cast<int16_t>(xCoordinate), kMenuBarTextYOffset);
|
||||
graf->DrawString(itemPos, PLPasStr(static_cast<const uint8_t*>(menu->stringBlobHandle->m_contents)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -695,9 +692,8 @@ namespace PortabilityLayer
|
||||
qdState->SetForeColor(gs_barHighlightTextColor);
|
||||
size_t xCoordinate = menu->cumulativeOffset + (menu->menuIndex * 2) * kMenuBarItemPadding + kMenuBarInitialPadding;
|
||||
|
||||
qdState->m_penPos.h = static_cast<int16_t>(xCoordinate);
|
||||
qdState->m_penPos.v = kMenuBarTextYOffset;
|
||||
DrawString(PLPasStr(static_cast<const uint8_t*>(menu->stringBlobHandle->m_contents)));
|
||||
const Point itemPos = Point::Create(static_cast<int16_t>(xCoordinate), kMenuBarTextYOffset);
|
||||
graf->DrawString(itemPos, PLPasStr(static_cast<const uint8_t*>(menu->stringBlobHandle->m_contents)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,7 +725,7 @@ namespace PortabilityLayer
|
||||
}
|
||||
}
|
||||
|
||||
if (CGraf *renderedMenu = m_menuSelectionState.GetRenderedMenu())
|
||||
if (DrawSurface *renderedMenu = m_menuSelectionState.GetRenderedMenu())
|
||||
{
|
||||
renderedMenu->PushToDDSurface(displayDriver);
|
||||
|
||||
@@ -968,7 +964,7 @@ namespace PortabilityLayer
|
||||
return m_currentMenu;
|
||||
}
|
||||
|
||||
CGraf *MenuManagerImpl::MenuSelectionState::GetRenderedMenu() const
|
||||
DrawSurface *MenuManagerImpl::MenuSelectionState::GetRenderedMenu() const
|
||||
{
|
||||
return m_menuGraf;
|
||||
}
|
||||
@@ -1019,7 +1015,9 @@ namespace PortabilityLayer
|
||||
return;
|
||||
}
|
||||
|
||||
CGrafPtr oldGraf = GetGraphicsPort();
|
||||
DrawSurface *surface = m_menuGraf;
|
||||
|
||||
DrawSurface *oldGraf = GetGraphicsPort();
|
||||
|
||||
SetGraphicsPort(m_menuGraf);
|
||||
|
||||
@@ -1029,15 +1027,14 @@ namespace PortabilityLayer
|
||||
|
||||
{
|
||||
const Rect rect = Rect::Create(0, 0, menu->layoutHeight, menu->layoutWidth);
|
||||
PaintRect(&rect);
|
||||
surface->FillRect(rect);
|
||||
}
|
||||
|
||||
TextFont(systemFont);
|
||||
TextSize(kMenuFontSize);
|
||||
m_menuGraf->SetSystemFont(kMenuFontSize, PortabilityLayer::FontFamilyFlag_Bold);
|
||||
|
||||
const uint8_t *strBlob = static_cast<const uint8_t*>(menu->stringBlobHandle->m_contents);
|
||||
|
||||
qdState->m_penPos.h = kMenuItemLeftPadding;
|
||||
Point itemPos = Point::Create(kMenuItemLeftPadding, 0);
|
||||
|
||||
qdState->SetForeColor(gs_barNormalTextColor);
|
||||
|
||||
@@ -1048,9 +1045,9 @@ namespace PortabilityLayer
|
||||
|
||||
const MenuItem &item = menu->menuItems[i];
|
||||
|
||||
qdState->m_penPos.v = item.layoutYOffset + kMenuItemTextYOffset;
|
||||
itemPos.v = item.layoutYOffset + kMenuItemTextYOffset;
|
||||
|
||||
DrawString(PLPasStr(strBlob + item.nameOffsetInStringBlob));
|
||||
surface->DrawString(itemPos, PLPasStr(strBlob + item.nameOffsetInStringBlob));
|
||||
}
|
||||
|
||||
if (m_haveItem)
|
||||
@@ -1058,15 +1055,15 @@ namespace PortabilityLayer
|
||||
const MenuItem &selectedItem = menu->menuItems[m_itemIndex];
|
||||
qdState->SetForeColor(gs_barHighlightMidColor);
|
||||
const Rect itemRect = Rect::Create(selectedItem.layoutYOffset, 0, selectedItem.layoutYOffset + selectedItem.layoutHeight, menu->layoutWidth);
|
||||
PaintRect(&itemRect);
|
||||
surface->FillRect(itemRect);
|
||||
|
||||
qdState->SetForeColor(gs_barHighlightTextColor);
|
||||
|
||||
const MenuItem &item = menu->menuItems[m_itemIndex];
|
||||
|
||||
qdState->m_penPos.v = item.layoutYOffset + kMenuItemTextYOffset;
|
||||
itemPos.v = item.layoutYOffset + kMenuItemTextYOffset;
|
||||
|
||||
DrawString(PLPasStr(strBlob + item.nameOffsetInStringBlob));
|
||||
surface->DrawString(itemPos, PLPasStr(strBlob + item.nameOffsetInStringBlob));
|
||||
}
|
||||
|
||||
m_menuGraf->m_port.SetDirty(QDPortDirtyFlag_Contents);
|
||||
|
||||
@@ -779,33 +779,15 @@ short StringWidth(const PLPasStr &str)
|
||||
const PortabilityLayer::QDState *qdState = PortabilityLayer::QDManager::GetInstance()->GetState();
|
||||
PortabilityLayer::FontManager *fontManager = PortabilityLayer::FontManager::GetInstance();
|
||||
|
||||
const int textSize = qdState->m_textSize;
|
||||
const int textFace = qdState->m_textFace;
|
||||
const int fontID = qdState->m_fontID;
|
||||
|
||||
int variationFlags = 0;
|
||||
if (textFace & bold)
|
||||
variationFlags |= PortabilityLayer::FontFamilyFlag_Bold;
|
||||
|
||||
PortabilityLayer::FontFamily *fontFamily = nullptr;
|
||||
|
||||
switch (fontID)
|
||||
{
|
||||
case applFont:
|
||||
fontFamily = fontManager->GetApplicationFont(textSize, variationFlags);
|
||||
break;
|
||||
case systemFont:
|
||||
fontFamily = fontManager->GetSystemFont(textSize, variationFlags);
|
||||
break;
|
||||
default:
|
||||
PL_NotYetImplemented();
|
||||
return 0;
|
||||
}
|
||||
PortabilityLayer::FontFamily *fontFamily = qdState->m_fontFamily;
|
||||
|
||||
if (!fontFamily)
|
||||
return 0;
|
||||
|
||||
PortabilityLayer::RenderedFont *rfont = fontManager->GetRenderedFontFromFamily(fontFamily, textSize, variationFlags);
|
||||
const int variationFlags = qdState->m_fontVariationFlags;
|
||||
const int fontSize = qdState->m_fontSize;
|
||||
|
||||
PortabilityLayer::RenderedFont *rfont = fontManager->GetRenderedFontFromFamily(fontFamily, fontSize, variationFlags);
|
||||
if (!rfont)
|
||||
return 0;
|
||||
|
||||
@@ -1035,3 +1017,8 @@ Window::Window()
|
||||
, m_wmY(0)
|
||||
{
|
||||
}
|
||||
|
||||
DrawSurface *Window::GetDrawSurface() const
|
||||
{
|
||||
return const_cast<DrawSurface*>(&m_graf);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ typedef unsigned char Str255[256];
|
||||
typedef unsigned char *StringPtr;
|
||||
|
||||
class PLPasStr;
|
||||
struct CGraf;
|
||||
struct DrawSurface;
|
||||
struct Menu;
|
||||
|
||||
typedef void *Ptr;
|
||||
@@ -100,7 +100,9 @@ struct Window
|
||||
{
|
||||
Window();
|
||||
|
||||
CGraf m_graf; // Must be the first item
|
||||
DrawSurface *GetDrawSurface() const;
|
||||
|
||||
DrawSurface m_graf; // Must be the first item
|
||||
|
||||
// The port is always at 0,0
|
||||
// These are the WM coordinates
|
||||
@@ -161,8 +163,6 @@ struct EventRecord
|
||||
int modifiers;
|
||||
};
|
||||
|
||||
typedef CGraf *CGrafPtr;
|
||||
typedef CGrafPtr GWorldPtr;
|
||||
typedef Window *WindowPtr;
|
||||
typedef Cursor *CursPtr;
|
||||
typedef CCursor *CCrsrPtr;
|
||||
@@ -182,7 +182,6 @@ struct KeyMap;
|
||||
enum RegionID
|
||||
{
|
||||
inMenuBar = 1,
|
||||
inSysWindow,
|
||||
inContent,
|
||||
inDrag,
|
||||
inGrow,
|
||||
|
||||
@@ -5,19 +5,13 @@ void DrawDialog(DialogPtr dialog)
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
WindowPtr GetDialogWindow(DialogPtr dialog)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DialogPtr GetNewDialog(int resID, void *unknown, WindowPtr behind)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CGrafPtr GetDialogPort(DialogPtr dialog)
|
||||
DrawSurface *GetDialogPort(DialogPtr dialog)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
return nullptr;
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
class PLPasStr;
|
||||
struct Control;
|
||||
|
||||
struct Dialog : public PortabilityLayer::QDPort
|
||||
struct Dialog
|
||||
{
|
||||
virtual void Destroy() = 0;
|
||||
virtual Window *GetWindow() const = 0;
|
||||
};
|
||||
|
||||
struct DialogTemplate
|
||||
@@ -30,9 +32,7 @@ typedef THandle<DialogTemplate> DialogTHndl;
|
||||
typedef Boolean(*ModalFilterUPP)(DialogPtr dial, EventRecord *event, short *item);
|
||||
|
||||
void DrawDialog(DialogPtr dialog);
|
||||
WindowPtr GetDialogWindow(DialogPtr dialog);
|
||||
DialogPtr GetNewDialog(int resID, void *unknown, WindowPtr behind);
|
||||
CGrafPtr GetDialogPort(DialogPtr dialog);
|
||||
DrawSurface *GetDialogPort(DialogPtr dialog);
|
||||
|
||||
void GetDialogItem(DialogPtr dialog, int index, short *itemType, THandle<Control> *itemHandle, Rect *itemRect);
|
||||
void GetDialogItemText(THandle<Control> handle, StringPtr str);
|
||||
|
||||
@@ -109,7 +109,7 @@ void DisposeMovie(Movie movie)
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void SetMovieGWorld(Movie movie, CGrafPtr graf, void *unknown)
|
||||
void SetMovieGWorld(Movie movie, DrawSurface *graf, void *unknown)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ void SetMovieMasterTimeBase(Movie movie, TimeBase timeBase, void *unused);
|
||||
void GetMovieBox(Movie movie, Rect *rect);
|
||||
void StopMovie(Movie movie);
|
||||
void DisposeMovie(Movie movie);
|
||||
void SetMovieGWorld(Movie movie, CGrafPtr graf, void *unknown);
|
||||
void SetMovieGWorld(Movie movie, DrawSurface *graf, void *unknown);
|
||||
void SetMovieActive(Movie movie, Boolean active);
|
||||
void StartMovie(Movie movie);
|
||||
void MoviesTask(Movie movie, int unknown);
|
||||
|
||||
@@ -18,231 +18,17 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class PixMapBlitEmitter final : public QDPictEmitContext
|
||||
{
|
||||
public:
|
||||
PixMapBlitEmitter(const Vec2i &drawOrigin, PixMapImpl *pixMap);
|
||||
~PixMapBlitEmitter();
|
||||
|
||||
bool SpecifyFrame(const Rect &rect) override;
|
||||
Rect ConstrainRegion(const Rect &rect) const override;
|
||||
void Start(QDPictBlitSourceType sourceType, const QDPictEmitScanlineParameters ¶ms) override;
|
||||
void BlitScanlineAndAdvance(const void *) override;
|
||||
bool AllocTempBuffers(uint8_t *&buffer1, size_t buffer1Size, uint8_t *&buffer2, size_t buffer2Size) override;
|
||||
|
||||
private:
|
||||
PixMapImpl *m_pixMap;
|
||||
Vec2i m_drawOrigin;
|
||||
uint8_t *m_tempBuffer;
|
||||
Rect m_specFrame;
|
||||
|
||||
QDPictBlitSourceType m_blitType;
|
||||
QDPictEmitScanlineParameters m_params;
|
||||
|
||||
size_t m_constraintRegionWidth;
|
||||
size_t m_constraintRegionStartIndex;
|
||||
size_t m_constraintRegionEndIndex;
|
||||
size_t m_outputIndexStart;
|
||||
|
||||
uint8_t m_paletteMap[256];
|
||||
bool m_sourceAndDestPalettesAreSame;
|
||||
};
|
||||
|
||||
PixMapBlitEmitter::PixMapBlitEmitter(const Vec2i &drawOrigin, PixMapImpl *pixMap)
|
||||
: m_pixMap(pixMap)
|
||||
, m_drawOrigin(drawOrigin)
|
||||
, m_tempBuffer(nullptr)
|
||||
, m_sourceAndDestPalettesAreSame(false)
|
||||
{
|
||||
}
|
||||
|
||||
PixMapBlitEmitter::~PixMapBlitEmitter()
|
||||
{
|
||||
if (m_tempBuffer)
|
||||
PortabilityLayer::MemoryManager::GetInstance()->Release(m_tempBuffer);
|
||||
}
|
||||
|
||||
bool PixMapBlitEmitter::SpecifyFrame(const Rect &rect)
|
||||
{
|
||||
m_specFrame = rect;
|
||||
return true;
|
||||
}
|
||||
|
||||
Rect PixMapBlitEmitter::ConstrainRegion(const Rect &rect) const
|
||||
{
|
||||
const Rect pixMapRect = m_pixMap->m_rect;
|
||||
|
||||
const Rect2i rectInDrawSpace = Rect2i(rect) + m_drawOrigin;
|
||||
|
||||
const Rect2i constrainedRectInDrawSpace = rectInDrawSpace.Intersect(Rect2i(pixMapRect));
|
||||
|
||||
// If this got completely culled away, return an empty rect, but avoid int truncation
|
||||
if (!constrainedRectInDrawSpace.IsValid())
|
||||
return Rect::Create(rect.top, rect.left, rect.top, rect.left);
|
||||
|
||||
// Otherwise, it should still be valid in the picture space
|
||||
const Rect2i constrainedRectInPictSpace = constrainedRectInDrawSpace - m_drawOrigin;
|
||||
return constrainedRectInPictSpace.ToShortRect();
|
||||
}
|
||||
|
||||
void PixMapBlitEmitter::Start(QDPictBlitSourceType sourceType, const QDPictEmitScanlineParameters ¶ms)
|
||||
{
|
||||
// FIXME: Detect different system palette (if we ever do that)
|
||||
if (QDPictBlitSourceType_IsIndexed(sourceType))
|
||||
{
|
||||
if (params.m_numColors == 256 && !memcmp(params.m_colors, StandardPalette::GetInstance()->GetColors(), sizeof(RGBAColor) * 256))
|
||||
m_sourceAndDestPalettesAreSame = true;
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
m_blitType = sourceType;
|
||||
m_params = params;
|
||||
|
||||
m_constraintRegionWidth = params.m_constrainedRegionRight - params.m_constrainedRegionLeft;
|
||||
m_constraintRegionStartIndex = params.m_constrainedRegionLeft - params.m_scanlineOriginX;
|
||||
m_constraintRegionEndIndex = params.m_constrainedRegionRight - params.m_scanlineOriginX;
|
||||
|
||||
const size_t firstCol = params.m_constrainedRegionLeft + m_drawOrigin.m_x - m_pixMap->m_rect.left;
|
||||
const size_t firstRow = params.m_firstY + m_drawOrigin.m_y - m_pixMap->m_rect.top;
|
||||
|
||||
m_outputIndexStart = firstRow * m_pixMap->GetPitch() + firstCol;
|
||||
}
|
||||
|
||||
void PixMapBlitEmitter::BlitScanlineAndAdvance(const void *data)
|
||||
{
|
||||
const int32_t crRight = m_params.m_constrainedRegionRight;
|
||||
const int32_t crLeft = m_params.m_constrainedRegionLeft;
|
||||
const size_t constraintRegionStartIndex = m_constraintRegionStartIndex;
|
||||
const uint8_t *dataBytes = static_cast<const uint8_t*>(data);
|
||||
const size_t outputIndexStart = m_outputIndexStart;
|
||||
const size_t planarSeparation = m_params.m_planarSeparation;
|
||||
const size_t constraintRegionWidth = m_constraintRegionWidth;
|
||||
|
||||
const uint8_t *paletteMapping = nullptr;
|
||||
|
||||
const uint8_t staticMapping1Bit[] = { 0, 255 };
|
||||
|
||||
void *imageData = m_pixMap->GetPixelData();
|
||||
|
||||
if (m_pixMap->GetPixelFormat() == GpPixelFormats::k8BitStandard || m_pixMap->GetPixelFormat() == GpPixelFormats::kBW1)
|
||||
{
|
||||
switch (m_blitType)
|
||||
{
|
||||
case QDPictBlitSourceType_Indexed1Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 7 - (itemIndex & 7);
|
||||
const int colorIndex = (dataBytes[itemIndex / 8] >> bitShift) & 0x1;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_Indexed2Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 6 - (2 * (itemIndex & 1));
|
||||
const int colorIndex = (dataBytes[itemIndex / 4] >> bitShift) & 0x3;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_Indexed4Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 4 - (4 * (itemIndex & 1));
|
||||
const int colorIndex = (dataBytes[itemIndex / 2] >> bitShift) & 0xf;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_Indexed8Bit:
|
||||
if (m_sourceAndDestPalettesAreSame)
|
||||
memcpy(static_cast<uint8_t*>(imageData) + outputIndexStart, dataBytes + constraintRegionStartIndex, m_constraintRegionWidth);
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
const uint8_t colorIndex = dataBytes[itemIndex];
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_1Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 7 - (itemIndex & 7);
|
||||
const int colorIndex = (dataBytes[itemIndex / 8] >> bitShift) & 0x1;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = staticMapping1Bit[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_RGB15:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const uint16_t item = *reinterpret_cast<const uint16_t*>(dataBytes + itemIndex * 2);
|
||||
uint8_t &outputItem = static_cast<uint8_t*>(imageData)[i + outputIndexStart];
|
||||
|
||||
outputItem = StandardPalette::GetInstance()->MapColorLUT((item >> 1) & 0xf, (item >> 6) & 0xf, (item >> 11) & 0x1f);
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_RGB24_Multiplane:
|
||||
for (size_t i = 0; i < m_constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
uint8_t &outputItem = static_cast<uint8_t*>(imageData)[i + outputIndexStart];
|
||||
|
||||
const uint8_t r = dataBytes[itemIndex];
|
||||
const uint8_t g = dataBytes[itemIndex + planarSeparation];
|
||||
const uint8_t b = dataBytes[itemIndex + planarSeparation * 2];
|
||||
|
||||
outputItem = StandardPalette::GetInstance()->MapColorLUT(r, g, b);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
m_outputIndexStart += m_pixMap->GetPitch();
|
||||
}
|
||||
|
||||
bool PixMapBlitEmitter::AllocTempBuffers(uint8_t *&buffer1, size_t buffer1Size, uint8_t *&buffer2, size_t buffer2Size)
|
||||
{
|
||||
m_tempBuffer = static_cast<uint8_t*>(PortabilityLayer::MemoryManager::GetInstance()->Alloc(buffer1Size + buffer2Size));
|
||||
if (!m_tempBuffer)
|
||||
return false;
|
||||
|
||||
buffer1 = m_tempBuffer;
|
||||
buffer2 = m_tempBuffer + buffer1Size;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PLError_t NewGWorld(GWorldPtr *gworld, GpPixelFormat_t pixelFormat, const Rect *bounds, CTabHandle colorTable)
|
||||
PLError_t NewGWorld(DrawSurface **gworld, GpPixelFormat_t pixelFormat, const Rect *bounds, CTabHandle colorTable)
|
||||
{
|
||||
return PortabilityLayer::QDManager::GetInstance()->NewGWorld(gworld, pixelFormat, *bounds, colorTable);
|
||||
}
|
||||
|
||||
void DisposeGWorld(GWorldPtr gworld)
|
||||
void DisposeGWorld(DrawSurface *gworld)
|
||||
{
|
||||
return PortabilityLayer::QDManager::GetInstance()->DisposeGWorld(gworld);
|
||||
}
|
||||
|
||||
PixMapHandle GetGWorldPixMap(GWorldPtr gworld)
|
||||
PixMapHandle GetGWorldPixMap(DrawSurface *gworld)
|
||||
{
|
||||
if (!gworld)
|
||||
return nullptr;
|
||||
@@ -263,68 +49,17 @@ void OffsetRect(Rect *rect, int right, int down)
|
||||
rect->bottom += down;
|
||||
}
|
||||
|
||||
void DrawPicture(PicHandle pict, Rect *bounds)
|
||||
{
|
||||
if (!pict)
|
||||
return;
|
||||
|
||||
PicPtr picPtr = *pict;
|
||||
|
||||
if (!picPtr)
|
||||
return;
|
||||
|
||||
const Rect picRect = picPtr->picFrame.ToRect();
|
||||
|
||||
if (bounds->right - bounds->left != picRect.right - picRect.left || bounds->bottom - bounds->top != picRect.bottom - picRect.top)
|
||||
{
|
||||
// Scaled pict draw (not supported)
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
|
||||
PortabilityLayer::QDManager *qdManager = PortabilityLayer::QDManager::GetInstance();
|
||||
PortabilityLayer::QDPort *port = qdManager->GetPort();
|
||||
|
||||
if (!port)
|
||||
return;
|
||||
|
||||
PortabilityLayer::PixMapImpl *pixMap = static_cast<PortabilityLayer::PixMapImpl*>(*port->GetPixMap());
|
||||
|
||||
long handleSize = pict.MMBlock()->m_size;
|
||||
PortabilityLayer::MemReaderStream stream(picPtr, handleSize);
|
||||
|
||||
// Adjust draw origin
|
||||
const PortabilityLayer::Vec2i drawOrigin = PortabilityLayer::Vec2i(bounds->left - picPtr->picFrame.left, bounds->top - picPtr->picFrame.top);
|
||||
|
||||
switch (pixMap->GetPixelFormat())
|
||||
{
|
||||
case GpPixelFormats::kBW1:
|
||||
case GpPixelFormats::k8BitStandard:
|
||||
{
|
||||
PortabilityLayer::PixMapBlitEmitter blitEmitter(drawOrigin, pixMap);
|
||||
PortabilityLayer::QDPictDecoder decoder;
|
||||
|
||||
decoder.DecodePict(&stream, &blitEmitter);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// TODO: Implement higher-resolution pixel blitters
|
||||
assert(false);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
CGraf *GetGraphicsPort()
|
||||
DrawSurface *GetGraphicsPort()
|
||||
{
|
||||
PortabilityLayer::QDPort *port = PortabilityLayer::QDManager::GetInstance()->GetPort();
|
||||
|
||||
CGraf *grafPtr = reinterpret_cast<CGraf *>(port);
|
||||
DrawSurface *grafPtr = reinterpret_cast<DrawSurface *>(port);
|
||||
assert(&grafPtr->m_port == port);
|
||||
|
||||
return grafPtr;
|
||||
}
|
||||
|
||||
void SetGraphicsPort(CGrafPtr gw)
|
||||
void SetGraphicsPort(DrawSurface *gw)
|
||||
{
|
||||
PortabilityLayer::QDManager::GetInstance()->SetPort(&gw->m_port);
|
||||
}
|
||||
|
||||
@@ -25,19 +25,17 @@ enum QDFlags
|
||||
useTempMem = 1,
|
||||
};
|
||||
|
||||
PLError_t NewGWorld(GWorldPtr *gworld, GpPixelFormat_t pixelFormat, const Rect *bounds, CTabHandle colorTable);
|
||||
void DisposeGWorld(GWorldPtr gworld);
|
||||
PLError_t NewGWorld(DrawSurface **gworld, GpPixelFormat_t pixelFormat, const Rect *bounds, CTabHandle colorTable);
|
||||
void DisposeGWorld(DrawSurface *gworld);
|
||||
|
||||
PixMapHandle GetGWorldPixMap(GWorldPtr gworld);
|
||||
PixMapHandle GetGWorldPixMap(DrawSurface *gworld);
|
||||
|
||||
PicHandle GetPicture(short resID);
|
||||
|
||||
void OffsetRect(Rect *rect, int right, int down);
|
||||
|
||||
void DrawPicture(PicHandle pict, Rect *bounds);
|
||||
|
||||
CGrafPtr GetGraphicsPort();
|
||||
void SetGraphicsPort(CGrafPtr gw);
|
||||
DrawSurface *GetGraphicsPort();
|
||||
void SetGraphicsPort(DrawSurface *gw);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "LinePlotter.h"
|
||||
#include "MMHandleBlock.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "MemReaderStream.h"
|
||||
#include "HostFontHandler.h"
|
||||
#include "PLPasStr.h"
|
||||
#include "RenderedFont.h"
|
||||
@@ -18,9 +19,13 @@
|
||||
#include "ScanlineMask.h"
|
||||
#include "ScanlineMaskConverter.h"
|
||||
#include "ScanlineMaskIterator.h"
|
||||
#include "QDGraf.h"
|
||||
#include "QDStandardPalette.h"
|
||||
#include "QDPictEmitContext.h"
|
||||
#include "QDPictEmitScanlineParameters.h"
|
||||
#include "WindowManager.h"
|
||||
#include "QDGraf.h"
|
||||
#include "QDPictDecoder.h"
|
||||
#include "QDPixMap.h"
|
||||
#include "Vec2i.h"
|
||||
|
||||
@@ -28,14 +33,219 @@
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
enum PaintColorResolution
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
PaintColorResolution_Fore,
|
||||
PaintColorResolution_Back,
|
||||
PaintColorResolution_Pen,
|
||||
};
|
||||
class PixMapBlitEmitter final : public QDPictEmitContext
|
||||
{
|
||||
public:
|
||||
PixMapBlitEmitter(const Vec2i &drawOrigin, PixMapImpl *pixMap);
|
||||
~PixMapBlitEmitter();
|
||||
|
||||
static void PaintRectWithPCR(const Rect &rect, PaintColorResolution pcr);
|
||||
bool SpecifyFrame(const Rect &rect) override;
|
||||
Rect ConstrainRegion(const Rect &rect) const override;
|
||||
void Start(QDPictBlitSourceType sourceType, const QDPictEmitScanlineParameters ¶ms) override;
|
||||
void BlitScanlineAndAdvance(const void *) override;
|
||||
bool AllocTempBuffers(uint8_t *&buffer1, size_t buffer1Size, uint8_t *&buffer2, size_t buffer2Size) override;
|
||||
|
||||
private:
|
||||
PixMapImpl *m_pixMap;
|
||||
Vec2i m_drawOrigin;
|
||||
uint8_t *m_tempBuffer;
|
||||
Rect m_specFrame;
|
||||
|
||||
QDPictBlitSourceType m_blitType;
|
||||
QDPictEmitScanlineParameters m_params;
|
||||
|
||||
size_t m_constraintRegionWidth;
|
||||
size_t m_constraintRegionStartIndex;
|
||||
size_t m_constraintRegionEndIndex;
|
||||
size_t m_outputIndexStart;
|
||||
|
||||
uint8_t m_paletteMap[256];
|
||||
bool m_sourceAndDestPalettesAreSame;
|
||||
};
|
||||
|
||||
PixMapBlitEmitter::PixMapBlitEmitter(const Vec2i &drawOrigin, PixMapImpl *pixMap)
|
||||
: m_pixMap(pixMap)
|
||||
, m_drawOrigin(drawOrigin)
|
||||
, m_tempBuffer(nullptr)
|
||||
, m_sourceAndDestPalettesAreSame(false)
|
||||
{
|
||||
}
|
||||
|
||||
PixMapBlitEmitter::~PixMapBlitEmitter()
|
||||
{
|
||||
if (m_tempBuffer)
|
||||
PortabilityLayer::MemoryManager::GetInstance()->Release(m_tempBuffer);
|
||||
}
|
||||
|
||||
bool PixMapBlitEmitter::SpecifyFrame(const Rect &rect)
|
||||
{
|
||||
m_specFrame = rect;
|
||||
return true;
|
||||
}
|
||||
|
||||
Rect PixMapBlitEmitter::ConstrainRegion(const Rect &rect) const
|
||||
{
|
||||
const Rect pixMapRect = m_pixMap->m_rect;
|
||||
|
||||
const Rect2i rectInDrawSpace = Rect2i(rect) + m_drawOrigin;
|
||||
|
||||
const Rect2i constrainedRectInDrawSpace = rectInDrawSpace.Intersect(Rect2i(pixMapRect));
|
||||
|
||||
// If this got completely culled away, return an empty rect, but avoid int truncation
|
||||
if (!constrainedRectInDrawSpace.IsValid())
|
||||
return Rect::Create(rect.top, rect.left, rect.top, rect.left);
|
||||
|
||||
// Otherwise, it should still be valid in the picture space
|
||||
const Rect2i constrainedRectInPictSpace = constrainedRectInDrawSpace - m_drawOrigin;
|
||||
return constrainedRectInPictSpace.ToShortRect();
|
||||
}
|
||||
|
||||
void PixMapBlitEmitter::Start(QDPictBlitSourceType sourceType, const QDPictEmitScanlineParameters ¶ms)
|
||||
{
|
||||
// FIXME: Detect different system palette (if we ever do that)
|
||||
if (QDPictBlitSourceType_IsIndexed(sourceType))
|
||||
{
|
||||
if (params.m_numColors == 256 && !memcmp(params.m_colors, StandardPalette::GetInstance()->GetColors(), sizeof(RGBAColor) * 256))
|
||||
m_sourceAndDestPalettesAreSame = true;
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
m_blitType = sourceType;
|
||||
m_params = params;
|
||||
|
||||
m_constraintRegionWidth = params.m_constrainedRegionRight - params.m_constrainedRegionLeft;
|
||||
m_constraintRegionStartIndex = params.m_constrainedRegionLeft - params.m_scanlineOriginX;
|
||||
m_constraintRegionEndIndex = params.m_constrainedRegionRight - params.m_scanlineOriginX;
|
||||
|
||||
const size_t firstCol = params.m_constrainedRegionLeft + m_drawOrigin.m_x - m_pixMap->m_rect.left;
|
||||
const size_t firstRow = params.m_firstY + m_drawOrigin.m_y - m_pixMap->m_rect.top;
|
||||
|
||||
m_outputIndexStart = firstRow * m_pixMap->GetPitch() + firstCol;
|
||||
}
|
||||
|
||||
void PixMapBlitEmitter::BlitScanlineAndAdvance(const void *data)
|
||||
{
|
||||
const int32_t crRight = m_params.m_constrainedRegionRight;
|
||||
const int32_t crLeft = m_params.m_constrainedRegionLeft;
|
||||
const size_t constraintRegionStartIndex = m_constraintRegionStartIndex;
|
||||
const uint8_t *dataBytes = static_cast<const uint8_t*>(data);
|
||||
const size_t outputIndexStart = m_outputIndexStart;
|
||||
const size_t planarSeparation = m_params.m_planarSeparation;
|
||||
const size_t constraintRegionWidth = m_constraintRegionWidth;
|
||||
|
||||
const uint8_t *paletteMapping = nullptr;
|
||||
|
||||
const uint8_t staticMapping1Bit[] = { 0, 255 };
|
||||
|
||||
void *imageData = m_pixMap->GetPixelData();
|
||||
|
||||
if (m_pixMap->GetPixelFormat() == GpPixelFormats::k8BitStandard || m_pixMap->GetPixelFormat() == GpPixelFormats::kBW1)
|
||||
{
|
||||
switch (m_blitType)
|
||||
{
|
||||
case QDPictBlitSourceType_Indexed1Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 7 - (itemIndex & 7);
|
||||
const int colorIndex = (dataBytes[itemIndex / 8] >> bitShift) & 0x1;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_Indexed2Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 6 - (2 * (itemIndex & 1));
|
||||
const int colorIndex = (dataBytes[itemIndex / 4] >> bitShift) & 0x3;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_Indexed4Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 4 - (4 * (itemIndex & 1));
|
||||
const int colorIndex = (dataBytes[itemIndex / 2] >> bitShift) & 0xf;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_Indexed8Bit:
|
||||
if (m_sourceAndDestPalettesAreSame)
|
||||
memcpy(static_cast<uint8_t*>(imageData) + outputIndexStart, dataBytes + constraintRegionStartIndex, m_constraintRegionWidth);
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
const uint8_t colorIndex = dataBytes[itemIndex];
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = paletteMapping[colorIndex];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_1Bit:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const int bitShift = 7 - (itemIndex & 7);
|
||||
const int colorIndex = (dataBytes[itemIndex / 8] >> bitShift) & 0x1;
|
||||
static_cast<uint8_t*>(imageData)[i + outputIndexStart] = staticMapping1Bit[colorIndex];
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_RGB15:
|
||||
for (size_t i = 0; i < constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
const uint16_t item = *reinterpret_cast<const uint16_t*>(dataBytes + itemIndex * 2);
|
||||
uint8_t &outputItem = static_cast<uint8_t*>(imageData)[i + outputIndexStart];
|
||||
|
||||
outputItem = StandardPalette::GetInstance()->MapColorLUT((item >> 1) & 0xf, (item >> 6) & 0xf, (item >> 11) & 0x1f);
|
||||
}
|
||||
break;
|
||||
case QDPictBlitSourceType_RGB24_Multiplane:
|
||||
for (size_t i = 0; i < m_constraintRegionWidth; i++)
|
||||
{
|
||||
const size_t itemIndex = i + constraintRegionStartIndex;
|
||||
|
||||
uint8_t &outputItem = static_cast<uint8_t*>(imageData)[i + outputIndexStart];
|
||||
|
||||
const uint8_t r = dataBytes[itemIndex];
|
||||
const uint8_t g = dataBytes[itemIndex + planarSeparation];
|
||||
const uint8_t b = dataBytes[itemIndex + planarSeparation * 2];
|
||||
|
||||
outputItem = StandardPalette::GetInstance()->MapColorLUT(r, g, b);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
m_outputIndexStart += m_pixMap->GetPitch();
|
||||
}
|
||||
|
||||
bool PixMapBlitEmitter::AllocTempBuffers(uint8_t *&buffer1, size_t buffer1Size, uint8_t *&buffer2, size_t buffer2Size)
|
||||
{
|
||||
m_tempBuffer = static_cast<uint8_t*>(PortabilityLayer::MemoryManager::GetInstance()->Alloc(buffer1Size + buffer2Size));
|
||||
if (!m_tempBuffer)
|
||||
return false;
|
||||
|
||||
buffer1 = m_tempBuffer;
|
||||
buffer2 = m_tempBuffer + buffer1Size;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void GetPort(GrafPtr *graf)
|
||||
{
|
||||
@@ -47,11 +257,6 @@ void SetPort(GrafPtr graf)
|
||||
PortabilityLayer::QDManager::GetInstance()->SetPort(graf);
|
||||
}
|
||||
|
||||
void BeginUpdate(WindowPtr graf)
|
||||
{
|
||||
(void)graf;
|
||||
}
|
||||
|
||||
void EndUpdate(WindowPtr graf)
|
||||
{
|
||||
graf->m_graf.m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
|
||||
@@ -105,21 +310,6 @@ void SetPortDialogPort(Dialog *dialog)
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void TextSize(int sz)
|
||||
{
|
||||
PortabilityLayer::QDManager::GetInstance()->GetState()->m_textSize = sz;
|
||||
}
|
||||
|
||||
void TextFace(int face)
|
||||
{
|
||||
PortabilityLayer::QDManager::GetInstance()->GetState()->m_textFace = face;
|
||||
}
|
||||
|
||||
void TextFont(int fontID)
|
||||
{
|
||||
PortabilityLayer::QDManager::GetInstance()->GetState()->m_fontID = fontID;
|
||||
}
|
||||
|
||||
int TextWidth(const PLPasStr &str, int firstChar1Based, int length)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
@@ -134,7 +324,7 @@ void MoveTo(int x, int y)
|
||||
penPos.v = y;
|
||||
}
|
||||
|
||||
static void PlotLine(PortabilityLayer::QDState *qdState, PortabilityLayer::QDPort *qdPort, const PortabilityLayer::Vec2i &pointA, const PortabilityLayer::Vec2i &pointB)
|
||||
static void PlotLine(PortabilityLayer::QDState *qdState, DrawSurface *surface, const PortabilityLayer::Vec2i &pointA, const PortabilityLayer::Vec2i &pointB)
|
||||
{
|
||||
const Rect lineRect = Rect::Create(
|
||||
std::min(pointA.m_y, pointB.m_y),
|
||||
@@ -145,13 +335,15 @@ static void PlotLine(PortabilityLayer::QDState *qdState, PortabilityLayer::QDPor
|
||||
// If the points are a straight line, paint as a rect
|
||||
if (pointA.m_y == pointB.m_y || pointA.m_x == pointB.m_x)
|
||||
{
|
||||
PaintRectWithPCR(lineRect, PaintColorResolution_Fore);
|
||||
surface->FillRect(lineRect);
|
||||
return;
|
||||
}
|
||||
|
||||
GpPixelFormat_t pixelFormat = qdPort->GetPixelFormat();
|
||||
PortabilityLayer::QDPort *port = &surface->m_port;
|
||||
|
||||
Rect constrainedRect = qdPort->GetRect();
|
||||
GpPixelFormat_t pixelFormat = surface->m_port.GetPixelFormat();
|
||||
|
||||
Rect constrainedRect = port->GetRect();
|
||||
|
||||
constrainedRect = constrainedRect.Intersect(qdState->m_clipRect);
|
||||
constrainedRect = constrainedRect.Intersect(lineRect);
|
||||
@@ -165,7 +357,7 @@ static void PlotLine(PortabilityLayer::QDState *qdState, PortabilityLayer::QDPor
|
||||
if (pointA.m_y > pointB.m_y)
|
||||
std::swap(upperPoint, lowerPoint);
|
||||
|
||||
PortabilityLayer::PixMapImpl *pixMap = static_cast<PortabilityLayer::PixMapImpl*>(*qdPort->GetPixMap());
|
||||
PortabilityLayer::PixMapImpl *pixMap = static_cast<PortabilityLayer::PixMapImpl*>(*port->GetPixMap());
|
||||
const size_t pitch = pixMap->GetPitch();
|
||||
uint8_t *pixData = static_cast<uint8_t*>(pixMap->GetPixelData());
|
||||
|
||||
@@ -249,14 +441,6 @@ static void PlotLine(PortabilityLayer::QDState *qdState, PortabilityLayer::QDPor
|
||||
}
|
||||
}
|
||||
|
||||
void LineTo(int x, int y)
|
||||
{
|
||||
PortabilityLayer::QDManager *qdManager = PortabilityLayer::QDManager::GetInstance();
|
||||
PortabilityLayer::QDState *qdState = qdManager->GetState();
|
||||
|
||||
PlotLine(qdState, qdManager->GetPort(), PortabilityLayer::Vec2i(qdState->m_penPos.h, qdState->m_penPos.v), PortabilityLayer::Vec2i(x, y));
|
||||
}
|
||||
|
||||
void SetOrigin(int x, int y)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
@@ -330,38 +514,7 @@ void BackColor(SystemColorID color)
|
||||
void GetForeColor(RGBColor *color)
|
||||
{
|
||||
const PortabilityLayer::RGBAColor foreColor = PortabilityLayer::QDManager::GetInstance()->GetState()->GetForeColor();
|
||||
color->red = foreColor.r * 0x0101;
|
||||
color->green = foreColor.g * 0x0101;
|
||||
color->blue = foreColor.b * 0x0101;
|
||||
}
|
||||
|
||||
void Index2Color(int index, RGBColor *color)
|
||||
{
|
||||
PortabilityLayer::QDPort *port = PortabilityLayer::QDManager::GetInstance()->GetPort();
|
||||
|
||||
GpPixelFormat_t pf = port->GetPixelFormat();
|
||||
if (pf == GpPixelFormats::k8BitCustom)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
else
|
||||
{
|
||||
const PortabilityLayer::RGBAColor color8 = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[index];
|
||||
color->red = color8.r * 0x0101;
|
||||
color->green = color8.g * 0x0101;
|
||||
color->blue = color8.b * 0x0101;
|
||||
}
|
||||
}
|
||||
|
||||
void RGBForeColor(const RGBColor *color)
|
||||
{
|
||||
PortabilityLayer::RGBAColor truncatedColor;
|
||||
truncatedColor.r = (color->red >> 8);
|
||||
truncatedColor.g = (color->green >> 8);
|
||||
truncatedColor.b = (color->blue >> 8);
|
||||
truncatedColor.a = 255;
|
||||
|
||||
PortabilityLayer::QDManager::GetInstance()->GetState()->SetForeColor(truncatedColor);
|
||||
*color = RGBColor(foreColor.r, foreColor.g, foreColor.b);
|
||||
}
|
||||
|
||||
static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const Rect &rect, Point &penPos, const PortabilityLayer::RenderedFont *rfont, unsigned int character)
|
||||
@@ -430,48 +583,21 @@ static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const
|
||||
}
|
||||
}
|
||||
|
||||
void DrawString(const PLPasStr &str)
|
||||
void DrawSurface::DrawString(const Point &point, const PLPasStr &str)
|
||||
{
|
||||
PortabilityLayer::QDManager *qdManager = PortabilityLayer::QDManager::GetInstance();
|
||||
PortabilityLayer::QDPort *port = &m_port;
|
||||
|
||||
PortabilityLayer::QDPort *port = qdManager->GetPort();
|
||||
|
||||
PortabilityLayer::QDState *qdState = qdManager->GetState();
|
||||
PortabilityLayer::QDState *qdState = m_port.GetState();
|
||||
|
||||
PortabilityLayer::FontManager *fontManager = PortabilityLayer::FontManager::GetInstance();
|
||||
|
||||
const int textSize = qdState->m_textSize;
|
||||
const int textFace = qdState->m_textFace;
|
||||
const int fontID = qdState->m_fontID;
|
||||
const int fontSize = qdState->m_fontSize;
|
||||
const int fontVariationFlags = qdState->m_fontVariationFlags;
|
||||
PortabilityLayer::FontFamily *fontFamily = qdState->m_fontFamily;
|
||||
|
||||
int variationFlags = 0;
|
||||
if (textFace & bold)
|
||||
variationFlags |= PortabilityLayer::FontFamilyFlag_Bold;
|
||||
PortabilityLayer::RenderedFont *rfont = fontManager->GetRenderedFontFromFamily(fontFamily, fontSize, fontVariationFlags);
|
||||
|
||||
const PortabilityLayer::FontFamily *fontFamily = nullptr;
|
||||
|
||||
switch (fontID)
|
||||
{
|
||||
case applFont:
|
||||
fontFamily = fontManager->GetApplicationFont(textSize, variationFlags);
|
||||
break;
|
||||
case systemFont:
|
||||
fontFamily = fontManager->GetSystemFont(textSize, variationFlags);
|
||||
break;
|
||||
default:
|
||||
PL_NotYetImplemented();
|
||||
return;
|
||||
}
|
||||
|
||||
const int realVariation = fontFamily->GetVariationForFlags(variationFlags);
|
||||
PortabilityLayer::HostFont *font = fontFamily->GetFontForVariation(realVariation);
|
||||
|
||||
if (!font)
|
||||
return;
|
||||
|
||||
PortabilityLayer::RenderedFont *rfont = fontManager->GetRenderedFont(font, textSize, fontFamily->GetHacksForVariation(realVariation));
|
||||
|
||||
Point penPos = qdState->m_penPos;
|
||||
Point penPos = point;
|
||||
const size_t len = str.Length();
|
||||
const uint8_t *chars = str.UChars();
|
||||
|
||||
@@ -486,12 +612,88 @@ void DrawString(const PLPasStr &str)
|
||||
DrawGlyph(qdState, pixMap, rect, penPos, rfont, chars[i]);
|
||||
}
|
||||
|
||||
void PaintRectWithPCR(const Rect &rect, PaintColorResolution pcr)
|
||||
|
||||
void DrawSurface::DrawPicture(THandle<Picture> pictHdl, const Rect &bounds)
|
||||
{
|
||||
if (!pictHdl)
|
||||
return;
|
||||
|
||||
Picture *picPtr = *pictHdl;
|
||||
if (!picPtr)
|
||||
return;
|
||||
|
||||
const Rect picRect = picPtr->picFrame.ToRect();
|
||||
|
||||
if (bounds.right - bounds.left != picRect.right - picRect.left || bounds.bottom - bounds.top != picRect.bottom - picRect.top)
|
||||
{
|
||||
// Scaled pict draw (not supported)
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
|
||||
PortabilityLayer::QDPort *port = &m_port;
|
||||
|
||||
if (!port)
|
||||
return;
|
||||
|
||||
PortabilityLayer::PixMapImpl *pixMap = static_cast<PortabilityLayer::PixMapImpl*>(*port->GetPixMap());
|
||||
|
||||
long handleSize = pictHdl.MMBlock()->m_size;
|
||||
PortabilityLayer::MemReaderStream stream(picPtr, handleSize);
|
||||
|
||||
// Adjust draw origin
|
||||
const PortabilityLayer::Vec2i drawOrigin = PortabilityLayer::Vec2i(bounds.left - picPtr->picFrame.left, bounds.top - picPtr->picFrame.top);
|
||||
|
||||
switch (pixMap->GetPixelFormat())
|
||||
{
|
||||
case GpPixelFormats::kBW1:
|
||||
case GpPixelFormats::k8BitStandard:
|
||||
{
|
||||
PortabilityLayer::PixMapBlitEmitter blitEmitter(drawOrigin, pixMap);
|
||||
PortabilityLayer::QDPictDecoder decoder;
|
||||
|
||||
decoder.DecodePict(&stream, &blitEmitter);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// TODO: Implement higher-resolution pixel blitters
|
||||
assert(false);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void DrawSurface::SetPattern8x8(const uint8_t *pattern)
|
||||
{
|
||||
m_port.GetState()->SetPenPattern8x8(pattern);
|
||||
}
|
||||
|
||||
void DrawSurface::ClearPattern()
|
||||
{
|
||||
m_port.GetState()->SetPenPattern8x8(nullptr);
|
||||
}
|
||||
|
||||
void DrawSurface::SetMaskMode(bool maskMode)
|
||||
{
|
||||
m_port.GetState()->m_penMask = maskMode;
|
||||
}
|
||||
|
||||
Rect DrawSurface::GetClipRect() const
|
||||
{
|
||||
return m_port.GetState()->m_clipRect;
|
||||
}
|
||||
|
||||
void DrawSurface::SetClipRect(const Rect &rect)
|
||||
{
|
||||
m_port.GetState()->m_clipRect = rect;;
|
||||
}
|
||||
|
||||
void DrawSurface::FillRect(const Rect &rect)
|
||||
{
|
||||
if (!rect.IsValid())
|
||||
return;
|
||||
|
||||
PortabilityLayer::QDPort *qdPort = PortabilityLayer::QDManager::GetInstance()->GetPort();
|
||||
PortabilityLayer::QDPort *qdPort = &m_port;
|
||||
|
||||
GpPixelFormat_t pixelFormat = qdPort->GetPixelFormat();
|
||||
|
||||
@@ -515,19 +717,7 @@ void PaintRectWithPCR(const Rect &rect, PaintColorResolution pcr)
|
||||
{
|
||||
case GpPixelFormats::k8BitStandard:
|
||||
{
|
||||
uint8_t color = 0;
|
||||
switch (pcr)
|
||||
{
|
||||
case PaintColorResolution_Fore:
|
||||
color = qdState->ResolveForeColor8(nullptr, 0);
|
||||
break;
|
||||
case PaintColorResolution_Back:
|
||||
color = qdState->ResolveBackColor8(nullptr, 0);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
const uint8_t color = qdState->ResolveForeColor8(nullptr, 0);
|
||||
|
||||
size_t scanlineIndex = 0;
|
||||
for (size_t ln = 0; ln < numLines; ln++)
|
||||
@@ -544,18 +734,43 @@ void PaintRectWithPCR(const Rect &rect, PaintColorResolution pcr)
|
||||
}
|
||||
}
|
||||
|
||||
void PaintRect(const Rect *rect)
|
||||
void DrawSurface::FillRectWithPattern8x8(const Rect &rect, const uint8_t *pattern)
|
||||
{
|
||||
PaintRectWithPCR(*rect, PaintColorResolution_Fore);
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
|
||||
void PaintOval(const Rect *rect)
|
||||
void DrawSurface::SetApplicationFont(int size, int variationFlags)
|
||||
{
|
||||
if (!rect->IsValid())
|
||||
PortabilityLayer::FontFamily *fontFamily = PortabilityLayer::FontManager::GetInstance()->GetApplicationFont(size, variationFlags);
|
||||
if (!fontFamily)
|
||||
return;
|
||||
|
||||
PortabilityLayer::ScanlineMask *mask = PortabilityLayer::ScanlineMaskConverter::CompileEllipse(PortabilityLayer::Rect2i(rect->top, rect->left, rect->bottom, rect->right));
|
||||
PortabilityLayer::QDState *qdState = m_port.GetState();
|
||||
|
||||
qdState->m_fontFamily = fontFamily;
|
||||
qdState->m_fontSize = size;
|
||||
qdState->m_fontVariationFlags = variationFlags;
|
||||
}
|
||||
|
||||
void DrawSurface::SetSystemFont(int size, int variationFlags)
|
||||
{
|
||||
PortabilityLayer::FontFamily *fontFamily = PortabilityLayer::FontManager::GetInstance()->GetSystemFont(size, variationFlags);
|
||||
if (!fontFamily)
|
||||
return;
|
||||
|
||||
PortabilityLayer::QDState *qdState = m_port.GetState();
|
||||
|
||||
qdState->m_fontFamily = fontFamily;
|
||||
qdState->m_fontSize = size;
|
||||
qdState->m_fontVariationFlags = variationFlags;
|
||||
}
|
||||
|
||||
void DrawSurface::FillEllipse(const Rect &rect)
|
||||
{
|
||||
if (!rect.IsValid())
|
||||
return;
|
||||
|
||||
PortabilityLayer::ScanlineMask *mask = PortabilityLayer::ScanlineMaskConverter::CompileEllipse(PortabilityLayer::Rect2i(rect.top, rect.left, rect.bottom, rect.right));
|
||||
if (mask)
|
||||
{
|
||||
FillScanlineMask(mask);
|
||||
@@ -563,6 +778,11 @@ void PaintOval(const Rect *rect)
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSurface::FrameEllipse(const Rect &rect)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
static void FillScanlineSpan(uint8_t *rowStart, size_t startCol, size_t endCol, uint8_t patternByte, uint8_t foreColor, uint8_t bgColor, bool mask)
|
||||
{
|
||||
if (patternByte == 0xff)
|
||||
@@ -593,15 +813,14 @@ static void FillScanlineSpan(uint8_t *rowStart, size_t startCol, size_t endCol,
|
||||
}
|
||||
}
|
||||
|
||||
void FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask)
|
||||
void DrawSurface::FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask)
|
||||
{
|
||||
if (!scanlineMask)
|
||||
return;
|
||||
|
||||
PortabilityLayer::QDManager *qdManager = PortabilityLayer::QDManager::GetInstance();
|
||||
PortabilityLayer::QDState *qdState = qdManager->GetState();
|
||||
PortabilityLayer::QDPort *port = &m_port;
|
||||
PortabilityLayer::QDState *qdState = port->GetState();
|
||||
|
||||
const PortabilityLayer::QDPort *port = qdManager->GetPort();
|
||||
PixMap *pixMap = *port->GetPixMap();
|
||||
const Rect portRect = port->GetRect();
|
||||
const Rect maskRect = scanlineMask->GetRect();
|
||||
@@ -742,6 +961,17 @@ void FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawSurface::DrawLine(const Point &a, const Point &b)
|
||||
{
|
||||
PlotLine(m_port.GetState(), this, PortabilityLayer::Vec2i(a.h, a.v), PortabilityLayer::Vec2i(b.h, b.v));
|
||||
}
|
||||
|
||||
void DrawSurface::InvertDrawLine(const Point &a, const Point &b, const uint8_t *pattern)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void GetClip(Rect *rect)
|
||||
{
|
||||
PortabilityLayer::QDState *qdState = PortabilityLayer::QDManager::GetInstance()->GetState();
|
||||
@@ -757,42 +987,67 @@ void ClipRect(const Rect *rect)
|
||||
qdState->m_clipRect = *rect;
|
||||
}
|
||||
|
||||
void FrameRect(const Rect *rect)
|
||||
void DrawSurface::FrameRect(const Rect &rect)
|
||||
{
|
||||
if (!rect->IsValid())
|
||||
if (!rect.IsValid())
|
||||
return;
|
||||
|
||||
uint16_t width = rect->right - rect->left;
|
||||
uint16_t height = rect->bottom - rect->top;
|
||||
uint16_t width = rect.right - rect.left;
|
||||
uint16_t height = rect.bottom - rect.top;
|
||||
|
||||
if (width <= 2 || height <= 2)
|
||||
PaintRect(rect);
|
||||
FillRect(rect);
|
||||
else
|
||||
{
|
||||
// This is stupid, especially in the vertical case, but oh well
|
||||
Rect edgeRect;
|
||||
|
||||
edgeRect = *rect;
|
||||
edgeRect = rect;
|
||||
edgeRect.right = edgeRect.left + 1;
|
||||
PaintRect(&edgeRect);
|
||||
FillRect(edgeRect);
|
||||
|
||||
edgeRect = *rect;
|
||||
edgeRect = rect;
|
||||
edgeRect.left = edgeRect.right - 1;
|
||||
PaintRect(&edgeRect);
|
||||
FillRect(edgeRect);
|
||||
|
||||
edgeRect = *rect;
|
||||
edgeRect = rect;
|
||||
edgeRect.bottom = edgeRect.top + 1;
|
||||
PaintRect(&edgeRect);
|
||||
FillRect(edgeRect);
|
||||
|
||||
edgeRect = *rect;
|
||||
edgeRect = rect;
|
||||
edgeRect.top = edgeRect.bottom - 1;
|
||||
PaintRect(&edgeRect);
|
||||
FillRect(edgeRect);
|
||||
}
|
||||
}
|
||||
|
||||
void FrameOval(const Rect *rect)
|
||||
void DrawSurface::InvertFrameRect(const Rect &rect, const uint8_t *pattern)
|
||||
{
|
||||
PL_NotYetImplemented_TODO("Editor");
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void DrawSurface::InvertFillRect(const Rect &rect, const uint8_t *pattern)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void DrawSurface::SetForeColor(const PortabilityLayer::RGBAColor &color)
|
||||
{
|
||||
m_port.GetState()->SetForeColor(color);
|
||||
}
|
||||
|
||||
const PortabilityLayer::RGBAColor &DrawSurface::GetForeColor() const
|
||||
{
|
||||
return m_port.GetState()->GetForeColor();
|
||||
}
|
||||
|
||||
void DrawSurface::SetBackColor(const PortabilityLayer::RGBAColor &color)
|
||||
{
|
||||
m_port.GetState()->SetBackColor(color);
|
||||
}
|
||||
|
||||
const PortabilityLayer::RGBAColor &DrawSurface::GetBackColor() const
|
||||
{
|
||||
return m_port.GetState()->GetBackColor();
|
||||
}
|
||||
|
||||
void FrameRoundRect(const Rect *rect, int w, int h)
|
||||
@@ -830,11 +1085,6 @@ void PenNormal()
|
||||
qdState->m_penMask = false;
|
||||
}
|
||||
|
||||
void EraseRect(const Rect *rect)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void InvertRect(const Rect *rect)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
@@ -848,21 +1098,6 @@ void InsetRect(Rect *rect, int x, int y)
|
||||
rect->bottom -= y;
|
||||
}
|
||||
|
||||
void Line(int x, int y)
|
||||
{
|
||||
PortabilityLayer::QDManager *qdManager = PortabilityLayer::QDManager::GetInstance();
|
||||
PortabilityLayer::QDState *qdState = qdManager->GetState();
|
||||
|
||||
const PortabilityLayer::Vec2i oldPos = PortabilityLayer::Vec2i(qdState->m_penPos.h, qdState->m_penPos.v);
|
||||
|
||||
qdState->m_penPos.h += x;
|
||||
qdState->m_penPos.v += y;
|
||||
|
||||
const PortabilityLayer::Vec2i newPos = PortabilityLayer::Vec2i(qdState->m_penPos.h, qdState->m_penPos.v);
|
||||
|
||||
PlotLine(qdState, qdManager->GetPort(), oldPos, newPos);
|
||||
}
|
||||
|
||||
Pattern *GetQDGlobalsGray(Pattern *pattern)
|
||||
{
|
||||
uint8_t *patternBytes = *pattern;
|
||||
@@ -1120,12 +1355,12 @@ void CopyMask(const BitMap *srcBitmap, const BitMap *maskBitmap, BitMap *destBit
|
||||
CopyBitsComplete(srcBitmap, maskBitmap, destBitmap, srcRectBase, maskRectBase, destRectBase, nullptr);
|
||||
}
|
||||
|
||||
BitMap *GetPortBitMapForCopyBits(CGrafPtr grafPtr)
|
||||
BitMap *GetPortBitMapForCopyBits(DrawSurface *grafPtr)
|
||||
{
|
||||
return *grafPtr->m_port.GetPixMap();
|
||||
}
|
||||
|
||||
CGrafPtr GetWindowPort(WindowPtr window)
|
||||
DrawSurface *GetWindowPort(WindowPtr window)
|
||||
{
|
||||
return &window->m_graf;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#ifndef __PL_QUICKDRAW_H__
|
||||
#define __PL_QUICKDRAW_H__
|
||||
|
||||
#include "PLCore.h"
|
||||
#include "QDGraf.h"
|
||||
@@ -70,11 +68,20 @@ struct BitMap
|
||||
void Init(const Rect &rect, GpPixelFormat_t pixelFormat, size_t pitch, void *dataPtr);
|
||||
};
|
||||
|
||||
struct RGBColor
|
||||
class RGBColor
|
||||
{
|
||||
unsigned short red;
|
||||
unsigned short green;
|
||||
unsigned short blue;
|
||||
public:
|
||||
RGBColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
RGBColor(const RGBColor &other);
|
||||
|
||||
uint8_t GetRed() const;
|
||||
uint8_t GetGreen() const;
|
||||
uint8_t GetBlue() const;
|
||||
|
||||
private:
|
||||
uint8_t m_r;
|
||||
uint8_t m_g;
|
||||
uint8_t m_b;
|
||||
};
|
||||
|
||||
typedef CIcon *CIconPtr;
|
||||
@@ -90,7 +97,6 @@ void SetPort(GrafPtr graf);
|
||||
void SetPortWindowPort(WindowPtr window);
|
||||
void SetPortDialogPort(Dialog *dialog);
|
||||
|
||||
void BeginUpdate(WindowPtr graf);
|
||||
void EndUpdate(WindowPtr graf);
|
||||
|
||||
PLError_t GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags);
|
||||
@@ -102,27 +108,16 @@ void DisposeCIcon(CIconHandle icon);
|
||||
|
||||
void SetRect(Rect *rect, short left, short top, short right, short bottom);
|
||||
|
||||
void TextSize(int sz);
|
||||
void TextFace(int face);
|
||||
void TextFont(int fontID);
|
||||
int TextWidth(const PLPasStr &str, int firstChar1Based, int length);
|
||||
void MoveTo(int x, int y);
|
||||
void LineTo(int x, int y);
|
||||
void SetOrigin(int x, int y);
|
||||
void ForeColor(SystemColorID color);
|
||||
void BackColor(SystemColorID color);
|
||||
void GetForeColor(RGBColor *color);
|
||||
void Index2Color(int index, RGBColor *color);
|
||||
void RGBForeColor(const RGBColor *color);
|
||||
void DrawString(const PLPasStr &str);
|
||||
void PaintRect(const Rect *rect);
|
||||
void PaintOval(const Rect *rect);
|
||||
void FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask);
|
||||
|
||||
void ClipRect(const Rect *rect);
|
||||
void GetClip(Rect *rect);
|
||||
|
||||
void FrameRect(const Rect *rect);
|
||||
void FrameOval(const Rect *rect);
|
||||
void FrameRoundRect(const Rect *rect, int w, int h);
|
||||
void PenInvertMode(bool invertMode);
|
||||
@@ -130,10 +125,8 @@ void PenMask(bool maskMode);
|
||||
void PenPat(const Pattern *pattern);
|
||||
void PenSize(int w, int h);
|
||||
void PenNormal();
|
||||
void EraseRect(const Rect *rect);
|
||||
void InvertRect(const Rect *rect);
|
||||
void InsetRect(Rect *rect, int x, int y);
|
||||
void Line(int x, int y);
|
||||
Pattern *GetQDGlobalsGray(Pattern *pattern);
|
||||
Pattern *GetQDGlobalsBlack(Pattern *pattern);
|
||||
|
||||
@@ -150,8 +143,8 @@ void CopyMaskConstrained(const BitMap *srcBitmap, const BitMap *maskBitmap, BitM
|
||||
|
||||
bool PointInScanlineMask(Point point, PortabilityLayer::ScanlineMask *scanlineMask);
|
||||
|
||||
BitMap *GetPortBitMapForCopyBits(CGrafPtr grafPtr);
|
||||
CGrafPtr GetWindowPort(WindowPtr window);
|
||||
BitMap *GetPortBitMapForCopyBits(DrawSurface *grafPtr);
|
||||
DrawSurface *GetWindowPort(WindowPtr window);
|
||||
|
||||
// Computes A - B and returns it packed?
|
||||
Int32 DeltaPoint(Point pointA, Point pointB);
|
||||
@@ -165,4 +158,17 @@ Boolean PtInRect(Point point, const Rect *rect);
|
||||
|
||||
void RestoreDeviceClut(void *unknown);
|
||||
|
||||
#endif
|
||||
|
||||
inline RGBColor::RGBColor(uint8_t r, uint8_t g, uint8_t b)
|
||||
: m_r(r)
|
||||
, m_g(g)
|
||||
, m_b(b)
|
||||
{
|
||||
}
|
||||
|
||||
inline RGBColor::RGBColor(const RGBColor &other)
|
||||
: m_r(other.m_r)
|
||||
, m_g(other.m_g)
|
||||
, m_b(other.m_b)
|
||||
{
|
||||
}
|
||||
|
||||
27
PortabilityLayer/PLStandardColors.cpp
Normal file
27
PortabilityLayer/PLStandardColors.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "PLStandardColors.h"
|
||||
#include "RGBAColor.h"
|
||||
|
||||
PortabilityLayer::RGBAColor StdColors::Black()
|
||||
{
|
||||
return PortabilityLayer::RGBAColor::Create(0, 0, 0, 255);
|
||||
}
|
||||
|
||||
PortabilityLayer::RGBAColor StdColors::White()
|
||||
{
|
||||
return PortabilityLayer::RGBAColor::Create(255, 255, 255, 255);
|
||||
}
|
||||
|
||||
PortabilityLayer::RGBAColor StdColors::Red()
|
||||
{
|
||||
return PortabilityLayer::RGBAColor::Create(255, 0, 0, 255);
|
||||
}
|
||||
|
||||
PortabilityLayer::RGBAColor StdColors::Green()
|
||||
{
|
||||
return PortabilityLayer::RGBAColor::Create(0, 255, 0, 255);
|
||||
}
|
||||
|
||||
PortabilityLayer::RGBAColor StdColors::Blue()
|
||||
{
|
||||
return PortabilityLayer::RGBAColor::Create(0, 0, 255, 255);
|
||||
}
|
||||
16
PortabilityLayer/PLStandardColors.h
Normal file
16
PortabilityLayer/PLStandardColors.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct RGBAColor;
|
||||
}
|
||||
|
||||
class StdColors
|
||||
{
|
||||
public:
|
||||
static PortabilityLayer::RGBAColor Black();
|
||||
static PortabilityLayer::RGBAColor White();
|
||||
static PortabilityLayer::RGBAColor Red();
|
||||
static PortabilityLayer::RGBAColor Green();
|
||||
static PortabilityLayer::RGBAColor Blue();
|
||||
};
|
||||
@@ -138,6 +138,7 @@
|
||||
<ClInclude Include="CFileStream.h" />
|
||||
<ClInclude Include="ClientAudioChannelContext.h" />
|
||||
<ClInclude Include="DataTypes.h" />
|
||||
<ClInclude Include="DialogManager.h" />
|
||||
<ClInclude Include="DisplayDeviceManager.h" />
|
||||
<ClInclude Include="EllipsePlotter.h" />
|
||||
<ClInclude Include="FileManager.h" />
|
||||
@@ -199,6 +200,8 @@
|
||||
<ClInclude Include="PLMacTypes.h" />
|
||||
<ClInclude Include="MenuManager.h" />
|
||||
<ClInclude Include="PlotDirection.h" />
|
||||
<ClInclude Include="PLStandardColors.h" />
|
||||
<ClInclude Include="ResolvedColor.h" />
|
||||
<ClInclude Include="ScanlineMaskBuilder.h" />
|
||||
<ClInclude Include="ScanlineMaskConverter.h" />
|
||||
<ClInclude Include="QDGraf.h" />
|
||||
@@ -260,6 +263,7 @@
|
||||
<ClCompile Include="BinHex4.cpp" />
|
||||
<ClCompile Include="ByteSwap.cpp" />
|
||||
<ClCompile Include="CFileStream.cpp" />
|
||||
<ClCompile Include="DialogManager.cpp" />
|
||||
<ClCompile Include="DisplayDeviceManager.cpp" />
|
||||
<ClCompile Include="EllipsePlotter.cpp" />
|
||||
<ClCompile Include="FileManager.cpp" />
|
||||
@@ -300,6 +304,7 @@
|
||||
<ClCompile Include="PLResourceManager.cpp" />
|
||||
<ClCompile Include="PLResources.cpp" />
|
||||
<ClCompile Include="PLSound.cpp" />
|
||||
<ClCompile Include="PLStandardColors.cpp" />
|
||||
<ClCompile Include="PLStringCompare.cpp" />
|
||||
<ClCompile Include="ScanlineMask.cpp" />
|
||||
<ClCompile Include="ScanlineMaskBuilder.cpp" />
|
||||
|
||||
@@ -393,6 +393,15 @@
|
||||
<ClInclude Include="PLHandle.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DialogManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="PLStandardColors.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ResolvedColor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CFileStream.cpp">
|
||||
@@ -596,5 +605,11 @@
|
||||
<ClCompile Include="PLHandle.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DialogManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PLStandardColors.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpDisplayDriverSurface.h"
|
||||
|
||||
void CGraf::PushToDDSurface(IGpDisplayDriver *displayDriver)
|
||||
void DrawSurface::PushToDDSurface(IGpDisplayDriver *displayDriver)
|
||||
{
|
||||
const PixMap *pixMap = *m_port.GetPixMap();
|
||||
const size_t width = pixMap->m_rect.right - pixMap->m_rect.left;
|
||||
|
||||
@@ -3,23 +3,34 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "GpPixelFormat.h"
|
||||
#include "PLHandle.h"
|
||||
#include "QDState.h"
|
||||
#include "QDPort.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class FontFamily;
|
||||
struct RGBAColor;
|
||||
class ScanlineMask;
|
||||
}
|
||||
|
||||
struct PixMap;
|
||||
struct Picture;
|
||||
struct Point;
|
||||
struct Rect;
|
||||
struct IGpDisplayDriver;
|
||||
struct IGpDisplayDriverSurface;
|
||||
class PLPasStr;
|
||||
|
||||
struct CGraf final
|
||||
struct DrawSurface final
|
||||
{
|
||||
CGraf()
|
||||
: m_port(PortabilityLayer::QDPortType_CGraf)
|
||||
DrawSurface()
|
||||
: m_port(PortabilityLayer::QDPortType_DrawSurface)
|
||||
, m_ddSurface(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CGraf(PortabilityLayer::QDPortType overridePortType)
|
||||
explicit DrawSurface(PortabilityLayer::QDPortType overridePortType)
|
||||
: m_port(overridePortType)
|
||||
, m_ddSurface(nullptr)
|
||||
{
|
||||
@@ -40,6 +51,40 @@ struct CGraf final
|
||||
|
||||
void PushToDDSurface(IGpDisplayDriver *displayDriver);
|
||||
|
||||
void FillRect(const Rect &rect);
|
||||
void FillRectWithPattern8x8(const Rect &rect, const uint8_t *pattern);
|
||||
void FrameRect(const Rect &rect);
|
||||
void InvertFrameRect(const Rect &rect, const uint8_t *pattern);
|
||||
void InvertFillRect(const Rect &rect, const uint8_t *pattern);
|
||||
|
||||
void FillEllipse(const Rect &rect);
|
||||
void FrameEllipse(const Rect &rect);
|
||||
|
||||
void FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask);
|
||||
|
||||
void DrawLine(const Point &a, const Point &b);
|
||||
void InvertDrawLine(const Point &a, const Point &b, const uint8_t *pattern);
|
||||
|
||||
void SetForeColor(const PortabilityLayer::RGBAColor &color);
|
||||
const PortabilityLayer::RGBAColor &GetForeColor() const;
|
||||
|
||||
void SetBackColor(const PortabilityLayer::RGBAColor &color);
|
||||
const PortabilityLayer::RGBAColor &GetBackColor() const;
|
||||
|
||||
void SetApplicationFont(int size, int variationFlags);
|
||||
void SetSystemFont(int size, int variationFlags);
|
||||
void DrawString(const Point &point, const PLPasStr &str);
|
||||
|
||||
void DrawPicture(THandle<Picture> pictHandle, const Rect &rect);
|
||||
|
||||
void SetPattern8x8(const uint8_t *pattern);
|
||||
void ClearPattern();
|
||||
|
||||
void SetMaskMode(bool maskMode);
|
||||
|
||||
Rect GetClipRect() const;
|
||||
void SetClipRect(const Rect &rect);
|
||||
|
||||
// Must be the first item
|
||||
PortabilityLayer::QDPort m_port;
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace PortabilityLayer
|
||||
void Init() override;
|
||||
QDPort *GetPort() const override;
|
||||
void SetPort(QDPort *gw) override;
|
||||
PLError_t NewGWorld(CGraf **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) override;
|
||||
void DisposeGWorld(CGraf *gw) override;
|
||||
PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) override;
|
||||
void DisposeGWorld(DrawSurface *gw) override;
|
||||
QDState *GetState() override;
|
||||
|
||||
static QDManagerImpl *GetInstance();
|
||||
@@ -49,16 +49,16 @@ namespace PortabilityLayer
|
||||
m_port = gw;
|
||||
}
|
||||
|
||||
PLError_t QDManagerImpl::NewGWorld(CGraf **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable)
|
||||
PLError_t QDManagerImpl::NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable)
|
||||
{
|
||||
void *grafStorage = MemoryManager::GetInstance()->Alloc(sizeof(CGraf));
|
||||
void *grafStorage = MemoryManager::GetInstance()->Alloc(sizeof(DrawSurface));
|
||||
if (!grafStorage)
|
||||
return PLErrors::kOutOfMemory;
|
||||
|
||||
if (!bounds.IsValid())
|
||||
return PLErrors::kInvalidParameter;
|
||||
|
||||
CGraf *graf = new (grafStorage) CGraf();
|
||||
DrawSurface *graf = new (grafStorage) DrawSurface();
|
||||
PLError_t initError = graf->Init(bounds, pixelFormat);
|
||||
if (initError)
|
||||
{
|
||||
@@ -70,9 +70,9 @@ namespace PortabilityLayer
|
||||
return PLErrors::kNone;
|
||||
}
|
||||
|
||||
void QDManagerImpl::DisposeGWorld(CGraf *gw)
|
||||
void QDManagerImpl::DisposeGWorld(DrawSurface *gw)
|
||||
{
|
||||
gw->~CGraf();
|
||||
gw->~DrawSurface();
|
||||
MemoryManager::GetInstance()->Release(gw);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "PLErrorCodes.h"
|
||||
|
||||
struct ColorTable;
|
||||
struct CGraf;
|
||||
struct DrawSurface;
|
||||
struct Rect;
|
||||
|
||||
namespace PortabilityLayer
|
||||
@@ -18,8 +18,8 @@ namespace PortabilityLayer
|
||||
virtual void Init() = 0;
|
||||
virtual QDPort *GetPort() const = 0;
|
||||
virtual void SetPort(QDPort *gw) = 0;
|
||||
virtual PLError_t NewGWorld(CGraf **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) = 0;
|
||||
virtual void DisposeGWorld(CGraf *gw) = 0;
|
||||
virtual PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) = 0;
|
||||
virtual void DisposeGWorld(DrawSurface *gw) = 0;
|
||||
|
||||
virtual QDState *GetState() = 0;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
QDPortType_Invalid,
|
||||
|
||||
QDPortType_CGraf,
|
||||
QDPortType_DrawSurface,
|
||||
QDPortType_Window,
|
||||
};
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
QDState::QDState()
|
||||
: m_fontID(applFont)
|
||||
, m_textSize(12)
|
||||
, m_textFace(0)
|
||||
: m_fontFamily(nullptr)
|
||||
, m_fontSize(12)
|
||||
, m_fontVariationFlags(0)
|
||||
, m_foreResolvedColor16(0)
|
||||
, m_backResolvedColor16(0)
|
||||
, m_foreResolvedColor8(0)
|
||||
|
||||
@@ -5,13 +5,15 @@
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class FontFamily;
|
||||
|
||||
struct QDState
|
||||
{
|
||||
QDState();
|
||||
|
||||
int m_fontID;
|
||||
int m_textFace;
|
||||
int m_textSize;
|
||||
FontFamily *m_fontFamily;
|
||||
int m_fontVariationFlags;
|
||||
int m_fontSize;
|
||||
Rect m_clipRect;
|
||||
Point m_penPos;
|
||||
bool m_penInvert;
|
||||
|
||||
9
PortabilityLayer/ResolvedColor.h
Normal file
9
PortabilityLayer/ResolvedColor.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "RGBAColor.h"
|
||||
|
||||
union ResolvedColor
|
||||
{
|
||||
uint8_t m_indexed;
|
||||
PortabilityLayer::RGBAColor m_rgba;
|
||||
};
|
||||
@@ -9,6 +9,11 @@ struct Point
|
||||
{
|
||||
int16_t v;
|
||||
int16_t h;
|
||||
|
||||
Point operator-(const Point &other) const;
|
||||
Point operator+(const Point &other) const;
|
||||
|
||||
static Point Create(int16_t h, int16_t v);
|
||||
};
|
||||
|
||||
struct Rect
|
||||
@@ -21,7 +26,9 @@ struct Rect
|
||||
bool IsValid() const;
|
||||
Rect Intersect(const Rect &rect) const;
|
||||
Rect MakeValid() const;
|
||||
|
||||
static Rect Create(int16_t top, int16_t left, int16_t bottom, int16_t right);
|
||||
static Rect CreateFromPoints(const Point &topLeft, const Point &bottomRight);
|
||||
};
|
||||
|
||||
struct BERect
|
||||
@@ -93,6 +100,25 @@ struct GDevice
|
||||
bool paletteIsDirty;
|
||||
};
|
||||
|
||||
inline Point Point::operator-(const Point &other) const
|
||||
{
|
||||
return Point::Create(this->h - other.h, this->v - other.v);
|
||||
}
|
||||
|
||||
inline Point Point::operator+(const Point &other) const
|
||||
{
|
||||
return Point::Create(this->h + other.h, this->v + other.v);
|
||||
}
|
||||
|
||||
inline Point Point::Create(int16_t h, int16_t v)
|
||||
{
|
||||
Point p;
|
||||
p.h = h;
|
||||
p.v = v;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
inline bool Rect::IsValid() const
|
||||
{
|
||||
return this->top <= this->bottom && this->left <= this->right;
|
||||
@@ -136,3 +162,8 @@ inline Rect Rect::Create(int16_t top, int16_t left, int16_t bottom, int16_t righ
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Rect Rect::CreateFromPoints(const Point &topLeft, const Point &bottomRight)
|
||||
{
|
||||
return Rect::Create(topLeft.v, topLeft.h, bottomRight.v, bottomRight.h);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace PortabilityLayer
|
||||
void ShowWindow(Window *window) override;
|
||||
void HideWindow(Window *window) override;
|
||||
void FindWindow(const Point &point, Window **outWindow, short *outRegion) const override;
|
||||
void DestroyWindow(Window *window) override;
|
||||
|
||||
void RenderFrame(IGpDisplayDriver *displayDriver) override;
|
||||
|
||||
@@ -236,7 +237,6 @@ namespace PortabilityLayer
|
||||
// outRegion = One of:
|
||||
/*
|
||||
inMenuBar,
|
||||
inSysWindow,
|
||||
inContent,
|
||||
inDrag,
|
||||
inGrow,
|
||||
@@ -285,6 +285,16 @@ namespace PortabilityLayer
|
||||
*outRegion = 0;
|
||||
}
|
||||
|
||||
void WindowManagerImpl::DestroyWindow(Window *window)
|
||||
{
|
||||
WindowImpl *windowImpl = static_cast<WindowImpl*>(window);
|
||||
|
||||
DetachWindow(window);
|
||||
|
||||
windowImpl->~WindowImpl();
|
||||
PortabilityLayer::MemoryManager::GetInstance()->Release(windowImpl);
|
||||
}
|
||||
|
||||
void WindowManagerImpl::RenderFrame(IGpDisplayDriver *displayDriver)
|
||||
{
|
||||
PortabilityLayer::DisplayDeviceManager *dd = PortabilityLayer::DisplayDeviceManager::GetInstance();
|
||||
@@ -342,7 +352,7 @@ namespace PortabilityLayer
|
||||
|
||||
void WindowManagerImpl::RenderWindow(WindowImpl *window, IGpDisplayDriver *displayDriver)
|
||||
{
|
||||
CGraf &graf = window->m_graf;
|
||||
DrawSurface &graf = window->m_graf;
|
||||
|
||||
graf.PushToDDSurface(displayDriver);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
struct Window;
|
||||
struct CGraf;
|
||||
struct DrawSurface;
|
||||
struct GDevice;
|
||||
struct IGpDisplayDriver;
|
||||
struct Point;
|
||||
@@ -22,6 +22,7 @@ namespace PortabilityLayer
|
||||
virtual void ShowWindow(Window *window) = 0;
|
||||
virtual void HideWindow(Window *window) = 0;
|
||||
virtual void FindWindow(const Point &point, Window **outWindow, short *outRegion) const = 0;
|
||||
virtual void DestroyWindow(Window *window) = 0;
|
||||
|
||||
virtual void RenderFrame(IGpDisplayDriver *displayDriver) = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user