Symphony Of Empires
image.cpp
Go to the documentation of this file.
1 // Symphony of Empires
2 // Copyright (C) 2021, Symphony of Empires contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // eng3d/ui/image.cpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #include "eng3d/ui/image.hpp"
26 #include "eng3d/texture.hpp"
27 #include "eng3d/state.hpp"
28 
29 using namespace UI;
30 
31 Image::Image(int _x, int _y, unsigned w, unsigned h, Widget* _parent)
32  : Widget(_parent, _x, _y, w, h, UI::WidgetType::IMAGE)
33 {
34 
35 }
36 
37 Image::Image(int _x, int _y, unsigned w, unsigned h, std::shared_ptr<Eng3D::Texture> tex, Widget* _parent)
38  : Widget(_parent, _x, _y, w, h, UI::WidgetType::IMAGE)
39 {
40  current_texture = tex;
41 }
42 
43 Image::Image(int _x, int _y, unsigned w, unsigned h, const std::string& texture_path, Widget* _parent)
44  : Widget(_parent, _x, _y, w, h, UI::WidgetType::IMAGE)
45 {
46  auto& s = Eng3D::State::get_instance();
47  current_texture = s.tex_man.load(s.package_man.get_unique(texture_path));
48 }
49 
50 Image::Image(int _x, int _y, unsigned w, unsigned h, const std::string& texture_path, bool mipmap, Widget* _parent)
51  : Widget(_parent, _x, _y, w, h, UI::WidgetType::IMAGE)
52 {
53  Eng3D::TextureOptions options;
54  if(mipmap) {
55  options.min_filter = Eng3D::TextureOptions::Filter::LINEAR_MIPMAP;
56  options.mag_filter = Eng3D::TextureOptions::Filter::LINEAR;
57  options.wrap_s = Eng3D::TextureOptions::Wrap::CLAMP_TO_EDGE;
58  options.wrap_t = Eng3D::TextureOptions::Wrap::CLAMP_TO_EDGE;
59  }
60  auto& s = Eng3D::State::get_instance();
61  current_texture = s.tex_man.load(s.package_man.get_unique(texture_path), options);
62 }
63 
64 Image* Image::make_transparent(int x, int y, unsigned w, unsigned h, const std::string& tex_path, Widget* parent) {
65  return make_transparent(x, y, w, h, tex_path, false, parent);
66 }
67 
68 Image* Image::make_transparent(int x, int y, unsigned w, unsigned h, const std::string& texture_path, bool mipmap, Widget* parent) {
69  Eng3D::TextureOptions no_drop_options{};
70  no_drop_options.editable = true;
71  if(mipmap) {
72  no_drop_options.min_filter = Eng3D::TextureOptions::Filter::LINEAR_MIPMAP;
73  no_drop_options.mag_filter = Eng3D::TextureOptions::Filter::LINEAR;
74  }
75  auto& s = Eng3D::State::get_instance();
76  auto texture = s.tex_man.load(s.package_man.get_unique(texture_path), no_drop_options);
77  Image* image = new Image(x, y, w, h, texture, parent);
78  image->is_transparent = true;
79  return image;
80 }
81 
82 AspectImage::AspectImage(int _x, int _y, unsigned w, unsigned h, std::shared_ptr<Eng3D::Texture> tex, Widget* _parent)
83  : Image(_x, _y, w, h, tex, _parent)
84 {
85  //width = w;this
86  //height = (float)current_texture->height * ((float)w / (float)current_texture->width);
87 
88  this->width = (float)this->current_texture->width * ((float)h / (float)this->current_texture->height);
89  this->height = h;
90 }
static State & get_instance()
Definition: state.cpp:514
enum Eng3D::TextureOptions::Filter min_filter
enum Eng3D::TextureOptions::Wrap wrap_s
AspectImage(int x, int y, unsigned w, unsigned max_h, std::shared_ptr< Eng3D::Texture > tex, Widget *parent=nullptr)
Definition: image.cpp:82
Image widget, can display pictures or effects on the screen.
Definition: image.hpp:43
static Image * make_transparent(int x, int y, unsigned w, unsigned h, const std::string &tex_path, Widget *parent=nullptr)
Definition: image.cpp:64
Image(int x, int y, unsigned w, unsigned h, Widget *parent=nullptr)
Definition: image.cpp:31
The master widget all the other widgets inherit from, do not use directly instead use one of the many...
Definition: widget.hpp:176
size_t width
Definition: widget.hpp:325
std::shared_ptr< Eng3D::Texture > current_texture
Definition: widget.hpp:327
bool is_transparent
Definition: widget.hpp:311
size_t height
Definition: widget.hpp:325
UI::Widget * parent
Definition: widget.hpp:314
WidgetType
The type of the widget, some widgets share types between them to keep simplicity.
Definition: widget.hpp:76