Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleSizing.cpp

Example for usage ContextWX, GLProjections and Scenes

, SceneOpenSceneGraph

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleSizing.cpp
@relates GLProjectionParametersPerspective, SceneOpenSceneGraph
@brief Example for usage ContextWX, GLProjections and Scenes
@ingroup g_examples
@author MIP
*/
#include <Base/Common/BIASpragmaStart.hh>
#include <wx/wx.h>
#include <wx/aboutdlg.h>
#include <wx/artprov.h>
#include <wx/filename.h>
#include <Base/Common/BIASpragmaEnd.hh>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Common/FileHandling.hh>
#include <Gui/StringConv.hh>
using namespace BIAS;
using namespace std;
/////////////////////////////////////
////////// the window //////////
/////////////////////////////////////
/** \cond HIDDEN_SYMBOLS */
class SizingFrame : public wxFrame
{
public:
SizingFrame(wxWindow *parent, const wxString& title);
void OnOpen(wxCommandEvent &event);
void OnQuit(wxCommandEvent &event);
void OnScreenshot(wxCommandEvent& event);
void OnViewSize(wxCommandEvent& event);
void OnAbout(wxCommandEvent &event);
void OnScreenInfo(wxCommandEvent &event);
void OnResize(wxSizeEvent &event);
void LateInit();
protected:
wxStaticBitmap* StaticBitmap_;
wxImage* Img_;
bool SizeLocked_;
enum {
ID_Whatever = wxID_HIGHEST + 42,
ID_Screenshot,
ID_VS_Free,
ID_VS_640,
ID_VS_800,
ID_VS_16_9,
ID_VS_16_10,
ID_ScreenInfo
};
private:
void DumpSizes_();
void FitToImageSize_();
wxMenuBar* Menubar_;
wxToolBar* Toolbar_;
wxStatusBar* Statusbar_;
DECLARE_EVENT_TABLE()
};
/** \endcond */
BEGIN_EVENT_TABLE(SizingFrame, wxFrame)
EVT_MENU(wxID_OPEN, SizingFrame::OnOpen)
EVT_MENU(wxID_EXIT, SizingFrame::OnQuit)
EVT_MENU(wxID_ABOUT, SizingFrame::OnAbout)
EVT_MENU(ID_Screenshot, SizingFrame::OnScreenshot)
EVT_MENU(ID_VS_Free, SizingFrame::OnViewSize)
EVT_MENU(ID_VS_640, SizingFrame::OnViewSize)
EVT_MENU(ID_VS_800, SizingFrame::OnViewSize)
EVT_MENU(ID_VS_16_9, SizingFrame::OnViewSize)
EVT_MENU(ID_VS_16_10, SizingFrame::OnViewSize)
EVT_MENU(ID_ScreenInfo, SizingFrame::OnScreenInfo)
EVT_SIZE(SizingFrame::OnResize)
END_EVENT_TABLE()
SizingFrame::SizingFrame(wxWindow *parent, const wxString& title)
: wxFrame(parent, wxID_ANY, title),
SizeLocked_(false)
{
Img_ = new wxImage(640, 480);
Img_->SetRGB(wxRect(50,50,100,100), 255, 255, 0);
StaticBitmap_ = new wxStaticBitmap(this, wxID_ANY, wxBitmap(*Img_));
// create a status bar
Statusbar_ = this->CreateStatusBar( 2, wxST_SIZEGRIP, wxID_ANY );
const int numFields = 2;
Statusbar_->SetFieldsCount(numFields);
const int widths[numFields] = { -1, 170 };
Statusbar_->SetStatusWidths(numFields, widths);
// create a tool bar
Toolbar_ = this->CreateToolBar( wxTB_HORIZONTAL, wxID_ANY );
Toolbar_->SetToolBitmapSize( wxSize( 24,24 ) );
Toolbar_->SetToolSeparation( 0 );
Toolbar_->SetToolPacking( 0 );
Toolbar_->AddTool( ID_ScreenInfo, wxT("Screen Info"),
wxArtProvider::GetIcon(wxART_INFORMATION,wxART_TOOLBAR) );
Toolbar_->Realize();
// create a menu bar
wxMenu *menuFile = new wxMenu;
menuFile->Append(wxID_OPEN);
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
wxMenu *menuEdit = new wxMenu;
menuEdit->Append(ID_Screenshot, wxString(wxT("&Screenshot")) + wxT('\t') + wxT("F3"));
wxMenu *menuView = new wxMenu;
menuView->AppendRadioItem(ID_VS_Free, wxString(wxT("View Size &Free")) + wxT('\t') + wxT("CTRL-SHIFT-0"));
menuView->AppendRadioItem(ID_VS_640, wxString(wxT("View Size 4:3 &small")) + wxT('\t') + wxT("CTRL-SHIFT-1"));
menuView->AppendRadioItem(ID_VS_800, wxString(wxT("View Size 4:3 &medium")) + wxT('\t') + wxT("CTRL-SHIFT-2"));
menuView->AppendRadioItem(ID_VS_16_9, wxString(wxT("View Size 16:&9 medium")) + wxT('\t') + wxT("CTRL-SHIFT-3"));
menuView->AppendRadioItem(ID_VS_16_10, wxString(wxT("View Size 16:&10 medium")) + wxT('\t') + wxT("CTRL-SHIFT-4"));
wxMenu *menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);
Menubar_ = new wxMenuBar;
Menubar_->Append(menuFile, wxT("&File"));
Menubar_->Append(menuEdit, wxT("&Edit"));
Menubar_->Append(menuView, wxT("&View"));
Menubar_->Append(menuHelp, wxT("&Help"));
SetMenuBar(Menubar_);
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(StaticBitmap_, 1, wxEXPAND|wxALL|wxALIGN_CENTRE, 0);
SetMinSize(wxSize(555,333));
SetSizer(mainSizer);
mainSizer->Fit(this);
Layout();
}
void SizingFrame::
LateInit()
{
FitToImageSize_();
}
void SizingFrame::
OnScreenInfo(wxCommandEvent &event)
{
wxString msg = wxT("Window size is ");
msg << GetSize().GetWidth() << wxT(" x ")
<< GetSize().GetHeight();
msg << wxT("\n") << wxT("Client size is ");
msg << GetClientSize().GetWidth() << wxT(" x ")
<< GetClientSize().GetHeight();
wxMessageBox(msg, wxT("Example Sizing - Screen Info"),
wxOK | wxICON_INFORMATION, this);
}
void SizingFrame::
OnResize(wxSizeEvent &event)
{
cout << "size event: window size \t("
<< GetSize().GetWidth() << " x " << GetSize().GetHeight() << ")\n";
event.Skip();
}
void SizingFrame::
OnOpen(wxCommandEvent &event)
{
event.Skip();
}
void SizingFrame::
OnQuit(wxCommandEvent &event)
{
Close();
}
void SizingFrame::
OnViewSize(wxCommandEvent& event)
{
FitToImageSize_();
}
void SizingFrame::
OnScreenshot(wxCommandEvent& event)
{
wxMessageBox(wxT("Saving screenshot not implemented!"), wxT("Information"),
wxOK | wxICON_INFORMATION, this);
}
void SizingFrame::
OnAbout(wxCommandEvent &event)
{
wxString desc;
desc << wxT(" This example is part of the\n");
desc << wxT(" BIAS library (Basic ImageAlgorithmS)\n") << wxT("\n\n");
wxString lic = wxT("BIAS is free software; you can redistribute it and/or modify\n \
it under the terms of the GNU Lesser General Public Licence as published by\n \
the Free Software Foundation; either version 2.1 of the Licence, or\n \
(at your option) any later version.\n \
\n \
BIAS is distributed in the hope that it will be useful,\n \
but WITHOUT ANY WARRANTY; without even the implied warranty of\n \
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n \
GNU Lesser General Public Licence for more details.\n \
\n \
You should have received a copy of the GNU Lesser General Public Licence\n \
along with BIAS; if not, write to the Free Software\n \
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
wxAboutDialogInfo aboutdlg;
aboutdlg.SetDescription( desc );
aboutdlg.SetLicence( lic );
aboutdlg.SetCopyright( wxT("Copyright (C) 2003-2009\n \
Multimediale Systeme der Informationsverarbeitung\n \
Institut fuer Informatik\n \
Christian-Albrechts-Universitaet Kiel") );
aboutdlg.SetWebSite( wxT("http://www.mip.informatik.uni-kiel.de/") );
wxAboutBox( aboutdlg );
}
void SizingFrame::
DumpSizes_()
{
static unsigned run = 0;
cout << "****** loads of sizes (no. " << run++ << ") *****\n";
cout << "size locked? " << boolalpha << SizeLocked_ << endl;
cout << "window size \t(" << GetSize().GetWidth() << " x " << GetSize().GetHeight() << ")\n";
cout << "client size \t(" << GetClientSize().GetWidth() << " x " << GetClientSize().GetHeight() << ")\n";
//cout << "menubar size \t(" << Menubar_->GetSize().GetWidth() << " x " << Menubar_->GetSize().GetHeight() << ")\n";
//cout << "toolbar size \t(" << Toolbar_->GetSize().GetWidth() << " x " << Toolbar_->GetSize().GetHeight() << ")\n";
//cout << "statusbar size \t(" << Statusbar_->GetSize().GetWidth() << " x " << Statusbar_->GetSize().GetHeight() << ")\n";
cout << "static bitmap size \t(" << StaticBitmap_->GetSize().GetWidth() << " x " << StaticBitmap_->GetSize().GetHeight() << ")\n\n";
}
void SizingFrame::
FitToImageSize_()
{
//DumpSizes_();
//wxSize windowSize = this->GetSize();
wxSize clientSize = this->GetClientSize();
wxSize staticBitmapSize = StaticBitmap_->GetSize();
SizeLocked_ = false;
if ( Menubar_->IsChecked(ID_VS_640) ) {
SizeLocked_ = true;
Img_->Resize(wxSize(640, 480), wxPoint(0,0), 0, 255, 0);
StaticBitmap_->SetBitmap(wxBitmap(*Img_));
}
if ( Menubar_->IsChecked(ID_VS_800) ) {
SizeLocked_ = true;
Img_->Resize(wxSize(800, 600), wxPoint(0,0), 255, 0, 0);
StaticBitmap_->SetBitmap(wxBitmap(*Img_));
}
if ( Menubar_->IsChecked(ID_VS_16_9) ) {
SizeLocked_ = true;
Img_->Resize(wxSize(800, 450), wxPoint(0,0), 0, 0, 255);
StaticBitmap_->SetBitmap(wxBitmap(*Img_));
}
if ( Menubar_->IsChecked(ID_VS_16_10) ) {
SizeLocked_ = true;
Img_->Resize(wxSize(800, 500), wxPoint(0,0), 0, 255, 255);
StaticBitmap_->SetBitmap(wxBitmap(*Img_));
}
if ( Menubar_->IsChecked(ID_VS_Free) ) {
Img_->Resize(clientSize, wxPoint(0,0), 255, 0, 255);
StaticBitmap_->SetBitmap(wxBitmap(*Img_));
SizeLocked_ = false;
}
//int height =
//Menubar_->GetSize().GetHeight() + Toolbar_->GetSize().GetHeight()
//+ Statusbar_->GetSize().GetHeight();
if ( SizeLocked_ ) {
StaticBitmap_->SetSize(staticBitmapSize);
}
else {
/// do nothing
}
clientSize = StaticBitmap_->GetSize();
this->SetClientSize(clientSize);
cout << "++++ before fitting ++++" << endl;
DumpSizes_();
Fit();
//Layout();
//Update();
cout << "++++ after fitting ++++" << endl;
DumpSizes_();
}
////////////////////////////////////////
////////// main routine //////////
////////////////////////////////////////
/** \cond HIDDEN_SYMBOLS*/
class SizingApp : public wxApp
{
public:
bool OnInit();
};
bool SizingApp::OnInit()
{
wxInitAllImageHandlers();
SizingFrame* mainFrame =
new SizingFrame(NULL, wxT("Example Sizing"));
mainFrame->Show();
mainFrame->LateInit();
return true;
}
IMPLEMENT_APP(SizingApp)
/** \endcond */