Simple Game Graphics Library 1.1
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
10
13namespace 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};
36
37 float fill_secondary_color[3] = { 1.f,1.f,1.f };
39
40 float fill_opacity = 1.0f;
43
46
47 float outline_color[3] = { 1.f,1.f,1.f };
50
51 float outline_opacity = 1.f;
53
54 float outline_width = 1.0f;
56
57 std::string texture = "";
78
79 bool gradient = false;
81
82 float gradient_dir_u = 0.0f;
89
90 float gradient_dir_v = 1.0f;
91 };
92
124
125
129
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
341
345
389 void setDrawFunction(std::function<void()> draw);
390
399 void setPreDrawFunction(std::function<void()> predraw);
400
409 void setPostDrawFunction(std::function<void()> postdraw);
410
463 void setUpdateFunction(std::function<void(float)> update );
464
496 void setResizeFunction(std::function<void(int, int)> resize);
498
515
516
531
535
545
554
558
572 void drawRect(float center_x, float center_y, float width, float height, const Brush & brush);
573
588 void drawBezier(float *ep1, float *cp1, float *cp2, float *ep2, const Brush& brush);
589
590
604 void drawLine(float x1, float y1, float x2, float y2, const Brush & brush);
605
618 void drawDisk(float cx, float cy, float radius, const Brush & brush);
619
648 void drawSector(float cx, float cy, float radius1, float radius2, float start_angle, float end_angle, const Brush & brush);
649
666 bool setFont(std::string fontname);
667
688 void drawText(float pos_x, float pos_y, float size, const std::string & text, const Brush & brush);
689
703 void setOrientation(float angle);
704
726 void setScale(float sx, float sy);
727
730 void resetPose();
731
733
737
785 std::vector<std::string> preloadBitmaps(const std::string & dir);
786
807 bool getBitmapData(const std::string & bitmap_name, unsigned char ** buffer, unsigned int * width, unsigned int * height);
808
829 bool updateBitmapData(const std::string& bitmap_name, const unsigned char* buffer);
830
831
833
834
838
852 void playSound(std::string soundfile, float volume, bool looping = false);
853
875 void playMusic(std::string soundfile, float volume, bool looping = true, int fade_time = 0);
876
884 void stopMusic(int fade_time = 0);
886
887}
void playMusic(std::string soundfile, float volume, bool looping=true, int fade_time=0)
void playSound(std::string soundfile, float volume, bool looping=false)
void stopMusic(int fade_time=0)
void setDrawFunction(std::function< void()> draw)
void setUpdateFunction(std::function< void(float)> update)
void setPreDrawFunction(std::function< void()> predraw)
void setResizeFunction(std::function< void(int, int)> resize)
void setPostDrawFunction(std::function< void()> postdraw)
bool setFont(std::string fontname)
void resetPose()
void setOrientation(float angle)
void drawDisk(float cx, float cy, float radius, const Brush &brush)
void drawText(float pos_x, float pos_y, float size, const std::string &text, const Brush &brush)
void setScale(float sx, float sy)
void drawSector(float cx, float cy, float radius1, float radius2, float start_angle, float end_angle, const Brush &brush)
void drawBezier(float *ep1, float *cp1, float *cp2, float *ep2, const Brush &brush)
void drawRect(float center_x, float center_y, float width, float height, const Brush &brush)
void drawLine(float x1, float y1, float x2, float y2, const Brush &brush)
void getMouseState(MouseState &ms)
bool getKeyState(scancode_t key)
bool updateBitmapData(const std::string &bitmap_name, const unsigned char *buffer)
std::vector< std::string > preloadBitmaps(const std::string &dir)
bool getBitmapData(const std::string &bitmap_name, unsigned char **buffer, unsigned int *width, unsigned int *height)
float getDeltaTime()
float getGlobalTime()
void stopMessageLoop()
void setCanvasScaleMode(scale_mode_t sm)
float windowToCanvasX(float x, bool clamped=true)
void startMessageLoop()
void createWindow(int width, int height, std::string title)
void setUserData(const void *user_data)
void * getUserData()
void destroyWindow()
void setFullScreen(bool fs)
void setCanvasSize(float w, float h)
void setWindowBackground(Brush style)
float windowToCanvasY(float y, bool clamped=true)
scancode_t
Definition scancodes.h:12
scale_mode_t
Definition graphics.h:17
Definition graphics.h:33
float fill_opacity
Definition graphics.h:40
float fill_color[3]
Definition graphics.h:34
float gradient_dir_v
Definition graphics.h:90
float outline_width
Definition graphics.h:54
float outline_opacity
Definition graphics.h:51
bool gradient
Definition graphics.h:79
float fill_secondary_color[3]
Definition graphics.h:37
float gradient_dir_u
Definition graphics.h:82
std::string texture
Definition graphics.h:57
float fill_secondary_opacity
Definition graphics.h:44
float outline_color[3]
Definition graphics.h:47
Definition graphics.h:108
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
int cur_pos_y
The current y position in pixel units of the pointing device.
Definition graphics.h:120
bool button_right_pressed
The right went from an "depressed" state to a "pressed" one during the last poll cycle.
Definition graphics.h:111
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
bool button_right_down
The right button is currently held down.
Definition graphics.h:117
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
bool button_left_down
The left button is currently held down.
Definition graphics.h:115
bool button_middle_down
The middle button is currently held down.
Definition graphics.h:116
int cur_pos_x
The current x position in pixel units of the pointing device.
Definition graphics.h:119
int prev_pos_y
The y position in pixel units of the pointing device in the previous update cycle.
Definition graphics.h:122
bool dragging
The left button is currently held down and the cursor is moving.
Definition graphics.h:118
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
int prev_pos_x
The x position in pixel units of the pointing device in the previous update cycle.
Definition graphics.h:121
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