summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemText.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
commitc0c336500955a23e344651e5412c9d9d441ef4ee (patch)
tree790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2DlgItemText.cpp
parent37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff)
downloadt2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz
t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2DlgItemText.cpp88
1 files changed, 80 insertions, 8 deletions
diff --git a/src/T2DLL/T2DlgItemText.cpp b/src/T2DLL/T2DlgItemText.cpp
index 71f9242..e8bd018 100644
--- a/src/T2DLL/T2DlgItemText.cpp
+++ b/src/T2DLL/T2DlgItemText.cpp
@@ -1,28 +1,100 @@
#include "T2DlgItemText.h"
-T2DlgItemText::T2DlgItemText(T2TowerDoc*, T2ImageObj*, CPalette*) {
+T2DlgItemText::T2DlgItemText(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
+ : T2DlgItem(inDoc, inImageObj, inPalette)
+ , mHasTextColor(false)
+{
}
-void T2DlgItemText::SetTextColor(unsigned long) {
+void T2DlgItemText::SetTextColor(COLORREF inColor) {
+ mTextColor = inColor;
+ mHasTextColor = true;
}
-/*virtual*/ void T2DlgItemText::GetDescriptor(CString&) const {
+/*virtual*/ void T2DlgItemText::GetDescriptor(CString& outStr) const {
+ GetContentText(outStr);
}
-/*virtual*/ void T2DlgItemText::SetDescriptor(const CString&) {
+/*virtual*/ void T2DlgItemText::SetDescriptor(const CString& inStr) {
+ CString str(GetJustification());
+ str += inStr;
+ SetWindowText(str);
+
+ CRect rect;
+ GetClientRect(rect);
+ MapWindowPoints(GetParent(), rect);
+ GetParent()->InvalidateRect(rect);
}
-/*virtual*/ int T2DlgItemText::OnT2DlgItemEraseBkgnd(CDC*) {
+/*virtual*/ BOOL T2DlgItemText::OnT2DlgItemEraseBkgnd(CDC* pDC) {
+ CRect rect;
+ GetClientRect(rect);
+
+ int save = pDC->SaveDC();
+
+ pDC->SelectPalette(mPalette, false);
+ pDC->RealizePalette();
+ pDC->SetTextColor(mHasTextColor ? mTextColor : PALETTEINDEX(255));
+ pDC->SetBkMode(TRANSPARENT);
+ pDC->SelectObject(mFont);
+
+ CString str;
+ GetContentText(str);
+
+ char justification = GetJustification();
+ UINT flags = DT_WORDBREAK | DT_NOPREFIX;
+
+ if (isupper(justification)) {
+ flags |= DT_VCENTER;
+ justification = tolower(justification);
+ }
+
+ switch (justification) {
+ case 'c': flags |= DT_CENTER; break;
+ case 'l': flags |= DT_LEFT; break;
+ case 'r': flags |= DT_RIGHT; break;
+ }
+
+ pDC->DrawText(str, rect, flags);
+
+ pDC->RestoreDC(save);
+
+ return true;
}
char T2DlgItemText::GetJustification() const {
+ char result = 'l';
+
+ CString text;
+ GetWindowText(text);
+ if (text.GetLength() > 0)
+ result = text[0];
+
+ return result;
}
-void T2DlgItemText::GetContentText(CString&) const {
+void T2DlgItemText::GetContentText(CString& outStr) const {
+ GetWindowText(outStr);
+
+ if (outStr.GetLength() > 0)
+ outStr = outStr.Mid(1);
}
-void T2DlgItemText::InfoDialogMessage(CString&, long) {
+void T2DlgItemText::InfoDialogMessage(CString& inStr, long inTime) {
+ if (inTime != -1) {
+ GetDescriptor(mPreviousString);
+ mTimerID = SetTimer(1000, inTime, NULL);
+ } else {
+ mPreviousString.Empty();
+ mTimerID = 0;
+ }
+ SetDescriptor(inStr);
}
-/*virtual*/ void T2DlgItemText::OnT2Timer(unsigned int) {
+/*virtual*/ void T2DlgItemText::OnT2Timer(UINT id) {
+ if (id == mTimerID && mPreviousString.GetLength() > 0) {
+ SetDescriptor(mPreviousString);
+ mPreviousString.Empty();
+ KillTimer(mTimerID);
+ }
}