2 * This file is part of ShapeFusion (Copyright 2000 Tito Dal Canton)
4 * ShapeFusion is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * ShapeFusion is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with ShapeFusion; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "BitmapView.h"
19 #include "utilities.h"
21 BEGIN_EVENT_TABLE(BitmapView, wxScrolledWindow)
22 EVT_PAINT(BitmapView::OnPaint)
23 EVT_LEFT_DOWN(BitmapView::OnDrag)
24 EVT_LEFT_UP(BitmapView::OnDrag)
25 EVT_MOTION(BitmapView::OnDrag)
26 EVT_SIZE(BitmapView::OnSize)
29 BitmapView::BitmapView(wxWindow *parent):
30 wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | wxFULL_REPAINT_ON_RESIZE),
31 mEncBmp(NULL), mColorTable(NULL), mDragging(false)
33 SetBackgroundColour(wxColour(255, 255, 255));
35 mWhiteTransparency = true;
36 mInvisiblePen.SetColour(255, 255, 255);
39 void BitmapView::OnPaint(wxPaintEvent& e)
41 wxPaintDC tempdc(this);
44 GetVirtualSize(&vw, &vh);
46 GetClientSize(&cw, &ch);
47 tempdc.SetPen(mInvisiblePen);
48 if (mEncBmp != NULL && mColorTable != NULL)
49 tempdc.DrawBitmap(mDecBmp, vw/2 - mDecBmp.GetWidth()/2, vh/2 - mDecBmp.GetHeight()/2);
52 // handle mouse drag (pan view)
53 void BitmapView::OnDrag(wxMouseEvent &e)
57 int scroll_x, scroll_y;
59 GetViewStart(&scroll_x, &scroll_y);
61 mDragStartX = e.GetPosition().x + scroll_x;
62 mDragStartY = e.GetPosition().y + scroll_y;
63 } else if (e.Dragging() && mDragging) {
65 int dx = mDragStartX - e.GetPosition().x,
66 dy = mDragStartY - e.GetPosition().y;
69 } else if (e.ButtonUp()) {
75 void BitmapView::OnSize(wxSizeEvent &e)
78 vw = (mEncBmp == NULL) ? 0 : mEncBmp->Width(),
79 vh = (mEncBmp == NULL) ? 0 : mEncBmp->Height();
81 GetClientSize(&cw, &ch);
86 SetVirtualSize(vw, vh);
89 void BitmapView::SetTranspPixelsDisplay(bool show)
91 mWhiteTransparency = show;
92 if (mEncBmp != NULL && mEncBmp->Pixels() != NULL && mColorTable != NULL)
93 mDecBmp = wxBitmap(ShapesBitmapToImage(mEncBmp, mColorTable, mWhiteTransparency));
97 // add a new ShapesBitmap to the thumbnail list
98 void BitmapView::SetBitmap(ShapesBitmap *bp)
101 if (mEncBmp != NULL) {
102 if (mEncBmp->Pixels() != NULL) {
105 vw = mEncBmp->Width(),
106 vh = mEncBmp->Height();
108 GetClientSize(&cw, &ch);
113 SetVirtualSize(vw, vh);
115 if (mColorTable != NULL)
116 mDecBmp = wxBitmap(ShapesBitmapToImage(mEncBmp, mColorTable, mWhiteTransparency));
119 wxLogError(wxT("[BitmapView] Addes a bitmap with NULL pixels"));
120 SetVirtualSize(0, 0);
123 SetVirtualSize(0, 0);
127 ShapesBitmap *BitmapView::GetBitmap(void) const
132 // call this before SettingBitmap!
133 void BitmapView::SetColorTable(ShapesColorTable *ct)
136 if (mEncBmp != NULL && mEncBmp->Pixels() != NULL && mColorTable != NULL)
137 mDecBmp = wxBitmap(ShapesBitmapToImage(mEncBmp, mColorTable, mWhiteTransparency));