| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: bmpshape.cpp |
| 3 | // Purpose: Bitmap shape class |
| 4 | // Author: Julian Smart |
| 5 | // Modified by: |
| 6 | // Created: 12/07/98 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Julian Smart |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // For compilers that support precompilation, includes "wx.h". |
| 13 | #include "wx/wxprec.h" |
| 14 | |
| 15 | #ifdef __BORLANDC__ |
| 16 | #pragma hdrstop |
| 17 | #endif |
| 18 | |
| 19 | #ifndef WX_PRECOMP |
| 20 | #include "wx/wx.h" |
| 21 | #endif |
| 22 | |
| 23 | #if wxUSE_PROLOGIO |
| 24 | #include "wx/deprecated/wxexpr.h" |
| 25 | #endif |
| 26 | |
| 27 | #include "wx/ogl/ogl.h" |
| 28 | |
| 29 | |
| 30 | /* |
| 31 | * Bitmap object |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapShape, wxRectangleShape) |
| 36 | |
| 37 | wxBitmapShape::wxBitmapShape():wxRectangleShape(100.0, 50.0) |
| 38 | { |
| 39 | m_filename = wxEmptyString; |
| 40 | } |
| 41 | |
| 42 | wxBitmapShape::~wxBitmapShape() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void wxBitmapShape::OnDraw(wxDC& dc) |
| 47 | { |
| 48 | if (!m_bitmap.Ok()) |
| 49 | return; |
| 50 | |
| 51 | int x, y; |
| 52 | x = WXROUND(m_xpos - m_bitmap.GetWidth() / 2.0); |
| 53 | y = WXROUND(m_ypos - m_bitmap.GetHeight() / 2.0); |
| 54 | dc.DrawBitmap(m_bitmap, x, y, true); |
| 55 | } |
| 56 | |
| 57 | void wxBitmapShape::SetSize(double w, double h, bool WXUNUSED(recursive)) |
| 58 | { |
| 59 | if (m_bitmap.Ok()) |
| 60 | { |
| 61 | w = m_bitmap.GetWidth(); |
| 62 | h = m_bitmap.GetHeight(); |
| 63 | } |
| 64 | |
| 65 | SetAttachmentSize(w, h); |
| 66 | |
| 67 | m_width = w; |
| 68 | m_height = h; |
| 69 | SetDefaultRegionSize(); |
| 70 | } |
| 71 | |
| 72 | #if wxUSE_PROLOGIO |
| 73 | void wxBitmapShape::WriteAttributes(wxExpr *clause) |
| 74 | { |
| 75 | // Can't really save the bitmap; so instantiate the bitmap |
| 76 | // at a higher level in the application, from a symbol library. |
| 77 | wxRectangleShape::WriteAttributes(clause); |
| 78 | clause->AddAttributeValueString(_T("filename"), m_filename); |
| 79 | } |
| 80 | |
| 81 | void wxBitmapShape::ReadAttributes(wxExpr *clause) |
| 82 | { |
| 83 | wxRectangleShape::ReadAttributes(clause); |
| 84 | clause->GetAttributeValue(_T("filename"), m_filename); |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | // Does the copying for this object |
| 89 | void wxBitmapShape::Copy(wxShape& copy) |
| 90 | { |
| 91 | wxRectangleShape::Copy(copy); |
| 92 | |
| 93 | wxASSERT( copy.IsKindOf(CLASSINFO(wxBitmapShape)) ) ; |
| 94 | |
| 95 | wxBitmapShape& bitmapCopy = (wxBitmapShape&) copy; |
| 96 | |
| 97 | bitmapCopy.m_bitmap = m_bitmap; |
| 98 | bitmapCopy.SetFilename(m_filename); |
| 99 | } |
| 100 | |
| 101 | void wxBitmapShape::SetBitmap(const wxBitmap& bm) |
| 102 | { |
| 103 | m_bitmap = bm; |
| 104 | if (m_bitmap.Ok()) |
| 105 | SetSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()); |
| 106 | } |
| 107 | |
| 108 | |