File: rgslideshow.cc

package info (click to toggle)
synaptic 0.81.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,184 kB
  • ctags: 2,538
  • sloc: cpp: 24,326; xml: 7,938; ansic: 2,084; makefile: 578; sh: 438; sed: 93; python: 82
file content (49 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download | duplicates (8)
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
#include <sys/types.h>
#include <dirent.h>

#include <gtk/gtk.h>

#include <algorithm>
#include <string>
#include <vector>

#include "rgslideshow.h"

using namespace std;

RGSlideShow::RGSlideShow(GtkImage * image, string imgPath)
: _image(image), _totalSteps(0), _currentStep(0)
{
   DIR *dir = opendir(imgPath.c_str());
   struct dirent *entry;
   imgPath += '/';
   if (dir != NULL) {
      for (entry = readdir(dir); entry != NULL; entry = readdir(dir)) {
         if (entry->d_name[0] != '.')
            _imageFileList.push_back(imgPath + entry->d_name);
      }
   }
   sort(_imageFileList.begin(), _imageFileList.end());
}

void RGSlideShow::step()
{
   _currentStep += 1;
   refresh();
}

void RGSlideShow::refresh()
{
   if (!_imageFileList.empty()) {
      int current = 0;
      if (_totalSteps) {
	 float stepping = (_totalSteps / (float)_imageFileList.size());
	 current = (int)((_currentStep + (stepping - 1) / 2) / stepping);
	 if (current >= _imageFileList.size())
	    current = _imageFileList.size() - 1;
      }
      gtk_image_set_from_file(_image, _imageFileList[current].c_str());
   }
}

// vim:sts=3:sw=3