Widget class that shows thumbnails images. More...
#include <wxImageBrowserWdg.h>
Public Member Functions | |
wxImageBrowserWdg (wxWindow *parent, wxWindowID id=-1, int sx=100, int sy=100, int gap=10, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxScrolledWindowStyle, const wxString &name=wxPanelNameStr) | |
void | SetVolume (unsigned short ***volume, wxArrayString &names, int width, int height, int depth, int min, int max) |
void | SetScaleX (int sx) |
void | SetScaleY (int sy) |
void | SetGap (int gap) |
int | GetScaleX () |
int | GetScaleY () |
int | GetGap () |
int | GetFirst () |
int | GetLast () |
void | GetSizeParameters (int *n, int *c, int *r) |
void | OnDraw (wxDC &dc) |
void | OnSize (wxSizeEvent &event) |
void | OnMouseLeftClick (wxMouseEvent &event) |
void | OnMouseRightClick (wxMouseEvent &event) |
Private Member Functions | |
int | GetIndexClicked (wxMouseEvent &event) |
DECLARE_EVENT_TABLE () | |
Private Attributes | |
wxImageList | _ima_list |
wxArrayString | _nrs_list |
int | _sx |
int | _sy |
int | _gap |
int | _first_selected |
int | _last_selected |
Widget class that shows thumbnails images.
Definition at line 13 of file wxImageBrowserWdg.h.
wxImageBrowserWdg::wxImageBrowserWdg | ( | wxWindow * | parent, | |
wxWindowID | id = -1 , |
|||
int | sx = 100 , |
|||
int | sy = 100 , |
|||
int | gap = 10 , |
|||
const wxPoint & | pos = wxDefaultPosition , |
|||
const wxSize & | size = wxDefaultSize , |
|||
long | style = wxScrolledWindowStyle , |
|||
const wxString & | name = wxPanelNameStr | |||
) |
Definition at line 14 of file wxImageBrowserWdg.cxx.
00025 : wxScrolledWindow( parent, id, pos, size, style, name ) 00026 { 00027 _sx = sx; 00028 _sy = sy; 00029 _gap = gap; 00030 _first_selected = -1; 00031 _last_selected = -1; 00032 _ima_list.RemoveAll( ); 00033 _ima_list.Create( _sx, _sy ); 00034 _nrs_list.Clear( ); 00035 00036 }
wxImageBrowserWdg::DECLARE_EVENT_TABLE | ( | ) | [private] |
int wxImageBrowserWdg::GetFirst | ( | ) |
Definition at line 132 of file wxImageBrowserWdg.cxx.
References _first_selected, _last_selected, and GTM_MIN.
00133 { 00134 return( GTM_MIN( _first_selected, _last_selected ) ); 00135 00136 }
int wxImageBrowserWdg::GetGap | ( | ) |
Definition at line 126 of file wxImageBrowserWdg.cxx.
References _gap.
00127 { 00128 return( _gap ); 00129 00130 }
int wxImageBrowserWdg::GetIndexClicked | ( | wxMouseEvent & | event | ) | [private] |
Definition at line 206 of file wxImageBrowserWdg.cxx.
References _gap, _sx, _sy, and GetSizeParameters().
Referenced by OnMouseLeftClick(), and OnMouseRightClick().
00207 { 00208 double re; 00209 int x, y, n, c, r, i; 00210 wxClientDC dc( this ); 00211 this->PrepareDC( dc ); 00212 wxPoint pos = event.GetLogicalPosition( dc ); 00213 00214 this->GetSizeParameters( &n, &c, &r ); 00215 00216 // Image index calculation (Help!!, Mr. wizard!) 00217 x = -1; 00218 re = ( double )( pos.x ) / ( double )( _gap + _sx ); 00219 if( ( re - floor( re ) ) >= ( ( double )( _gap ) / ( double )( _gap + _sx ) ) ) x = ( int )floor( re ); 00220 x = ( x >= 0 && x < c )? x: -1; 00221 y = -1; 00222 re = ( double )( pos.y ) / ( double )( _gap + _sy ); 00223 if( ( re - floor( re ) ) >= ( ( double )( _gap ) / ( double )( _gap + _sy ) ) ) y = ( int )floor( re ); 00224 y = ( y >= 0 && y < r )? y: -1; 00225 i = ( x != -1 && y != -1 )? x + ( y * c ): -1; 00226 return( ( i < n )? i: -1 ); 00227 00228 }
int wxImageBrowserWdg::GetLast | ( | ) |
Definition at line 138 of file wxImageBrowserWdg.cxx.
References _first_selected, _last_selected, and GTM_MAX.
00139 { 00140 return( GTM_MAX( _first_selected, _last_selected ) ); 00141 00142 }
int wxImageBrowserWdg::GetScaleX | ( | ) |
Definition at line 114 of file wxImageBrowserWdg.cxx.
References _sx.
00115 { 00116 return( _sx ); 00117 00118 }
int wxImageBrowserWdg::GetScaleY | ( | ) |
Definition at line 120 of file wxImageBrowserWdg.cxx.
References _sy.
00121 { 00122 return( _sy ); 00123 00124 }
void wxImageBrowserWdg::GetSizeParameters | ( | int * | n, | |
int * | c, | |||
int * | r | |||
) |
Definition at line 144 of file wxImageBrowserWdg.cxx.
References _gap, _ima_list, and _sx.
Referenced by GetIndexClicked(), OnDraw(), and OnSize().
00145 { 00146 wxSize sz = this->GetClientSize( ); 00147 00148 *n = _ima_list.GetImageCount( ); 00149 *c = ( int )floor( ( double )( sz.GetWidth( ) ) / ( double )( _gap + _sx ) ); 00150 *c = ( *c <= 0 )? 1: *c; 00151 *r = ( int )ceil( ( double )( *n ) / ( double )( *c ) ); 00152 00153 }
void wxImageBrowserWdg::OnDraw | ( | wxDC & | dc | ) |
Definition at line 155 of file wxImageBrowserWdg.cxx.
References _first_selected, _gap, _ima_list, _last_selected, _nrs_list, _sx, _sy, and GetSizeParameters().
00156 { 00157 int r, c, i, x, y, n, rt; 00158 wxSize sz = this->GetClientSize( ); 00159 00160 dc.SetTextForeground( wxColour( 255, 255, 0 ) ); 00161 dc.SetBrush( *wxTRANSPARENT_BRUSH ); 00162 00163 this->GetSizeParameters( &n, &c, &r ); 00164 for( i = 0; i < n; i++ ) 00165 { 00166 rt = ( int )floor( ( double )i / ( double )c ); 00167 x = ( _sx * ( i % c ) ) + ( ( ( i % c ) + 1 ) * _gap ); 00168 y = ( _sy * ( rt % r ) ) + ( ( ( rt % r ) + 1 ) * _gap ); 00169 _ima_list.Draw( i, dc, x, y, wxIMAGELIST_DRAW_NORMAL, true ); 00170 dc.DrawText( _nrs_list[ i ], x, y ); 00171 if( _first_selected == i && _last_selected != i ) 00172 { 00173 dc.SetPen( *wxRED_PEN ); 00174 dc.DrawRectangle( x - ( _gap / 2 ), y - ( _gap / 2 ), _sx + _gap, _sy + _gap ); 00175 00176 } 00177 else if( _first_selected != i && _last_selected == i ) 00178 { 00179 dc.SetPen( *wxGREEN_PEN ); 00180 dc.DrawRectangle( x - ( _gap / 2 ), y - ( _gap / 2 ), _sx + _gap, _sy + _gap ); 00181 00182 } 00183 else if( _first_selected == i && _last_selected == i ) 00184 { 00185 dc.SetPen( *wxCYAN_PEN ); 00186 dc.DrawRectangle( x - ( _gap / 2 ), y - ( _gap / 2 ), _sx + _gap, _sy + _gap ); 00187 00188 } // fi 00189 00190 } // rof 00191 00192 }
void wxImageBrowserWdg::OnMouseLeftClick | ( | wxMouseEvent & | event | ) |
Definition at line 230 of file wxImageBrowserWdg.cxx.
References _first_selected, and GetIndexClicked().
00231 { 00232 // Select! 00233 _first_selected = this->GetIndexClicked( event ); 00234 00235 // Drawing 00236 this->Refresh( ); 00237 00238 }
void wxImageBrowserWdg::OnMouseRightClick | ( | wxMouseEvent & | event | ) |
Definition at line 240 of file wxImageBrowserWdg.cxx.
References _last_selected, and GetIndexClicked().
00241 { 00242 // Select! 00243 _last_selected = this->GetIndexClicked( event ); 00244 00245 // Drawing 00246 this->Refresh( ); 00247 00248 }
void wxImageBrowserWdg::OnSize | ( | wxSizeEvent & | event | ) |
Definition at line 194 of file wxImageBrowserWdg.cxx.
References _gap, _sx, _sy, and GetSizeParameters().
Referenced by SetVolume().
00195 { 00196 int r, c, n; 00197 wxSize sz = this->GetClientSize( ); 00198 00199 this->GetSizeParameters( &n, &c, &r ); 00200 00201 // Scroll bars 00202 this->SetScrollbars( _sx + _gap, _sy + ( _gap * 2 ), c, r ); 00203 00204 }
void wxImageBrowserWdg::SetGap | ( | int | gap | ) |
Definition at line 108 of file wxImageBrowserWdg.cxx.
References _gap.
00109 { 00110 _gap = gap; 00111 00112 }
void wxImageBrowserWdg::SetScaleX | ( | int | sx | ) |
Definition at line 96 of file wxImageBrowserWdg.cxx.
References _sx.
00097 { 00098 _sx = sx; 00099 00100 }
void wxImageBrowserWdg::SetScaleY | ( | int | sy | ) |
Definition at line 102 of file wxImageBrowserWdg.cxx.
References _sy.
00103 { 00104 _sy = sy; 00105 00106 }
void wxImageBrowserWdg::SetVolume | ( | unsigned short *** | volume, | |
wxArrayString & | names, | |||
int | width, | |||
int | height, | |||
int | depth, | |||
int | min, | |||
int | max | |||
) |
Definition at line 38 of file wxImageBrowserWdg.cxx.
References _ima_list, _nrs_list, _sx, _sy, and OnSize().
00047 { 00048 wxImage tmpI; 00049 unsigned char value; 00050 unsigned char* data; //pointeur sur mon image 00051 // int i, j, k; 00052 00053 tmpI.Create( width, height ); 00054 _nrs_list = names; 00055 00056 // Canvas creation 00057 _ima_list.RemoveAll( ); 00058 _ima_list.Create( _sx, _sy ); 00059 00060 for( int k = 0; k < depth; k++ ) 00061 { 00062 00063 data = tmpI.GetData(); 00064 data += 3*width*height; 00065 // unsigned short** voltemp = volume[k]; 00066 for ( int i = 0; i < width; i++ ) 00067 { 00068 for ( int j = 0; j < height; j++ ) 00069 { 00070 value = ( unsigned char )( 0x00ff*( volume[ k ][ i ][ height - j - 1] - min) / (max - min)); 00071 data -= 3; 00072 data[0] = value; 00073 data[1] = value; 00074 data[2] = value; 00075 //memset( data, value, 3); 00076 } //rof 00077 } //rof 00078 00079 //image is set, add it to the list 00080 //another image is created so allocation is not a problem 00081 _ima_list.Add( wxBitmap( tmpI.Scale( _sx, _sy ) ) ); 00082 } // rof 00083 00084 //FIXME: 00085 #ifdef __WXMSW__ 00086 this->OnSize( wxSizeEvent( ) ); 00087 #else 00088 wxSizeEvent myevent(wxSize(-1, -1), this->GetId()); 00089 this->OnSize(myevent); 00090 this->Show(true); 00091 #endif 00092 }
int wxImageBrowserWdg::_first_selected [private] |
Definition at line 67 of file wxImageBrowserWdg.h.
Referenced by GetFirst(), GetLast(), OnDraw(), and OnMouseLeftClick().
int wxImageBrowserWdg::_gap [private] |
Definition at line 66 of file wxImageBrowserWdg.h.
Referenced by GetGap(), GetIndexClicked(), GetSizeParameters(), OnDraw(), OnSize(), and SetGap().
wxImageList wxImageBrowserWdg::_ima_list [private] |
Definition at line 62 of file wxImageBrowserWdg.h.
Referenced by GetSizeParameters(), OnDraw(), and SetVolume().
int wxImageBrowserWdg::_last_selected [private] |
Definition at line 68 of file wxImageBrowserWdg.h.
Referenced by GetFirst(), GetLast(), OnDraw(), and OnMouseRightClick().
wxArrayString wxImageBrowserWdg::_nrs_list [private] |
Definition at line 63 of file wxImageBrowserWdg.h.
Referenced by OnDraw(), and SetVolume().
int wxImageBrowserWdg::_sx [private] |
Definition at line 64 of file wxImageBrowserWdg.h.
Referenced by GetIndexClicked(), GetScaleX(), GetSizeParameters(), OnDraw(), OnSize(), SetScaleX(), and SetVolume().
int wxImageBrowserWdg::_sy [private] |
Definition at line 65 of file wxImageBrowserWdg.h.
Referenced by GetIndexClicked(), GetScaleY(), OnDraw(), OnSize(), SetScaleY(), and SetVolume().