2 // TOOLWINDOW.CPP - Tool Palette window
4 // (C) 2008 Underground Software
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 08/28/2008 Created this file
19 // Uncomment this for debugging...
21 #define DEBUGFOO // Various tool debugging...
22 #define DEBUGTP // Toolpalette debugging...
24 #include "toolwindow.h"
29 #include "res/toolpal1.xpm" // Docs say this is portable... Let's see!
32 BEGIN_EVENT_TABLE(ToolWindow, wxFrame)
33 EVT_PAINT(ToolWindow::OnPaint)
37 ToolWindow::ToolWindow(wxFrame * parent, const wxString &title, const wxPoint &pos,
38 const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style),
39 bmp(NULL), prevTool(TOOLNone)
41 bmp = new wxBitmap(toolpal1_xpm);
45 sizeTPBM.x = bmp->GetWidth(), sizeTPBM.y = bmp->GetHeight();
46 sizeStamp.x = sizeTPBM.x / 4, sizeStamp.y = sizeTPBM.y / 2;
48 SetSize(0, 0, sizeTPBM.x, sizeTPBM.y);
52 ToolWindow::~ToolWindow()
58 void ToolWindow::OnPaint(wxPaintEvent &e)
63 memDC.SelectObject(*bmp);
64 dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY);
68 //need ul corner of bitmap, ul corner of dest, width/height
69 wxPoint pt(sizeStamp.x * (prevTool & 0x03), sizeStamp.y * (prevTool >> 2));
70 dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT);
73 memDC.SelectObject(wxNullBitmap);
77 // Find which tool we're pointing at
79 ToolType ToolWindow::FindSelectedTool(void)
81 // Get mouse coords relative to the tool palette window
82 wxPoint pt = ScreenToClient(wxGetMousePosition());
84 // Divide mouse coords by the bitmap stamp size to find which one is pointed to
85 uint32 x = (uint32)pt.x / sizeStamp.x, y = (uint32)pt.y / sizeStamp.y;
87 // Preset failure into newTool, in case no new tool is selected
88 ToolType newTool = TOOLNone;
90 // NOTE: This works because x and y are UNSIGNED
92 newTool = (ToolType)((y * 4) + x);