summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemPopup.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/T2DlgItemPopup.cpp
parent37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff)
downloadt2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz
t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip
first pass of T2DLL
Diffstat (limited to 'src/T2DLL/T2DlgItemPopup.cpp')
-rw-r--r--src/T2DLL/T2DlgItemPopup.cpp169
1 files changed, 162 insertions, 7 deletions
diff --git a/src/T2DLL/T2DlgItemPopup.cpp b/src/T2DLL/T2DlgItemPopup.cpp
index 97129b7..0ace311 100644
--- a/src/T2DLL/T2DlgItemPopup.cpp
+++ b/src/T2DLL/T2DlgItemPopup.cpp
@@ -1,25 +1,180 @@
+#include "CTokenizer.h"
#include "T2DlgItemPopup.h"
-T2DlgItemPopup::T2DlgItemPopup(T2TowerDoc*, T2ImageObj*, CPalette*) {
+T2DlgItemPopup::T2DlgItemPopup(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
+ : T2DlgItem(inDoc, inImageObj, inPalette)
+ , mMenu(NULL)
+ , mMenuClicked(false)
+{
+#line 21
+ mMenu = DEBUG_NEW CMenu;
+ mMenu->CreatePopupMenu();
}
/*virtual*/ T2DlgItemPopup::~T2DlgItemPopup() {
+ delete mMenu;
}
-/*virtual*/ int T2DlgItemPopup::OnT2DlgItemCreate(CREATESTRUCTA*) {
+/*virtual*/ int T2DlgItemPopup::OnT2DlgItemCreate(CREATESTRUCT* cs) {
+ T2DlgItem::OnT2DlgItemCreate(cs);
+
+ char *buf = (char *) calloc(GetWindowTextLength() + 1, 1);
+ GetWindowText(buf, GetWindowTextLength());
+
+ if (strlen(buf) != 0 && buf[0] != '-') {
+ CTokenizer theTokenizer(buf, "|\r\n");
+ const char *text = theTokenizer.NextString();
+ int i = 0;
+
+ while (text) {
+ CString title = text;
+ i++;
+ mMenu->AppendMenuA(0, i, title);
+ text = theTokenizer.NextString();
+ }
+ }
+
+ free(buf);
+ return 0;
}
-/*virtual*/ int T2DlgItemPopup::OnT2DlgItemEraseBkgnd(CDC*) {
+/*virtual*/ BOOL T2DlgItemPopup::OnT2DlgItemEraseBkgnd(CDC* pDC) {
+#pragma var_order(pen1, rect1, rect2, pen4, i, y1, x, rect3, pen2, save, brush1, pen3, brush2, clientRect, text, y2)
+ CRect clientRect;
+ GetClientRect(clientRect);
+
+ int save = pDC->SaveDC();
+ pDC->SelectPalette(mPalette, false);
+ pDC->RealizePalette();
+
+ CRect rect1 = clientRect;
+
+ CBrush brush1, brush2;
+ CPen pen1, pen2, pen3, pen4;
+
+ if (IsWindowEnabled()) {
+ brush1.CreateSolidBrush(PALETTEINDEX(255));
+ pen3.CreatePen(PS_SOLID, 0, PALETTEINDEX(255));
+
+ if (mMenuClicked) {
+ pen1.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133));
+ pen2.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255));
+ brush2.CreateSolidBrush(PALETTERGB(179, 179, 179));
+ pen4.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255));
+ } else {
+ pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255));
+ pen2.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133));
+ brush2.CreateSolidBrush(PALETTERGB(204, 204, 204));
+ pen4.CreatePen(PS_SOLID, 0, PALETTEINDEX(255));
+ }
+ } else {
+ brush1.CreateSolidBrush(PALETTERGB(179, 179, 179));
+ pen1.CreatePen(PS_SOLID, 0, PALETTERGB(204, 204, 204));
+ pen2.CreatePen(PS_SOLID, 0, PALETTERGB(204, 204, 204));
+ brush2.CreateSolidBrush(PALETTERGB(204, 204, 204));
+ pen4.CreatePen(PS_SOLID, 0, PALETTERGB(179, 179, 179));
+ }
+
+ pDC->FrameRect(clientRect, &brush1);
+
+ rect1.DeflateRect(1, 1);
+
+ CRect rect2 = rect1;
+ rect2.left = rect2.right - 16;
+
+ pDC->SelectObject(pen1);
+ pDC->MoveTo(rect2.right - 1, rect2.top);
+ pDC->LineTo(rect2.left, rect2.top);
+ pDC->LineTo(rect2.left, rect2.bottom);
+
+ pDC->SelectObject(pen2);
+ pDC->MoveTo(rect2.right - 1, rect2.top + 1);
+ pDC->LineTo(rect2.right - 1, rect2.bottom - 1);
+ pDC->LineTo(rect2.left, rect2.bottom - 1);
+
+ rect2.DeflateRect(1, 1);
+
+ pDC->SelectObject(pen1);
+ pDC->MoveTo(rect2.right - 1, rect2.top);
+ pDC->LineTo(rect2.left, rect2.top);
+ pDC->LineTo(rect2.left, rect2.bottom);
+
+ pDC->SelectObject(pen2);
+ pDC->MoveTo(rect2.right - 1, rect2.top + 1);
+ pDC->LineTo(rect2.right - 1, rect2.bottom - 1);
+ pDC->LineTo(rect2.left, rect2.bottom - 1);
+
+ rect2.DeflateRect(1, 1);
+ pDC->FillRect(rect2, &brush2);
+
+ int x = rect2.left + (rect2.Width() - 7) / 2;
+ int y1 = rect2.top + (rect2.Height() - 10) / 2;
+ int y2 = y1 + 9;
+
+ pDC->SelectObject(pen4);
+ for (int i = 0; i < 4; i++) {
+ pDC->MoveTo(x + (4 - i) - 1, y1 + i);
+ pDC->LineTo(x + (4 + i), y1 + i);
+
+ pDC->MoveTo(x + (4 - i) - 1, y2 - i);
+ pDC->LineTo(x + (4 + i), y2 - i);
+ }
+
+ CRect rect3 = rect1;
+ rect3.right -= 16;
+
+ pDC->SelectObject(pen1);
+ pDC->MoveTo(rect3.right - 1, rect3.top);
+ pDC->LineTo(rect3.left, rect3.top);
+ pDC->LineTo(rect3.left, rect3.bottom);
+
+ pDC->SelectObject(pen2);
+ pDC->MoveTo(rect3.right - 1, rect3.top + 1);
+ pDC->LineTo(rect3.right - 1, rect3.bottom - 1);
+ pDC->LineTo(rect3.left, rect3.bottom - 1);
+
+ rect3.DeflateRect(1, 1);
+ pDC->FillRect(rect3, &brush2);
+
+ pDC->SetTextColor(PALETTEINDEX(255));
+ pDC->SetBkMode(TRANSPARENT);
+ pDC->SelectObject(mFont);
+
+ rect3.DeflateRect(3, 0);
+ CString text;
+ mMenu->GetMenuString(GetValue() - 1, text, MF_BYPOSITION);
+ pDC->DrawText(text, rect3, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
+
+ pDC->RestoreDC(save);
+ return true;
}
-/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonDown(unsigned int, CPoint) {
+/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) {
+ POINT menuPos;
+ menuPos.x = 0;
+ menuPos.y = 0;
+ ClientToScreen(&menuPos);
+
+ mMenuClicked = true;
+ Invalidate();
+
+ int tracked = mMenu->TrackPopupMenu(TPM_NONOTIFY | TPM_RETURNCMD, menuPos.x, menuPos.y, this);
+ if (tracked && tracked > 0 && tracked <= (int) mMenu->GetMenuItemCount()) {
+ SetValue(tracked);
+ Notify(GetDlgCtrlID(), 0, NULL);
+ }
+
+ mMenuClicked = false;
+ Invalidate();
}
-/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonUp(unsigned int, CPoint) {
+/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) {
}
-/*virtual*/ int T2DlgItemPopup::OnCommand(unsigned int, long) {
+/*virtual*/ BOOL T2DlgItemPopup::OnCommand(WPARAM wParam, LPARAM lParam) {
+ return true;
}
-void T2DlgItemPopup::AppendItem(const CString&) {
+void T2DlgItemPopup::AppendItem(const CString& inName) {
+ mMenu->AppendMenu(0, mMenu->GetMenuItemCount() + 1, inName);
}