summaryrefslogtreecommitdiff
path: root/src/Plugins/ToolPalette/DefaultToolPalette/ToolPaletteItem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugins/ToolPalette/DefaultToolPalette/ToolPaletteItem.cpp')
-rw-r--r--src/Plugins/ToolPalette/DefaultToolPalette/ToolPaletteItem.cpp262
1 files changed, 262 insertions, 0 deletions
diff --git a/src/Plugins/ToolPalette/DefaultToolPalette/ToolPaletteItem.cpp b/src/Plugins/ToolPalette/DefaultToolPalette/ToolPaletteItem.cpp
index ad675b8..f4993fc 100644
--- a/src/Plugins/ToolPalette/DefaultToolPalette/ToolPaletteItem.cpp
+++ b/src/Plugins/ToolPalette/DefaultToolPalette/ToolPaletteItem.cpp
@@ -1,7 +1,269 @@
+#include "StdAfx.h"
+#include "ToolPalette.h"
#include "ToolPaletteItem.h"
+#include "../../../T2DLL/T2ImageObj.h"
+#include "../../../T2DLL/T2ToolWindow.h"
+#include "../../../T2DLL/T2WorldDef.h"
+#include "../../../T2TowerDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
+
+ToolPaletteItem::ToolPaletteItem() {
+}
+
+ToolPaletteItem::ToolPaletteItem(T2TowerDoc *inDoc, int inMode) {
+ ToolPaletteItem();
+
+ mIcon = NULL;
+ mMode = inMode;
+ mDocument = inDoc;
+ mPalette = inDoc->mWorldDef->GetPalette();
+ mStatus = 0;
+ mScrollPos = 0;
+ mScrollRange = 0;
+ mOption = 0;
+
+ if (inMode == kTPIMode2)
+ mStatus = 22;
+}
+
+/*virtual*/ ToolPaletteItem::~ToolPaletteItem() {
+}
+
+BEGIN_MESSAGE_MAP(ToolPaletteItem, CWnd)
+ //{{AFX_MSG_MAP(ToolPaletteItem)
+ ON_WM_ERASEBKGND()
+ ON_WM_LBUTTONDOWN()
+ ON_WM_LBUTTONUP()
+ ON_WM_MOUSEMOVE()
+ //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/*virtual*/ int ToolPaletteItem::GetScrollPos() {
+ return mScrollPos;
+}
+
+/*virtual*/ void ToolPaletteItem::SetScrollRange(int inRange) {
+ if (mScrollRange != inRange) {
+ mScrollRange = inRange;
+ SetScrollStatus(false, false);
+ if (mScrollPos > mScrollRange)
+ mScrollPos = mScrollRange;
+
+ ((ToolPalette *) GetParent())->ItemCallbackDown(this);
+ }
+}
+
+/*virtual*/ void ToolPaletteItem::SetScrollPos(int inPos) {
+ if (mScrollPos != inPos)
+ mScrollPos = inPos;
+}
+
+void ToolPaletteItem::SetScrollStatus(BOOL inLeftPressed, BOOL inRightPressed) {
+ int theStatusL = inLeftPressed ? 1 : 0;
+ int theStatusR = inRightPressed ? 1 : 0;
+ if (mScrollPos == 0)
+ theStatusL = 2;
+ if (mScrollPos == mScrollRange)
+ theStatusR = 2;
+ mStatus = theStatusL * 10 + theStatusR;
+ InvalidateRect(NULL);
+}
+
+/*virtual*/ void ToolPaletteItem::SetStatus(int inStatus) {
+ mStatus = inStatus;
+ InvalidateRect(NULL);
+}
+
+/*virtual*/ int ToolPaletteItem::GetOption() {
+ return mOption;
+}
+
+/*virtual*/ void ToolPaletteItem::SetOption(int inOption) {
+ mOption = inOption;
+}
+
+/*virtual*/ void ToolPaletteItem::SetIcon(T2ToolIconItem *inItem) {
+ mIcon = inItem;
+ InvalidateRect(NULL);
+}
+
+/*virtual*/ void ToolPaletteItem::SetText(const char *inText) {
+ SetWindowText(inText);
+}
+
+/*virtual*/ int ToolPaletteItem::GetMode() {
+ return mMode;
+}
+
+/*virtual*/ T2ToolIconItem *ToolPaletteItem::GetIcon() {
+ return mIcon;
+}
+
+BOOL ToolPaletteItem::OnEraseBkgnd(CDC *pDC) {
+ CRect clientRect;
+ GetClientRect(clientRect);
+
+ int save = pDC->SaveDC();
+ pDC->SelectPalette(mPalette, false);
+ pDC->RealizePalette();
+
+ CBrush brush;
+ CPen pen;
+ CFont font;
+
+ if (mMode == kTPIMode1 && mIcon->mName != "") {
+ int pattern = mIcon->mValiation * 10;
+ if (mIcon->m30) {
+ if (mIcon->mEnableCount > 0)
+ pattern += 2;
+ else
+ pattern += mIcon->m24 ? 1 : 0;
+ } else {
+ pattern += 2;
+ }
+
+ int index = mDocument->mWorldDef->m1D0->FindObject(mIcon->mName, pattern);
+ if (index < 0) {
+ if (mIcon->m30) {
+ if (mIcon->mEnableCount > 0) {
+ pattern -= 2;
+ index = mDocument->mWorldDef->m1D0->FindObject(mIcon->mName, pattern);
+ }
+ } else {
+ pattern -= 2;
+ index = mDocument->mWorldDef->m1D0->FindObject(mIcon->mName, pattern);
+ }
+ }
+
+#line 172
+ _ASSERT(index >= 0);
+
+ mDocument->mWorldDef->m1D0->DrawObject(pDC, index, clientRect);
+
+ } else if (mMode == kTPIMode0) {
+ brush.CreateSolidBrush(PALETTERGB(255, 255, 255));
+ pen.CreateStockObject(BLACK_PEN);
+
+ pDC->SelectObject(brush);
+ pDC->SelectObject(pen);
+ pDC->Rectangle(clientRect);
+
+ CString text;
+ GetWindowText(text);
+
+ int currWidth, width;
+ currWidth = width = clientRect.Width();
+
+ unsigned int textLen = strlen(text);
+ if (textLen > 8)
+ currWidth /= textLen;
+ else
+ currWidth = 7;
+
+ currWidth = -currWidth;
+
+ CRect theRect;
+ BOOL isWidthFinish = false;
+ while (!isWidthFinish) {
+ theRect = clientRect;
+ theRect.top += 1;
+ theRect.left += 1;
+ theRect.bottom -= 1;
+ theRect.right -= 1;
+
+ font.CreateFont(-15, currWidth, 0, 0, FW_DONTCARE, false, false, false, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E");
+ pDC->SelectObject(font);
+ pDC->SetTextColor(RGB(0, 0, 0));
+ pDC->SetBkMode(TRANSPARENT);
+ pDC->DrawText(text, theRect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
+ if (width >= theRect.Width())
+ isWidthFinish = true;
+ else
+ currWidth++;
+ }
+
+ int textWidth = theRect.Width();
+ int textHeight = theRect.Height();
+
+ TEXTMETRIC textMetric;
+ pDC->GetTextMetrics(&textMetric);
+
+ CPoint textCenterPt = clientRect.CenterPoint();
+ theRect.top = textCenterPt.y - textHeight / 2;
+ theRect.bottom = theRect.top + textHeight;
+ theRect.left = textCenterPt.x - textWidth / 2;
+ theRect.right = theRect.left + textWidth;
+
+ pDC->DrawText(text, theRect, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX);
+ } else if (mMode == kTPIMode2) {
+ T2ImageObj *theImageObj = ((ToolPalette *) GetParent())->mImageObj;
+ int index = theImageObj->FindObject("ScrollButton", mStatus);
+ theImageObj->DrawObject(pDC, index, clientRect);
+ } else {
+ brush.CreateSolidBrush(PALETTERGB(255, 255, 255));
+ pen.CreateStockObject(BLACK_PEN);
+
+ pDC->SelectObject(brush);
+ pDC->SelectObject(pen);
+ pDC->Rectangle(clientRect);
+ }
+
+ pDC->RestoreDC(save);
+ return true;
+}
+
+void ToolPaletteItem::OnLButtonDown(UINT nFlags, CPoint point) {
+ SetCapture();
+
+ switch (mMode) {
+ case kTPIMode1:
+ ((ToolPalette *) GetParent())->ItemCallbackDown(this);
+ break;
+ case kTPIMode2:
+ if (point.x < 38)
+ SetScrollStatus(true, false);
+ else
+ SetScrollStatus(false, true);
+ break;
+ }
+}
+
+void ToolPaletteItem::OnLButtonUp(UINT nFlags, CPoint point) {
+ if (mMode == kTPIMode1)
+ ((ToolPalette *) GetParent())->ItemCallbackUp(this);
+
+ if (mMode == kTPIMode2) {
+ BOOL changed = false;
+ if (point.x < 38) {
+ if (mScrollPos != 0) {
+ mScrollPos--;
+ changed = true;
+ }
+ } else {
+ if (mScrollPos < mScrollRange) {
+ mScrollPos++;
+ changed = true;
+ }
+ }
+
+ if (changed)
+ ((ToolPalette *) GetParent())->UpdateScroll(this);
+
+ SetScrollStatus(false, false);
+ }
+
+ if (::GetCapture() == m_hWnd)
+ ReleaseCapture();
+}
+
+void ToolPaletteItem::OnMouseMove(UINT nFlags, CPoint point) {
+ CWinApp *app = AfxGetApp();
+ HCURSOR cursorH = app->LoadStandardCursor(IDC_ARROW);
+ if (cursorH)
+ SetCursor(cursorH);
+}