mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Edit box baseline (regresses volume control dialog though)
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "PLButtonWidget.h"
|
#include "PLButtonWidget.h"
|
||||||
#include "PLCheckboxWidget.h"
|
#include "PLCheckboxWidget.h"
|
||||||
#include "PLDialogs.h"
|
#include "PLDialogs.h"
|
||||||
|
#include "PLEditboxWidget.h"
|
||||||
#include "PLIconWidget.h"
|
#include "PLIconWidget.h"
|
||||||
#include "PLImageWidget.h"
|
#include "PLImageWidget.h"
|
||||||
#include "PLInvisibleWidget.h"
|
#include "PLInvisibleWidget.h"
|
||||||
@@ -315,6 +316,8 @@ namespace PortabilityLayer
|
|||||||
widget = RadioButtonWidget::Create(basicState);
|
widget = RadioButtonWidget::Create(basicState);
|
||||||
break;
|
break;
|
||||||
case SerializedDialogItemTypeCodes::kEditBox:
|
case SerializedDialogItemTypeCodes::kEditBox:
|
||||||
|
widget = EditboxWidget::Create(basicState);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
widget = InvisibleWidget::Create(basicState);
|
widget = InvisibleWidget::Create(basicState);
|
||||||
break;
|
break;
|
||||||
|
72
PortabilityLayer/PLEditboxWidget.cpp
Normal file
72
PortabilityLayer/PLEditboxWidget.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#include "PLEditboxWidget.h"
|
||||||
|
#include "PLStandardColors.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
#include "FontFamily.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace PortabilityLayer
|
||||||
|
{
|
||||||
|
EditboxWidget::EditboxWidget(const WidgetBasicState &state)
|
||||||
|
: WidgetSpec<EditboxWidget>(state)
|
||||||
|
, m_capacity(255)
|
||||||
|
, m_length(0)
|
||||||
|
, m_chars(nullptr)
|
||||||
|
, m_selStartChar(0)
|
||||||
|
, m_selEndChar(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EditboxWidget::~EditboxWidget()
|
||||||
|
{
|
||||||
|
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
|
||||||
|
|
||||||
|
if (m_chars)
|
||||||
|
mm->Release(m_chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditboxWidget::Init(const WidgetBasicState &state)
|
||||||
|
{
|
||||||
|
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
|
||||||
|
m_capacity = 255;
|
||||||
|
|
||||||
|
m_chars = static_cast<uint8_t*>(mm->Alloc(m_capacity * sizeof(m_chars[0])));
|
||||||
|
if (!m_chars)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditboxWidget::EditboxWidget::DrawControl(DrawSurface *surface)
|
||||||
|
{
|
||||||
|
const Rect textRect = m_rect;
|
||||||
|
const Rect innerRect = textRect.Inset(-2, -2);
|
||||||
|
const Rect outerRect = innerRect.Inset(-1, -1);
|
||||||
|
|
||||||
|
surface->SetForeColor(StdColors::Black());
|
||||||
|
surface->FillRect(outerRect);
|
||||||
|
surface->SetForeColor(StdColors::White());
|
||||||
|
surface->FillRect(innerRect);
|
||||||
|
|
||||||
|
surface->SetForeColor(StdColors::Black());
|
||||||
|
surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_None);
|
||||||
|
int32_t ascender = surface->MeasureFontAscender();
|
||||||
|
|
||||||
|
Point basePoint = Point::Create(textRect.left, (textRect.top + textRect.bottom + ascender + 1) / 2);
|
||||||
|
surface->DrawStringConstrained(basePoint, this->GetString(), true, m_rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditboxWidget::SetString(const PLPasStr &str)
|
||||||
|
{
|
||||||
|
const size_t len = std::min<size_t>(m_capacity, str.Length());
|
||||||
|
|
||||||
|
m_length = len;
|
||||||
|
memcpy(m_chars, str.UChars(), len);
|
||||||
|
}
|
||||||
|
|
||||||
|
PLPasStr EditboxWidget::GetString() const
|
||||||
|
{
|
||||||
|
const uint8_t len = static_cast<uint8_t>(std::min<size_t>(255, m_length));
|
||||||
|
return PLPasStr(len, reinterpret_cast<const char*>(m_chars));
|
||||||
|
}
|
||||||
|
}
|
27
PortabilityLayer/PLEditboxWidget.h
Normal file
27
PortabilityLayer/PLEditboxWidget.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "PascalStr.h"
|
||||||
|
#include "PLWidgets.h"
|
||||||
|
|
||||||
|
namespace PortabilityLayer
|
||||||
|
{
|
||||||
|
class EditboxWidget final : public WidgetSpec<EditboxWidget>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EditboxWidget(const WidgetBasicState &state);
|
||||||
|
~EditboxWidget();
|
||||||
|
|
||||||
|
bool Init(const WidgetBasicState &state) override;
|
||||||
|
|
||||||
|
void DrawControl(DrawSurface *surface) override;
|
||||||
|
void SetString(const PLPasStr &str) override;
|
||||||
|
PLPasStr GetString() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t *m_chars;
|
||||||
|
size_t m_capacity;
|
||||||
|
size_t m_length;
|
||||||
|
size_t m_selStartChar;
|
||||||
|
size_t m_selEndChar;
|
||||||
|
};
|
||||||
|
}
|
@@ -31,10 +31,6 @@ namespace PortabilityLayer
|
|||||||
|
|
||||||
void LabelWidget::DrawControl(DrawSurface *surface)
|
void LabelWidget::DrawControl(DrawSurface *surface)
|
||||||
{
|
{
|
||||||
// FIXME: This is kind of bad
|
|
||||||
surface->SetForeColor(StdColors::White());
|
|
||||||
surface->FillRect(m_rect);
|
|
||||||
|
|
||||||
surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold);
|
surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold);
|
||||||
surface->SetForeColor(StdColors::Black());
|
surface->SetForeColor(StdColors::Black());
|
||||||
|
|
||||||
|
@@ -309,8 +309,8 @@ static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const
|
|||||||
if (clampedLeftCoord >= clampedRightCoord || clampedTopCoord >= clampedBottomCoord)
|
if (clampedLeftCoord >= clampedRightCoord || clampedTopCoord >= clampedBottomCoord)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const uint32_t firstOutputRow = clampedTopCoord - rect.top;
|
const uint32_t firstOutputRow = clampedTopCoord;
|
||||||
const uint32_t firstOutputCol = clampedLeftCoord - rect.left;
|
const uint32_t firstOutputCol = clampedLeftCoord;
|
||||||
|
|
||||||
const uint32_t firstInputRow = clampedTopCoord - topCoord;
|
const uint32_t firstInputRow = clampedTopCoord - topCoord;
|
||||||
const uint32_t firstInputCol = clampedLeftCoord - leftCoord;
|
const uint32_t firstInputCol = clampedLeftCoord - leftCoord;
|
||||||
@@ -394,6 +394,11 @@ static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DrawSurface::DrawString(const Point &point, const PLPasStr &str, bool aa)
|
void DrawSurface::DrawString(const Point &point, const PLPasStr &str, bool aa)
|
||||||
|
{
|
||||||
|
DrawStringConstrained(point, str, aa, Rect::CreateLargest());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawSurface::DrawStringConstrained(const Point &point, const PLPasStr &str, bool aa, const Rect &constraintRect)
|
||||||
{
|
{
|
||||||
PortabilityLayer::QDPort *port = &m_port;
|
PortabilityLayer::QDPort *port = &m_port;
|
||||||
|
|
||||||
@@ -413,10 +418,10 @@ void DrawSurface::DrawString(const Point &point, const PLPasStr &str, bool aa)
|
|||||||
|
|
||||||
PixMap *pixMap = *port->GetPixMap();
|
PixMap *pixMap = *port->GetPixMap();
|
||||||
|
|
||||||
const Rect rect = pixMap->m_rect;
|
const Rect rect = pixMap->m_rect.Intersect(constraintRect);
|
||||||
|
|
||||||
if (!rect.IsValid())
|
if (!rect.IsValid())
|
||||||
return; // ???
|
return;
|
||||||
|
|
||||||
Point paraStartPos = penPos;
|
Point paraStartPos = penPos;
|
||||||
|
|
||||||
|
@@ -206,6 +206,7 @@
|
|||||||
<ClInclude Include="PLCore.h" />
|
<ClInclude Include="PLCore.h" />
|
||||||
<ClInclude Include="PLCTabReducer.h" />
|
<ClInclude Include="PLCTabReducer.h" />
|
||||||
<ClInclude Include="PLDialogs.h" />
|
<ClInclude Include="PLDialogs.h" />
|
||||||
|
<ClInclude Include="PLEditboxWidget.h" />
|
||||||
<ClInclude Include="PLErrorCodes.h" />
|
<ClInclude Include="PLErrorCodes.h" />
|
||||||
<ClInclude Include="PLEventQueue.h" />
|
<ClInclude Include="PLEventQueue.h" />
|
||||||
<ClInclude Include="PLHacks.h" />
|
<ClInclude Include="PLHacks.h" />
|
||||||
@@ -330,6 +331,7 @@
|
|||||||
<ClCompile Include="PLCore.cpp" />
|
<ClCompile Include="PLCore.cpp" />
|
||||||
<ClCompile Include="PLCTabReducer.cpp" />
|
<ClCompile Include="PLCTabReducer.cpp" />
|
||||||
<ClCompile Include="PLDialogs.cpp" />
|
<ClCompile Include="PLDialogs.cpp" />
|
||||||
|
<ClCompile Include="PLEditboxWidget.cpp" />
|
||||||
<ClCompile Include="PLEventQueue.cpp" />
|
<ClCompile Include="PLEventQueue.cpp" />
|
||||||
<ClCompile Include="PLHacks.cpp" />
|
<ClCompile Include="PLHacks.cpp" />
|
||||||
<ClCompile Include="PLIconWidget.cpp" />
|
<ClCompile Include="PLIconWidget.cpp" />
|
||||||
|
@@ -468,6 +468,9 @@
|
|||||||
<ClInclude Include="CombinedTimestamp.h">
|
<ClInclude Include="CombinedTimestamp.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="PLEditboxWidget.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="CFileStream.cpp">
|
<ClCompile Include="CFileStream.cpp">
|
||||||
@@ -734,5 +737,8 @@
|
|||||||
<ClCompile Include="BitmapImage.cpp">
|
<ClCompile Include="BitmapImage.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="PLEditboxWidget.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@@ -82,6 +82,7 @@ struct DrawSurface final
|
|||||||
void SetApplicationFont(int size, int variationFlags);
|
void SetApplicationFont(int size, int variationFlags);
|
||||||
void SetSystemFont(int size, int variationFlags);
|
void SetSystemFont(int size, int variationFlags);
|
||||||
void DrawString(const Point &point, const PLPasStr &str, bool aa);
|
void DrawString(const Point &point, const PLPasStr &str, bool aa);
|
||||||
|
void DrawStringConstrained(const Point &point, const PLPasStr &str, bool aa, const Rect &constraintRect);
|
||||||
void DrawStringWrap(const Point &point, const Rect &constrainRect, const PLPasStr &str, bool aa);
|
void DrawStringWrap(const Point &point, const Rect &constrainRect, const PLPasStr &str, bool aa);
|
||||||
|
|
||||||
size_t MeasureString(const PLPasStr &str);
|
size_t MeasureString(const PLPasStr &str);
|
||||||
|
@@ -47,6 +47,7 @@ struct Rect
|
|||||||
|
|
||||||
static Rect Create(int16_t top, int16_t left, int16_t bottom, int16_t right);
|
static Rect Create(int16_t top, int16_t left, int16_t bottom, int16_t right);
|
||||||
static Rect CreateFromPoints(const Point &topLeft, const Point &bottomRight);
|
static Rect CreateFromPoints(const Point &topLeft, const Point &bottomRight);
|
||||||
|
static Rect CreateLargest();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BERect
|
struct BERect
|
||||||
@@ -244,3 +245,8 @@ inline Rect Rect::CreateFromPoints(const Point &topLeft, const Point &bottomRigh
|
|||||||
{
|
{
|
||||||
return Rect::Create(topLeft.v, topLeft.h, bottomRight.v, bottomRight.h);
|
return Rect::Create(topLeft.v, topLeft.h, bottomRight.v, bottomRight.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Rect Rect::CreateLargest()
|
||||||
|
{
|
||||||
|
return Rect::Create(-0x8000, -0x8000, 0x7fff, 0x7fff);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user