X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ftoolwindow.cpp;h=5fd774c1498430542df30b7ec84403e2afaf2041;hb=2b16243b0aa693d18ce49a071cdae73cadc37c4f;hp=453296490827ea2a41e35383e94475b3e6da21a7;hpb=4e11c12e60477f13a26c0bbad41fbd9a2b1db5d9;p=ttedit diff --git a/src/toolwindow.cpp b/src/toolwindow.cpp index 4532964..5fd774c 100755 --- a/src/toolwindow.cpp +++ b/src/toolwindow.cpp @@ -1,95 +1,89 @@ -// -// TOOLWINDOW.CPP - Tool Palette window -// by James L. Hammons -// (C) 2008 Underground Software -// -// JLH = James L. Hammons -// -// Who When What -// --- ---------- ------------------------------------------------------------- -// JLH 08/28/2008 Created this file -// - -// FIXED: -// -// STILL TO BE DONE: -// -// - -// Uncomment this for debugging... -#define DEBUG -#define DEBUGFOO // Various tool debugging... -#define DEBUGTP // Toolpalette debugging... - -#include "toolwindow.h" -#include "types.h" - -// Pixmap resources - -#include "res/toolpal1.xpm" // Docs say this is portable... Let's see! - - -BEGIN_EVENT_TABLE(ToolWindow, wxFrame) - EVT_PAINT(ToolWindow::OnPaint) -END_EVENT_TABLE() - - -ToolWindow::ToolWindow(wxFrame * parent, const wxString &title, const wxPoint &pos, - const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style), - bmp(NULL), prevTool(TOOLNone) -{ - bmp = new wxBitmap(toolpal1_xpm); - - // Set up sizes - - sizeTPBM.x = bmp->GetWidth(), sizeTPBM.y = bmp->GetHeight(); - sizeStamp.x = sizeTPBM.x / 4, sizeStamp.y = sizeTPBM.y / 2; - - SetSize(0, 0, sizeTPBM.x, sizeTPBM.y); - Show(false); -} - -ToolWindow::~ToolWindow() -{ - if (bmp) - delete bmp; -} - -void ToolWindow::OnPaint(wxPaintEvent &e) -{ - wxPaintDC dc(this); - - wxMemoryDC memDC; - memDC.SelectObject(*bmp); - dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY); - - if (prevTool != -1) - { - //need ul corner of bitmap, ul corner of dest, width/height - wxPoint pt(sizeStamp.x * (prevTool & 0x03), sizeStamp.y * (prevTool >> 2)); - dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT); - } - - memDC.SelectObject(wxNullBitmap); -} - -// -// Find which tool we're pointing at -// -ToolType ToolWindow::FindSelectedTool(void) -{ - // Get mouse coords relative to the tool palette window - wxPoint pt = ScreenToClient(wxGetMousePosition()); - - // Divide mouse coords by the bitmap stamp size to find which one is pointed to - uint32 x = (uint32)pt.x / sizeStamp.x, y = (uint32)pt.y / sizeStamp.y; - - // Preset failure into newTool, in case no new tool is selected - ToolType newTool = TOOLNone; - - // NOTE: This works because x and y are UNSIGNED - if (x < 4 && y < 2) - newTool = (ToolType)((y * 4) + x); - - return newTool; -} +// +// TOOLWINDOW.CPP - Tool Palette window +// by James L. Hammons +// (C) 2008 Underground Software +// +// JLH = James L. Hammons +// +// Who When What +// --- ---------- ------------------------------------------------------------- +// JLH 08/28/2008 Created this file +// JLH 03/11/2009 Converted from wxWidgets to Qt +// + +// FIXED: +// +// STILL TO BE DONE: +// +// + +// Uncomment this for debugging... +#define DEBUG +#define DEBUGFOO // Various tool debugging... +#define DEBUGTP // Toolpalette debugging... + +#include "toolwindow.h" +#include "types.h" + + +ToolWindow::ToolWindow(void): QWidget(NULL, Qt::Window | Qt::FramelessWindowHint), + prevTool(TOOLNone) +{ +// img = QImage(":/res/toolpal1.xpm"); + img = QImage(":/res/toolpal1.png"); + + // Set up sizes + + sizeTPBM.rx() = img.width(), sizeTPBM.ry() = img.height(); + sizeStamp.rx() = sizeTPBM.x() / 4, sizeStamp.ry() = sizeTPBM.y() / 3; + + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setVisible(false); +} + +QSize ToolWindow::sizeHint() const +{ + return QSize(sizeTPBM.x(), sizeTPBM.y()); +} + +void ToolWindow::paintEvent(QPaintEvent * event) +{ + QPainter p(this); + p.drawImage(QPoint(0, 0), img); + + if (prevTool != -1) + { + //need ul corner of bitmap, ul corner of dest, width/height + p.setCompositionMode(QPainter::RasterOp_NotSource); +// QPoint pt(sizeStamp.x() * (prevTool & 0x03), sizeStamp.y() * (prevTool >> 2)); + QPoint pt(sizeStamp.x() * (prevTool % 4), sizeStamp.y() * (prevTool / 4)); + p.drawImage(pt.x(), pt.y(), img, pt.x(), pt.y(), sizeStamp.x(), sizeStamp.y()); + } +} + +// +// Find which tool we're pointing at +// +ToolType ToolWindow::FindSelectedTool(void) +{ + // Get mouse coords relative to the tool palette window +// wxPoint pt = ScreenToClient(wxGetMousePosition()); + QPoint pt = mapFromGlobal(QCursor::pos()); +//printf("pt = %u, %u\n", pt.x(), pt.y()); + + // Divide mouse coords by the bitmap stamp size to find which one is pointed to + uint32 x = (uint32)pt.x() / sizeStamp.x(), y = (uint32)pt.y() / sizeStamp.y(); + + // Preset failure into newTool, in case no new tool is selected + ToolType newTool = TOOLNone; + + // NOTE: This works because x and y are UNSIGNED + if (x < 4 && y < 3) + newTool = (ToolType)((y * 4) + x); + + // We don't have 11 yet, so fix this if the user selected the blank space + if (newTool > 10) + newTool = TOOLNone; + + return newTool; +}