]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/ogl/bmpshape.cpp
Added wxFileHistory demo
[wxWidgets.git] / contrib / src / ogl / bmpshape.cpp
CommitLineData
1fc25a89
JS
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#ifdef __GNUG__
13#pragma implementation "bmpshape.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
92a19c2e 17#include "wx/wxprec.h"
1fc25a89
JS
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <wx/wx.h>
25#endif
26
27#include <wx/wxexpr.h>
28
29#include <wx/ogl/basic.h>
30#include <wx/ogl/basicp.h>
31#include <wx/ogl/canvas.h>
32#include <wx/ogl/bmpshape.h>
33#include <wx/ogl/misc.h>
34
35/*
36 * Bitmap object
37 *
38 */
39
40IMPLEMENT_DYNAMIC_CLASS(wxBitmapShape, wxShape)
41
42wxBitmapShape::wxBitmapShape():wxRectangleShape(100.0, 50.0)
43{
44 m_filename = "";
45}
46
47wxBitmapShape::~wxBitmapShape()
48{
49}
50
51void wxBitmapShape::OnDraw(wxDC& dc)
52{
53 if (!m_bitmap.Ok())
54 return;
55
56 wxMemoryDC tempDC;
57 tempDC.SelectObject(m_bitmap);
58 double x, y;
59 x = WXROUND(m_xpos - m_bitmap.GetWidth() / 2.0);
60 y = WXROUND(m_ypos - m_bitmap.GetHeight() / 2.0);
61 dc.Blit((long) x, (long) y, m_bitmap.GetWidth(), m_bitmap.GetHeight(), &tempDC, 0, 0);
62}
63
64void wxBitmapShape::SetSize(double w, double h, bool recursive)
65{
66 if (m_bitmap.Ok())
67 {
68 w = m_bitmap.GetWidth();
69 h = m_bitmap.GetHeight();
70 }
71
72 SetAttachmentSize(w, h);
73
74 m_width = w;
75 m_height = h;
76 SetDefaultRegionSize();
77}
78
79#ifdef PROLOGIO
80void wxBitmapShape::WriteAttributes(wxExpr *clause)
81{
82 // Can't really save the bitmap; so instantiate the bitmap
83 // at a higher level in the application, from a symbol library.
84 wxRectangleShape::WriteAttributes(clause);
85 clause->AddAttributeValueString("filename", m_filename);
86}
87
88void wxBitmapShape::ReadAttributes(wxExpr *clause)
89{
90 wxRectangleShape::ReadAttributes(clause);
91 clause->GetAttributeValue("filename", m_filename);
92}
93#endif
94
95// Does the copying for this object
96void wxBitmapShape::Copy(wxShape& copy)
97{
98 wxRectangleShape::Copy(copy);
99
100 wxASSERT( copy.IsKindOf(CLASSINFO(wxBitmapShape)) ) ;
101
102 wxBitmapShape& bitmapCopy = (wxBitmapShape&) copy;
103
104 bitmapCopy.m_bitmap = m_bitmap;
105 bitmapCopy.SetFilename(m_filename);
106}
107
108void wxBitmapShape::SetBitmap(const wxBitmap& bm)
109{
110 m_bitmap = bm;
111 if (m_bitmap.Ok())
112 SetSize(m_bitmap.GetWidth(), m_bitmap.GetHeight());
113}
114
115