Simple Game Graphics Library  1.0
graphics.h
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include <functional>
4 #include <sgg/scancodes.h>
5 #include <vector>
6 
13 namespace graphics
14 {
17  typedef enum {
18  CANVAS_SCALE_WINDOW = 0,
19  CANVAS_SCALE_STRETCH,
20  CANVAS_SCALE_FIT
21  }
23 
32  struct Brush
33  {
34  float fill_color[3] = {1.f,1.f,1.f};
35 
37  float fill_secondary_color[3] = { 1.f,1.f,1.f };
38 
40  float fill_opacity = 1.0f;
41 
44  float fill_secondary_opacity = 1.f;
45 
47  float outline_color[3] = { 1.f,1.f,1.f };
48 
51  float outline_opacity = 1.f;
52 
54  float outline_width = 1.0f;
55 
57  std::string texture = "";
58 
79  bool gradient = false;
80 
82  float gradient_dir_u = 0.0f;
83 
90  float gradient_dir_v = 1.0f;
91  };
92 
107  struct MouseState
108  {
118  bool dragging;
119  int cur_pos_x;
120  int cur_pos_y;
123  };
124 
125 
139  void createWindow(int width, int height, std::string title);
140 
156 
162 
193 
198 
214  void setCanvasSize(float w, float h);
215 
243 
250  void setFullScreen(bool fs);
251 
262  float windowToCanvasX(float x, bool clamped = true);
263 
274  float windowToCanvasY(float y, bool clamped = true);
275 
327  void setUserData(const void* user_data);
328 
338  void* getUserData();
339 
389  void setDrawFunction(std::function<void()> draw);
390 
443  void setUpdateFunction(std::function<void(float)> update );
444 
476  void setResizeFunction(std::function<void(int, int)> resize);
495 
496 
524  float getDeltaTime();
525 
532  float getGlobalTime();
552  void drawRect(float center_x, float center_y, float width, float height, const Brush & brush);
553 
567  void drawLine(float x1, float y1, float x2, float y2, const Brush & brush);
568 
581  void drawDisk(float cx, float cy, float radius, const Brush & brush);
582 
611  void drawSector(float cx, float cy, float radius1, float radius2, float start_angle, float end_angle, const Brush & brush);
612 
629  bool setFont(std::string fontname);
630 
651  void drawText(float pos_x, float pos_y, float size, const std::string & text, const Brush & brush);
652 
666  void setOrientation(float angle);
667 
689  void setScale(float sx, float sy);
690 
693  void resetPose();
694 
742  std::vector<std::string> preloadBitmaps(std::string dir);
743 
764  void playSound(std::string soundfile, float volume, bool looping = false);
765 
787  void playMusic(std::string soundfile, float volume, bool looping = true, int fade_time = 0);
788 
796  void stopMusic(int fade_time = 0);
799 }
graphics::Brush::fill_secondary_color
float fill_secondary_color[3]
Definition: graphics.h:37
graphics::drawRect
void drawRect(float center_x, float center_y, float width, float height, const Brush &brush)
graphics::MouseState::cur_pos_x
int cur_pos_x
The current x position in pixel units of the pointing device.
Definition: graphics.h:119
graphics::getGlobalTime
float getGlobalTime()
graphics::MouseState::button_left_released
bool button_left_released
The left button went from an "pressed" state to a "released" one during the last poll cycle.
Definition: graphics.h:112
graphics::setCanvasSize
void setCanvasSize(float w, float h)
graphics::Brush::gradient
bool gradient
Definition: graphics.h:79
graphics::MouseState::button_right_down
bool button_right_down
The right button is currently held down.
Definition: graphics.h:117
graphics::MouseState::button_middle_down
bool button_middle_down
The middle button is currently held down.
Definition: graphics.h:116
graphics::Brush::outline_width
float outline_width
Definition: graphics.h:54
graphics::Brush::gradient_dir_u
float gradient_dir_u
Definition: graphics.h:82
graphics::windowToCanvasX
float windowToCanvasX(float x, bool clamped=true)
graphics::setFullScreen
void setFullScreen(bool fs)
graphics::setWindowBackground
void setWindowBackground(Brush style)
graphics::setResizeFunction
void setResizeFunction(std::function< void(int, int)> resize)
graphics::Brush::fill_secondary_opacity
float fill_secondary_opacity
Definition: graphics.h:44
graphics::MouseState::button_left_pressed
bool button_left_pressed
The left button went from an "depressed" state to a "pressed" one during the last poll cycle.
Definition: graphics.h:109
graphics::Brush
Definition: graphics.h:33
graphics::Brush::fill_opacity
float fill_opacity
Definition: graphics.h:40
graphics::MouseState::button_right_pressed
bool button_right_pressed
The right went from an "depressed" state to a "pressed" one during the last poll cycle.
Definition: graphics.h:111
graphics::MouseState::cur_pos_y
int cur_pos_y
The current y position in pixel units of the pointing device.
Definition: graphics.h:120
graphics::MouseState::button_left_down
bool button_left_down
The left button is currently held down.
Definition: graphics.h:115
graphics::startMessageLoop
void startMessageLoop()
graphics::getUserData
void * getUserData()
graphics::drawText
void drawText(float pos_x, float pos_y, float size, const std::string &text, const Brush &brush)
graphics
graphics::drawDisk
void drawDisk(float cx, float cy, float radius, const Brush &brush)
graphics::MouseState
Definition: graphics.h:108
graphics::playMusic
void playMusic(std::string soundfile, float volume, bool looping=true, int fade_time=0)
graphics::setCanvasScaleMode
void setCanvasScaleMode(scale_mode_t sm)
graphics::MouseState::prev_pos_x
int prev_pos_x
The x position in pixel units of the pointing device in the previous update cycle.
Definition: graphics.h:121
graphics::drawSector
void drawSector(float cx, float cy, float radius1, float radius2, float start_angle, float end_angle, const Brush &brush)
graphics::Brush::outline_color
float outline_color[3]
Definition: graphics.h:47
graphics::setUpdateFunction
void setUpdateFunction(std::function< void(float)> update)
graphics::preloadBitmaps
std::vector< std::string > preloadBitmaps(std::string dir)
graphics::stopMessageLoop
void stopMessageLoop()
graphics::setOrientation
void setOrientation(float angle)
graphics::Brush::gradient_dir_v
float gradient_dir_v
Definition: graphics.h:90
graphics::scancode_t
scancode_t
Definition: scancodes.h:12
graphics::destroyWindow
void destroyWindow()
graphics::MouseState::dragging
bool dragging
The left button is currently held down and the cursor is moving.
Definition: graphics.h:118
graphics::setUserData
void setUserData(const void *user_data)
graphics::MouseState::button_right_released
bool button_right_released
The right button went from an "pressed" state to a "released" one during the last poll cycle.
Definition: graphics.h:114
graphics::drawLine
void drawLine(float x1, float y1, float x2, float y2, const Brush &brush)
graphics::MouseState::button_middle_pressed
bool button_middle_pressed
The middle button went from an "depressed" state to a "pressed" one during the last poll cycle.
Definition: graphics.h:110
graphics::setScale
void setScale(float sx, float sy)
graphics::setFont
bool setFont(std::string fontname)
graphics::getMouseState
void getMouseState(MouseState &ms)
graphics::MouseState::button_middle_released
bool button_middle_released
The middle button went from an "pressed" state to a "released" one during the last poll cycle.
Definition: graphics.h:113
graphics::stopMusic
void stopMusic(int fade_time=0)
graphics::resetPose
void resetPose()
graphics::getKeyState
bool getKeyState(scancode_t key)
graphics::createWindow
void createWindow(int width, int height, std::string title)
graphics::setDrawFunction
void setDrawFunction(std::function< void()> draw)
graphics::getDeltaTime
float getDeltaTime()
graphics::Brush::fill_color
float fill_color[3]
Definition: graphics.h:34
graphics::playSound
void playSound(std::string soundfile, float volume, bool looping=false)
graphics::MouseState::prev_pos_y
int prev_pos_y
The y position in pixel units of the pointing device in the previous update cycle.
Definition: graphics.h:122
graphics::windowToCanvasY
float windowToCanvasY(float y, bool clamped=true)
graphics::scale_mode_t
scale_mode_t
Definition: graphics.h:17
graphics::Brush::outline_opacity
float outline_opacity
Definition: graphics.h:51
graphics::Brush::texture
std::string texture
Definition: graphics.h:57