]> Shamusworld >> Repos - ttedit/blob - src/toolwindow.cpp
80f90e429a5edf8b1ff0c14841808cfc2325396a
[ttedit] / src / toolwindow.cpp
1 //
2 // TOOLWINDOW.CPP - Tool Palette window
3 // by James L. Hammons
4 // (C) 2008 Underground Software
5 //
6 // JLH = James L. Hammons <jlhamm@acm.org>
7 //
8 // Who  When        What
9 // ---  ----------  -------------------------------------------------------------
10 // JLH  08/28/2008  Created this file
11 //
12
13 // FIXED:
14 //
15 // STILL TO BE DONE:
16 //
17 //
18
19 // Uncomment this for debugging...
20 #define DEBUG
21 #define DEBUGFOO            // Various tool debugging...
22 #define DEBUGTP                         // Toolpalette debugging...
23
24 #include "toolwindow.h"
25 #include "types.h"
26
27 // Pixmap resources
28
29 #include "res/toolpal1.xpm"                                             // Docs say this is portable... Let's see!
30
31
32 BEGIN_EVENT_TABLE(ToolWindow, wxFrame)
33         EVT_PAINT(ToolWindow::OnPaint)
34 END_EVENT_TABLE()
35
36
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)
40 {
41         bmp = new wxBitmap(toolpal1_xpm);
42
43         // Set up sizes
44
45         sizeTPBM.x = bmp->GetWidth(), sizeTPBM.y = bmp->GetHeight();
46         sizeStamp.x = sizeTPBM.x / 4, sizeStamp.y = sizeTPBM.y / 2;
47
48         SetSize(0, 0, sizeTPBM.x, sizeTPBM.y);
49         Show(false);
50 }
51
52 ToolWindow::~ToolWindow()
53 {
54         if (bmp)
55                 delete bmp;
56 }
57
58 void ToolWindow::OnPaint(wxPaintEvent &e)
59 {
60         wxPaintDC dc(this);
61
62         wxMemoryDC memDC;
63         memDC.SelectObject(*bmp);
64         dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY);
65
66         if (prevTool != -1)
67         {
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);
71         }
72
73         memDC.SelectObject(wxNullBitmap);
74 }
75
76 //
77 // Find which tool we're pointing at
78 //
79 ToolType ToolWindow::FindSelectedTool(void)
80 {
81         // Get mouse coords relative to the tool palette window
82         wxPoint pt = ScreenToClient(wxGetMousePosition());
83
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;
86
87         // Preset failure into newTool, in case no new tool is selected
88         ToolType newTool = TOOLNone;
89
90         // NOTE: This works because x and y are UNSIGNED
91         if (x < 4 && y < 2)
92                 newTool = (ToolType)((y * 4) + x);
93
94         return newTool;
95 }