mousetrap v0.2.0
Loading...
Searching...
No Matches
image_display.hpp
1//
2// Copyright 2022 Clemens Cords
3// Created on 8/26/22 by clem (mail@clemens-cords.com)
4//
5
6#pragma once
7
8#include <mousetrap/image.hpp>
9#include <mousetrap/widget.hpp>
10#include <mousetrap/icon.hpp>
11#include <mousetrap/file_descriptor.hpp>
12
13namespace mousetrap
14{
15 #ifndef DOXYGEN
16 class ImageDisplay;
17 namespace detail
18 {
19 struct _ImageDisplayInternal;
20 using ImageDisplayInternal = _ImageDisplayInternal;
21 DEFINE_INTERNAL_MAPPING(ImageDisplay);
22 }
23 #endif
24
25 /// @brief widget that display an iamge
26 class ImageDisplay : public detail::notify_if_gtk_uninitialized,
27 public Widget,
28 HAS_SIGNAL(ImageDisplay, realize),
29 HAS_SIGNAL(ImageDisplay, unrealize),
30 HAS_SIGNAL(ImageDisplay, destroy),
31 HAS_SIGNAL(ImageDisplay, hide),
32 HAS_SIGNAL(ImageDisplay, show),
33 HAS_SIGNAL(ImageDisplay, map),
34 HAS_SIGNAL(ImageDisplay, unmap)
35 {
36 public:
37 /// @brief default ctor, initialize as 0x0 image
39
40 /// @brief create from internal
41 ImageDisplay(detail::ImageDisplayInternal*);
42
43 /// @brief destructor
45
46 /// @brief expose internal
47 NativeObject get_internal() const override;
48
49 /// @brief construct from GtkImage \for_internal_use_only
50 /// @param image GtkImage instance
51 ImageDisplay(GtkImage*);
52
53 /// @brief construct from image on disk
54 /// @param path
55 ImageDisplay(const std::string& path);
56
57 /// @brief construct from image
58 /// @param image
59 ImageDisplay(const Image& image);
60
61 /// @brief construct from icon
62 /// @param icon
63 ImageDisplay(const Icon& icon);
64
65 /// @brief get resolution of image buffer
66 /// @return resolution
67 Vector2ui get_size() const;
68
69 /// @brief load from image on disk
70 /// @param path
71 /// @return true if succesfull, false otherwise
72 bool create_from_file(const std::string& path);
73
74 /// @brief load from image
75 /// @param image
76 void create_from_image(const Image& image);
77
78 /// @brief load from icon
79 /// @param icon
80 void create_from_icon(const Icon& icon);
81
82 /// @brief create as preview of a file, if the file can be opened as an image, will display image, otherwise will display icon of filetype
83 /// @param file
84 void create_as_file_preview(const FileDescriptor& file);
85
86 /// @brief create from empty image
87 void clear();
88
89 /// @brief set scale, will use linear interpolation. For other types of interpolation, scale a mousetrap::Image instead
90 /// @param scale (positive integer) or -1 for default size
91 void set_scale(int scale);
92
93 /// @brief get_scale
94 /// @return integer, or -1 for default size
95 int get_scale() const;
96
97 private:
98 detail::ImageDisplayInternal* _internal = nullptr;
99
100 void update_size(uint64_t, uint64_t);
101 void initialize();
102 };
103}
non-mutating file descriptor, may point to any file, directory, or no file at all....
Definition: file_descriptor.hpp:24
object representing an icon. Note that this does not hodl any image data, instead it points to a file...
Definition: icon.hpp:73
widget that display an iamge
Definition: image_display.hpp:35
bool create_from_file(const std::string &path)
load from image on disk
Definition: image_display.cpp:130
int get_scale() const
get_scale
Definition: image_display.cpp:203
void create_from_icon(const Icon &icon)
load from icon
Definition: image_display.cpp:160
NativeObject get_internal() const override
expose internal
Definition: image_display.cpp:65
void clear()
create from empty image
Definition: image_display.cpp:189
ImageDisplay()
default ctor, initialize as 0x0 image
Definition: image_display.cpp:76
Vector2ui get_size() const
get resolution of image buffer
Definition: image_display.cpp:125
void create_as_file_preview(const FileDescriptor &file)
create as preview of a file, if the file can be opened as an image, will display image,...
Definition: image_display.cpp:168
void set_scale(int scale)
set scale, will use linear interpolation. For other types of interpolation, scale a mousetrap::Image ...
Definition: image_display.cpp:195
void create_from_image(const Image &image)
load from image
Definition: image_display.cpp:153
~ImageDisplay()
destructor
Definition: image_display.cpp:60
a 2d buffer container RGBA pixels
Definition: image.hpp:36
Widget, super class of all renderable entities.
Definition: widget.hpp:67