-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathImageList.cpp
More file actions
83 lines (73 loc) · 3.36 KB
/
ImageList.cpp
File metadata and controls
83 lines (73 loc) · 3.36 KB
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
#include <wx/app.h>
#include <wx/artprov.h>
#include <wx/bmpbuttn.h>
#include <wx/filedlg.h>
#include <wx/filename.h>
#include <wx/frame.h>
#include <wx/imaglist.h>
#include <wx/panel.h>
#include <wx/sysopt.h>
#include <wx/settings.h>
#include <wx/statbmp.h>
namespace ImageListExample {
class Frame : public wxFrame {
public:
Frame() : wxFrame {nullptr, wxID_ANY, "ImageList example"} {
wxInitAllImageHandlers();
SetClientSize({300, 250});
panel->Bind(wxEVT_LEFT_DOWN, [&](wxMouseEvent& event) {
LoadImages();
});
picture->SetSize({150, 150});
picture->SetBackgroundColour(wxSystemSettings::GetColour(wxSystemColour::wxSYS_COLOUR_WINDOW));
picture->Bind(wxEVT_LEFT_DOWN, [&](wxMouseEvent& event) {
LoadImages();
});
buttonBack->Enable(false);
buttonBack->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) {
if (currentImageIndex > 0) picture->SetBitmap(pictures->GetBitmap(--currentImageIndex));
picture->SetSize({150, 150});
buttonBack->Enable(currentImageIndex > 0);
buttonForward->Enable(currentImageIndex < pictures->GetImageCount() - 1);
});
buttonForward->Enable(false);
buttonForward->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) {
if (currentImageIndex < pictures->GetImageCount()) picture->SetBitmap(pictures->GetBitmap(++currentImageIndex));
picture->SetSize({150, 150});
buttonBack->Enable(currentImageIndex > 0);
buttonForward->Enable(currentImageIndex < pictures->GetImageCount() - 1);
});
Show();
LoadImages();
}
private:
void LoadImages() {
auto openFileDialog = wxFileDialog {this, wxEmptyString, wxEmptyString, wxEmptyString, "All Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.xpm|Bitmap Files|*.bmp|Gif Files|*.gif|Jpeg Files|*.jpg;*.jpeg|Png Files|*.png|Tiff Files|*.tif;*.tiff|xpm Files|*.xpm", wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_MULTIPLE};
if (openFileDialog.ShowModal() == wxID_OK) {
auto filenames = wxArrayString {};
openFileDialog.GetFilenames(filenames);
pictures->RemoveAll();
for (auto filename : filenames)
pictures->Add({wxImage {openFileDialog.GetDirectory() + wxFileName::GetPathSeparator() + filename}.Rescale(128, 128, wxIMAGE_QUALITY_HIGH)});
currentImageIndex = 0;
picture->SetBitmap(pictures->GetBitmap(currentImageIndex));
picture->SetSize({150, 150});
buttonBack->Enable(currentImageIndex > 0);
buttonForward->Enable(currentImageIndex < pictures->GetImageCount() - 1);
}
}
int currentImageIndex = 0;
wxPanel* panel = new wxPanel {this};
wxImageList* pictures = new wxImageList {128, 128};
wxStaticBitmap* picture = new wxStaticBitmap {panel, wxID_ANY, wxNullBitmap, {75, 25}, wxDefaultSize, wxBORDER_SUNKEN};
wxBitmapButton* buttonBack = new wxBitmapButton {panel, wxID_UP, wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_BUTTON), {75, 200}, {75, 25}};
wxBitmapButton* buttonForward = new wxBitmapButton {panel, wxID_DOWN, wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_BUTTON), {150, 200}, {75, 25}};
};
class Application : public wxApp {
auto OnInit() -> bool override {
wxSystemOptions::SetOption("osx.openfiledialog.always-show-types", 1);
return (new Frame);
}
};
}
wxIMPLEMENT_APP(ImageListExample::Application);