1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include "wx/wx.h"
#include "CImg.h"
#include <iostream>
#include<string.h>
using namespace std;
#define cimg_use_jpeg
#define cimg_use_png
using namespace cimg_library;
// Classe application :
class MyApp : public wxApp
{
public:
// Méthode virtuelle de démarrage de l'application :
virtual bool OnInit();
};
// Notre fenêtre minimale :
class MyFrame : public wxFrame
{
public:
// Constructeur :
MyFrame(const wxString& title);
bool TextChg;
wxTextCtrl *mlTextCtrl;
// 2 handler d'évènements
void OnQuit(wxCommandEvent& event);
void Onouvre(wxCommandEvent& event);
void Onrotation(wxCommandEvent& event);
private:
// la table des évènements
DECLARE_EVENT_TABLE()
};
IMPLEMENT_APP(MyApp)
// Notre 'main' :
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App"));
frame->Show(true);
return true;
}
// IDs pour nos menus et contrôles :
enum
{
Minimal_Quit = wxID_EXIT,
Minimal_ouvre,
Minimal_rotation,
};
// La table des évènements de notre fenêtre :
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_ouvre, MyFrame::Onouvre)
EVT_MENU(Minimal_rotation, MyFrame::Onrotation)
END_EVENT_TABLE()
// Le constructeur de notre classe de fenêtre :
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
// Ajoutons nos menus :
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(Minimal_Quit, _T("&Quitter\tAlt-Q"), _T("Sortir du programme"));
wxMenu *file2Menu = new wxMenu;
file2Menu->Append(Minimal_ouvre, _T("&ouvrir"), _T("ouvrir"));
wxMenu *file3Menu = new wxMenu;
file3Menu->Append(Minimal_rotation, _T("&rotation"), _T("rotation"));
// dans une barre de menu :
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, _T("&Fichier"));
menuBar->Append(file2Menu, _T("&ouvrir"));
menuBar->Append(file3Menu, _T("&rotation"));
SetMenuBar(menuBar);
// Une barre de statut :
CreateStatusBar(2);
SetStatusText(_T("Bienvenu sur notre premier projet wxWidgets avec MinGW !"));
}
// La gestion des évènements :
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void MyFrame::Onouvre(wxCommandEvent& WXUNUSED(event))
{
wxString nomfichier = wxFileSelector(_T("Ouvrir") ,_T("") ,_T("") ,_T(""),
_T("cpp files (*.jpg;*.bmp)|*.jpg;*.bmp|resources files (*.rc)|*.rc"),wxOPEN);
if (!nomfichier.empty())
{
mlTextCtrl->LoadFile(nomfichier);
TextChg = false;
}
}
void MyFrame::Onrotation(wxCommandEvent& WXUNUSED(event))
{
CImg<double> image(monfichier);
image.rotate(90);
image.display();
} |
Partager