2 /// \file ClickImage.cc
3 /// Clickable image class
7 Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "ClickImage.h"
24 //////////////////////////////////////////////////////////////////////////////
27 ClickableImage::ClickableImage(wxWindow
*parent
,
28 const wxBitmap
&image
,
32 const wxCursor
&hover
)
39 , m_event_on_up(event_on_up
)
40 , m_hover_cursor(hover
)
44 bool ClickableImage::CalculateHit(int x
, int y
)
46 return ( x
>= m_x
&& x
< (m_x
+ m_image
.GetWidth()) )
48 ( y
>= m_y
&& y
< (m_y
+ m_image
.GetHeight()) );
51 void ClickableImage::Draw(wxDC
&dc
)
53 dc
.DrawBitmap(m_image
, m_x
, m_y
, true);
56 void ClickableImage::HandleMotion(wxDC
&dc
, int x
, int y
)
58 bool focus
= CalculateHit(x
, y
);
60 if( focus
&& !m_focus
) {
62 m_parent
->SetCursor(m_hover_cursor
);
64 else if( m_focus
&& !focus
) {
65 // not in focus anymore
66 m_parent
->SetCursor(wxNullCursor
);
73 void ClickableImage::HandleDown(wxDC
&dc
, int x
, int y
)
75 if( !m_event_on_up
) {
76 m_focus
= CalculateHit(x
, y
);
80 m_parent
->SetCursor(wxNullCursor
);
84 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
,m_id
);
85 m_parent
->GetEventHandler()->ProcessEvent(event
);
90 void ClickableImage::HandleUp(wxDC
&dc
, int x
, int y
)
93 m_focus
= CalculateHit(x
, y
);
97 m_parent
->SetCursor(wxNullCursor
);
101 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
,m_id
);
102 m_parent
->GetEventHandler()->ProcessEvent(event
);