diff --git a/05_sdl_alapok/image.h b/05_sdl_alapok/image.h index 4bc1c8e..7177ee6 100644 --- a/05_sdl_alapok/image.h +++ b/05_sdl_alapok/image.h @@ -1,8 +1,63 @@ #ifndef IMAGE_H #define IMAGE_H +#include "color.h" +#include "rect2.h" +#include "string.h" +#include "vector.h" +#include + class Image { public: + void create(Uint32 flags, int width, int height); + + void enable_transparent_color(const Color &color); + void disable_transparent_color(); + void set_transparent_color(const Color &color); + bool has_transparent_color(); + Color get_transparent_color(); + + Color get_color_mod(); + void set_color_mod(const Color &color); + + Color get_alpha_mod(); + void set_alpha_mod(const Color &color); + + SDL_BlendMode get_blend_mode(); + void get_blend_mode(const SDL_BlendMode mode); + + Rect2 get_clip_rect(); + void get_clip_rect(const Rect2 &mode); + + Image *duplicate(); + + void convert(const SDL_PixelFormat *fmt, Uint32 flags); + void convert(Uint32 pixel_format, Uint32 flags); + + void fill_rect(const Rect2 &rect, const Color &color); + void fill_rects(const Vector &rects, const Color &color); + void set_pixel(const int x, const int y, const Color &color); + Color get_pixel(const int x, const int y); + + void blit_surface(const Image &source, const Rect2 &srcrect, const Rect2 &dstrect); + + void lock(); + void unlock(); + + void free(); + + void load_bmp(); + + Uint32 get_width() const; + Uint32 get_height() const; + + SDL_Surface *get_surface(); + + Image(); + virtual ~Image(); + +private: + SDL_Surface *_surface; }; #endif \ No newline at end of file diff --git a/05_sdl_alapok/vector.h b/05_sdl_alapok/vector.h new file mode 100644 index 0000000..5330100 --- /dev/null +++ b/05_sdl_alapok/vector.h @@ -0,0 +1,213 @@ +#ifndef VECTOR_H +#define VECTOR_H + +template +class Vector { + +public: + void push_back(const T &element); + void pop_back(); + void remove(const int index); + void remove_keep_order(const int index); + void erase(const T &element); + void clear(); + bool empty() const; + T get(const int index); + const T &get(const int index) const; + void set(const int index, const T &value); + + int size() const; + int capacity() const; + void ensure_capacity(const int capacity); + void resize(const int s); + void append_array(const Vector &other); + int find(const T &val) const; + + int *dataw(); + const int *data() const; + + const T &operator[](const int index) const; + T &operator[](const int index); + + Vector(); + Vector(int prealloc); + Vector(int prealloc, int grow_by); + +private: + T *_data; + int _actual_size; + int _size; + int _grow_by; +}; + +template +void Vector::push_back(const T &element) { + ensure_capacity(_size + 1); + + _data[_size++] = element; +} + +template +void Vector::pop_back() { + if (_size == 0) { + return; + } + + --_size; +} + +template +void Vector::remove(const int index) { + _data[index] = _data[_size - 1]; + + --_size; +} + +template +void Vector::remove_keep_order(const int index) { + --_size; + + for (int i = index; i < _size; ++i) { + _data[i] = _data[i + 1]; + } +} + +template +void Vector::erase(const T &element) { + int index = find(element); + + if (index != -1) { + remove(index); + } +} + +template +void Vector::clear() { + _size = 0; +} + +template +bool Vector::empty() const { + return _size == 0; +} + +template +T Vector::get(const int index) { + return _data[index]; +} + +template +const T &Vector::get(const int index) const { + return _data[index]; +} + +template +void Vector::set(const int index, const T &value) { + _data[index] = value; +} + +template +int Vector::size() const { + return _size; +} + +template +int Vector::capacity() const { + return _actual_size; +} + +template +void Vector::ensure_capacity(const int capacity) { + if (capacity <= _actual_size) { + return; + } + + int tsize = capacity + _grow_by; + + T *nd = new T[tsize]; + + for (int i = 0; i < _size; ++i) { + nd[i] = _data[i]; + } + + delete[] _data; + + _data = nd; +} + +template +void Vector::resize(const int s) { + ensure_capacity(s); + + _size = s; +} + +template +void Vector::append_array(const Vector &other) { + ensure_capacity(_size + other._size); + + for (int i = 0; i < other._size; ++i) { + _data[_size++] = other._data[i]; + } +} + +template +int Vector::find(const T &val) const { + for (int i = 0; i < _size; ++i) { + if (_data[i] == val) { + return i; + } + } + + return -1; +} + +template +int *Vector::dataw() { + return _data; +} + +template +const int *Vector::data() const { + return _data; +} + +template +const T &Vector::operator[](const int index) const { + return _data[index]; +} + +template +T &Vector::operator[](const int index) { + return _data[index]; +} + +template +Vector::Vector() { + _data = nullptr; + _actual_size = 0; + _size = 0; + _grow_by = 100; +} + +template +Vector::Vector(int prealloc) { + _data = nullptr; + _actual_size = 0; + _size = 0; + _grow_by = 100; + + ensure_capacity(prealloc); +} + +template +Vector::Vector(int prealloc, int grow_by) { + _data = nullptr; + _actual_size = 0; + _size = 0; + _grow_by = grow_by; + + ensure_capacity(prealloc); +} + +#endif \ No newline at end of file