Revision 280,
1.1 KB
checked in by yasumichi, 14 years ago
(diff) |
first import
|
Line | |
---|
1 | #include <sys/types.h> |
---|
2 | #include <dirent.h> |
---|
3 | |
---|
4 | #include <gtk/gtk.h> |
---|
5 | |
---|
6 | #include <string> |
---|
7 | #include <vector> |
---|
8 | |
---|
9 | #include "rgslideshow.h" |
---|
10 | |
---|
11 | using namespace std; |
---|
12 | |
---|
13 | RGSlideShow::RGSlideShow(GtkImage * image, string imgPath) |
---|
14 | : _image(image), _totalSteps(0), _currentStep(0) |
---|
15 | { |
---|
16 | DIR *dir = opendir(imgPath.c_str()); |
---|
17 | struct dirent *entry; |
---|
18 | imgPath += '/'; |
---|
19 | if (dir != NULL) { |
---|
20 | for (entry = readdir(dir); entry != NULL; entry = readdir(dir)) { |
---|
21 | if (entry->d_name[0] != '.') |
---|
22 | _imageFileList.push_back(imgPath + entry->d_name); |
---|
23 | } |
---|
24 | } |
---|
25 | sort(_imageFileList.begin(), _imageFileList.end()); |
---|
26 | } |
---|
27 | |
---|
28 | void RGSlideShow::step() |
---|
29 | { |
---|
30 | _currentStep += 1; |
---|
31 | refresh(); |
---|
32 | } |
---|
33 | |
---|
34 | void RGSlideShow::refresh() |
---|
35 | { |
---|
36 | if (!_imageFileList.empty()) { |
---|
37 | int current = 0; |
---|
38 | if (_totalSteps) { |
---|
39 | float stepping = (_totalSteps / (float)_imageFileList.size()); |
---|
40 | current = (int)((_currentStep + (stepping - 1) / 2) / stepping); |
---|
41 | if (current >= _imageFileList.size()) |
---|
42 | current = _imageFileList.size() - 1; |
---|
43 | } |
---|
44 | gtk_image_set_from_file(_image, _imageFileList[current].c_str()); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | // vim:sts=3:sw=3 |
---|
Note: See
TracBrowser
for help on using the repository browser.