blob: fb1e5e3e8f69c722b9ce6ba32f105a2be16ceb19 (
plain)
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
|
#pragma once
#include "Path.hpp"
#include <string>
#include <vector>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/System/Clock.hpp>
namespace QuickMedia {
class Manga;
struct ImageData {
sf::Texture texture;
sf::Sprite sprite;
bool failed_to_load_image;
bool visible_on_screen;
};
struct PageSize {
sf::Vector2<double> size;
bool loaded;
};
class ImageViewer {
public:
ImageViewer(Manga *manga, const std::string &images_url, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir, sf::Font *font);
bool draw(sf::RenderWindow &window);
// Returns page as 1 indexed
int get_focused_page() const;
int get_num_pages() const { return num_pages; }
private:
bool render_page(sf::RenderWindow &window, int page, double offset_y);
sf::Vector2<double> get_page_size(int page);
private:
int current_page;
int num_pages;
int page_center;
std::string chapter_title;
Path chapter_cache_dir;
double scroll = 0.0;
double scroll_speed = 0.0;
double min_page_center_dist;
int page_closest_to_center;
int focused_page;
int prev_focused_page = -1;
sf::Font *font;
sf::Clock frame_timer;
sf::Text page_text;
std::vector<std::unique_ptr<ImageData>> image_data;
std::vector<PageSize> page_size;
sf::Vector2<double> window_size;
bool window_size_set = false;
};
}
|