| 1 | // $Header$cxx . . $ `<file>/src/wxDynamicBitmap.cpp`/ |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2006-2007 by Guy Rutenberg * |
| 4 | * [email protected] * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the * |
| 18 | * Free Software Foundation, Inc., * |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | #include "wxDynamicBitmap.h"cxx . . $ `<file>/src/wxDynamicBitmap.h`/ |
| 23 | #include <wx/wx.h> |
| 24 | |
| 25 | #include <iostream> |
| 26 | |
| 27 | wxDynamicBitmapcxx . . $ wxDynamicBitmap#::wxDynamicBitmapcxx . . $ wxDynamicBitmap#wxDynamicBitmap(ce2e2fe9496d05c4).(wxWindowcxx . . $ wxWindow#* parent, wxWindowIDcxx . . $ wxWindowID# id, wxBitmapcxx . . $ wxBitmap# *bitmap, |
| 28 | const wxPointcxx . . $ wxPoint#& pos, const wxSizecxx . . $ wxSize#& size, |
| 29 | long style, const wxStringcxx . . $ wxString#& name) |
| 30 | { |
| 31 | wxControlcxx . . $ wxControl#::Createcxx . . $ wxControl#Create(4aa1fef7c445b1d9).(parent,id,pos,size,style,wxDefaultValidatorcxx . . $ wxDefaultValidator.,name); |
| 32 | Connectcxx . . $ wxEvtHandler#Connect(bb4f3294b37e5589).(id, wxEVT_PAINTcxx . . $ wxEVT_PAINT., wxPaintEventHandlercxx . . $ `<external>/9123237030240659982/event.h:4280:9`!(wxDynamicBitmap::OnPaint)); |
| 33 | Connectcxx . . $ wxEvtHandler#Connect(bb4f3294b37e5589).(id, wxEVT_LEFT_UPcxx . . $ wxEVT_LEFT_UP.,wxMouseEventHandlercxx . . $ `<external>/9123237030240659982/event.h:4286:9`!(wxDynamicBitmap::OnClick)); |
| 34 | m_grayscalecxx . . $ wxDynamicBitmap#m_grayscale.=false; |
| 35 | SetBitmapcxx . . $ wxDynamicBitmap#SetBitmap(5b5686b4f88e80eb).( bitmap); |
| 36 | |
| 37 | } |
| 38 | |
| 39 | void wxDynamicBitmapcxx . . $ wxDynamicBitmap#::OnPaintcxx . . $ wxDynamicBitmap#OnPaint(954efb20b042ed11).(wxPaintEventcxx . . $ wxPaintEvent#& event) |
| 40 | { |
| 41 | wxPaintDCcxx . . $ wxPaintDC# dccxx . . $ wxPaintDC#wxPaintDC(4289b2e0b1e17a99).(this); |
| 42 | PaintBitmapcxx . . $ wxDynamicBitmap#PaintBitmap(99f63e575cba0cee).(dc); |
| 43 | } |
| 44 | |
| 45 | wxBitmapcxx . . $ wxBitmap# wxDynamicBitmapcxx . . $ wxDynamicBitmap#::GetBitmapcxx . . $ wxDynamicBitmap#GetBitmap(e893204fbbabd17a).() |
| 46 | { |
| 47 | return m_bitmapcxx . . $ wxBitmap#wxBitmap(98862698a0401ee5).; |
| 48 | } |
| 49 | |
| 50 | void wxDynamicBitmapcxx . . $ wxDynamicBitmap#::SetBitmapcxx . . $ wxDynamicBitmap#SetBitmap(5b5686b4f88e80eb).( wxBitmapcxx . . $ wxBitmap# *bitmap) |
| 51 | { |
| 52 | m_bitmapcxx . . $ wxDynamicBitmap#m_bitmap. =cxx . . $ wxBitmap#`operator=`(38f6929f438e2a8). *bitmap; |
| 53 | SetGrayScalecxx . . $ wxDynamicBitmap#SetGrayScale(b45ddcbc8423892c).(m_grayscalecxx . . $ wxDynamicBitmap#m_grayscale.); |
| 54 | wxWindowcxx . . $ wxWindow#::Refreshcxx . . $ wxWindow#Refresh(e1a781ccdc106755).(); |
| 55 | wxWindowcxx . . $ wxWindow#::Updatecxx . . $ wxWindow#Update(49f6e7a06ebc5aa8).(); |
| 56 | } |
| 57 | |
| 58 | void wxDynamicBitmapcxx . . $ wxDynamicBitmap#::PaintBitmapcxx . . $ wxDynamicBitmap#PaintBitmap(99f63e575cba0cee).(wxDCcxx . . $ wxDC#& dc) |
| 59 | { |
| 60 | wxColourcxx . . $ wxColour# backgroundColour = GetBackgroundColourcxx . . $ wxColour#wxColour(c6fe1e6e9a9d4367).(); |
| 61 | if (!backgroundColour.Okcxx . . $ wxGDIObject#Ok(50ce9a9e25b4a850).()) |
| 62 | backgroundColour =cxx . . $ wxColour#`operator=`(bbf00ed33a71f598). wxSystemSettingscxx . . $ wxSystemSettings#::GetColourcxx . . $ wxSystemSettingsNative#GetColour(569b49f68c1d7e90).(wxSYS_COLOUR_3DFACEcxx . . $ wxSYS_COLOUR_3DFACE.); |
| 63 | dc.SetBrushcxx . . $ wxDC#SetBrush(7703d09f4870cffa).(wxBrushcxx . . $ wxBrush#wxBrush(800f1e3ac2d1c11b).(backgroundColour)); |
| 64 | dc.SetPencxx . . $ wxDC#SetPen(14801b85a4885f61).(wxPencxx . . $ wxPen#wxPen(29dfe2b222d7822d).(backgroundColour, 1)); |
| 65 | wxRectcxx . . $ wxRect# windowRectcxx . . $ wxRect#wxRect(68082ca517bcf30).(wxPointcxx . . $ wxPoint#wxPoint(3e454b8ccf442868).(0, 0), GetClientSizecxx . . $ wxWindowBase#GetClientSize(1760195b8cec6c4e).()); |
| 66 | |
| 67 | dc.DrawRectanglecxx . . $ wxDC#DrawRectangle(80584521abac96fa).(windowRect); |
| 68 | |
| 69 | dc.DrawBitmapcxx . . $ wxDC#DrawBitmap(a16b7703627a53d1).((m_grayscalecxx . . $ wxDynamicBitmap#m_grayscale.?m_graybitmapcxx . . $ wxDynamicBitmap#m_graybitmap.:m_bitmapcxx . . $ wxDynamicBitmap#m_bitmap.) , 0 , 0, true); |
| 70 | |
| 71 | } |
| 72 | |
| 73 | wxSizecxx . . $ wxSize# wxDynamicBitmapcxx . . $ wxDynamicBitmap#::DoGetBestSizecxx . . $ wxDynamicBitmap#DoGetBestSize(1760195b8cec6c4e).() const |
| 74 | { |
| 75 | |
| 76 | return wxSizecxx . . $ wxSize#wxSize(3e454b8ccf442868).(m_bitmapcxx . . $ wxDynamicBitmap#m_bitmap..GetWidthcxx . . $ wxBitmap#GetWidth(455f465bc33b4cdf).(),m_bitmapcxx . . $ wxDynamicBitmap#m_bitmap..GetHeightcxx . . $ wxBitmap#GetHeight(455f465bc33b4cdf).()); |
| 77 | } |
| 78 | |
| 79 | void wxDynamicBitmapcxx . . $ wxDynamicBitmap#::OnClickcxx . . $ wxDynamicBitmap#OnClick(7e6a1c70b0e99497).(wxMouseEventcxx . . $ wxMouseEvent#& event) |
| 80 | { |
| 81 | //A hack that makes propogates wxEVT_COMMAND_BUTTON_CLICKED events to the parent of this control |
| 82 | wxCommandEventcxx . . $ wxCommandEvent# neweventcxx . . $ wxCommandEvent#wxCommandEvent(3e454b8ccf442868).( wxEVT_COMMAND_BUTTON_CLICKEDcxx . . $ `<external>/9123237030240659982/event.h:4822:9`!, GetIdcxx . . $ wxWindowBase#GetId(455f465bc33b4cdf).() ); |
| 83 | newevent.SetEventObjectcxx . . $ wxEvent#SetEventObject(8b80276450f090b2).( this ); |
| 84 | GetEventHandlercxx . . $ wxWindowBase#GetEventHandler(bffaa1cdeaa34ac2).()->ProcessEventcxx . . $ wxEvtHandler#ProcessEvent(20113e99158efb0d).( newevent ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * This function repaints the widget with a grayscale version of the currently |
| 89 | * displayed picture, or repaints it with the original version depending on the |
| 90 | * value of grayscale. |
| 91 | * \param grayscale [bool] if true repaints the image with grayscale version, |
| 92 | * otherwise reverts to the original picture |
| 93 | */ |
| 94 | void wxDynamicBitmapcxx . . $ wxDynamicBitmap#::SetGrayScalecxx . . $ wxDynamicBitmap#SetGrayScale(b45ddcbc8423892c).(bool grayscale) |
| 95 | { |
| 96 | m_grayscalecxx . . $ wxDynamicBitmap#m_grayscale. = grayscale; |
| 97 | |
| 98 | //regenerate the grayscale bitmap; |
| 99 | if (grayscale) { |
| 100 | wxImagecxx . . $ wxImage# tempimagecxx . . $ wxImage#wxImage(49f6e7a06ebc5aa8).; |
| 101 | tempimage =cxx . . $ wxImage#`operator=`(dafe8c9c74ba901d). m_bitmapcxx . . $ wxDynamicBitmap#m_bitmap..ConvertToImagecxx . . $ wxBitmap#ConvertToImage(9773744de489104).(); |
| 102 | //ConvertToGrayScale(tempimage); |
| 103 | m_graybitmapcxx . . $ wxDynamicBitmap#m_graybitmap. =cxx . . $ wxBitmap#`operator=`(38f6929f438e2a8). wxBitmapcxx . . $ wxBitmap#wxBitmap(52214030be2c8edc).(tempimage.ConvertToGreyscalecxx . . $ wxImage#ConvertToGreyscale(9773744de489104).()); |
| 104 | } |
| 105 | wxWindowcxx . . $ wxWindow#::Refreshcxx . . $ wxWindow#Refresh(e1a781ccdc106755).(); |
| 106 | wxWindowcxx . . $ wxWindow#::Updatecxx . . $ wxWindow#Update(49f6e7a06ebc5aa8).(); |
| 107 | } |
| 108 | |
| 109 | void wxDynamicBitmapcxx . . $ wxDynamicBitmap#::ConvertToGrayScalecxx . . $ wxDynamicBitmap#ConvertToGrayScale(14c8f64dce9da251).(wxImagecxx . . $ wxImage#& image) const |
| 110 | { |
| 111 | double red2Gray = 0.297; |
| 112 | double green2Gray = 0.589; |
| 113 | double blue2Gray = 0.114; |
| 114 | int w = image.GetWidthcxx . . $ wxImage#GetWidth(455f465bc33b4cdf).(), h = image.GetHeightcxx . . $ wxImage#GetHeight(455f465bc33b4cdf).(); |
| 115 | unsigned char *data = image.GetDatacxx . . $ wxImage#GetData(707a43c27767d44a).(); |
| 116 | int x,y; |
| 117 | for (y = 0; y < h; y++) |
| 118 | for (x = 0; x < w; x++) |
| 119 | { |
| 120 | long pos = (y * w + x) * 3; |
| 121 | char g = (char) (data[pos]*red2Gray + |
| 122 | data[pos+1]*green2Gray + |
| 123 | data[pos+2]*blue2Gray); |
| 124 | data[pos] = data[pos+1] = data[pos+2] = g; |
| 125 | } |
| 126 | } |
| 127 |