EggAche is a Lightweight, Cross-Platform C++ Graphics Library
- You can easily embed the code WHEREVER there needs a GUI
- You can take Snapshot of the Window (if there should be a Graphical Log)
Welcome to Join 😉
Requirements:
- MSVC and Windows SDK (installed with Visual Studio)
- g++ and MinGW
Steps:
- Download this Project's zip
- Add the
EggAche.h
,EggAche.cpp
,EggAche_Impl.h
andWindows_Impl.cpp
in src directory to your project #include "EggAche.h"
where you want to use EggAche Library- Add
#define EGGACHE_WINDOWS
inEggAche.h
to specify that you are on Windows
Support Linux, Mac OSX and other Unix/Unix-Like Systems.
Still on the way 😇
- Create Window and Canvas
- Draw on Background Canvas
- Refresh Window
- Wait for User Closing the Window
Window window (640, 480); // Create a new Window
Canvas bgCanvas (640, 480); // Create a new Canvas
window.SetBackground (&bgCanvas); // Set Background Canvas of this Window
bgCanvas.DrawTxt (0, 0, "Hello EggAche"); // Draw Text at (0, 0)
bgCanvas.DrawLine (0, 30, 100, 30); // Draw Line From (0, 30) to (100, 30)
bgCanvas.DrawImg ("Assets/Egg.bmp", 20, 50); // Draw Canvas at (20, 50)
window.Refresh (); // Refresh the Window to View Changes
while (!window.IsClosed ()) // Not Quit until the Window is closed
std::this_thread::sleep_for (
std::chrono::milliseconds (50));// Sleep just 50ms
- Bind Event Handler to a Window
- Associate an Canvas to another one
- Take a Snapshot of the Window
Canvas lineCanvas (640, 480); // Create a New Canvas
bgCanvas += &lineCanvas; // Associate this new Canvas with Background Canvas
window.OnClick ([&]
(Window *, int x, int y) // Register OnClick Event
{
lineCanvas.Clear (); // Clear Previous Content
lineCanvas.DrawLine (0, 0, x, y); // Draw Line from (0, 0) to the Point you Clicked
window.Refresh (); // Refresh the Window to View Changes
bgCanvas.SaveAsBmp ("Snapshot.bmp");// Take a Snapshot :-)
});
And you will notice that Snapshot.bmp
has been saved 😉
- Add Draw Lock into your Code 😉
- Draw BMP File with a Color Mask
- Add Animation into the Game Loop
std::mutex mtx; // Mutex for Draw Lock
// ...
window.OnClick ([&]
(Window *, int x, int y)
{
// Lock for Draw
std::lock_guard<std::mutex> lg (mtx);
// ...
}
// ...
Canvas aniCanvas (73, 75, // Create a New Canvas
100, 100); // at (100, 100) initially
bgCanvas += &aniCanvas; // Associate this new Canvas with Background Canvas
aniCanvas.DrawImgMask ("Assets/EggMask.bmp",
"Assets/EggMask.bmp",
73, 75, 0, 0,
0, 0, 73, 0);
// Draw Image EggMask.bmp with a Mask in EggMask.bmp, of size 73 * 75, at (0, 0)
// And the left-top of Src Image is (0, 0), left-top of Mask Image is (74, 0)
auto offset = 0;
while (!window.IsClosed ()) // Rewrite this Part
{
{
// Lock for Draw
std::lock_guard<std::mutex> lg (mtx);
if (offset < 10) offset++; // Update offset
else offset = -10;
aniCanvas.MoveTo (100 + offset * 10,// Move aniCanvas
100 + offset * 10);
window.Refresh (); // Refresh Window
}
std::this_thread::sleep_for (
std::chrono::milliseconds (50)); // Sleep just 50ms
}
- Get Started's Full Code
- Running Dragon (Buffering and fps)
- Responsive Typer
- Beautiful Rainbow Animation
- v1.0
- This version is written in C
- There's No Classes and Objects
- There's only GDI Wrappers...
- v2.0
- This version is written in C++
- Everything is encapsulated in Classes
- v3.0
- Decoupling Platform Dependency
- Introducing C++ 11 Features (concept, lambda, stl...)
- Using Bridge Pattern to Separate the Common Interface (
EggAche_Impl.h
) from Platform-specific Implementations (*_Impl.h
) - Using Abstract Factory to Produce Platform-specific Implementation Objects for diverse Platforms (
EggAche.cpp
) - Using Composite Pattern to Define the Layout of Canvases (
EggAche.h
) - Using Adapter Pattern to Convert the interface of
WindowImpl Events
intoWindow Events
(EggAche.cpp
) - Using Observer Pattern to Notify Window Events and Auto Redraw (
*_Impl.h
) - Using Dependency Injection in Window Event System and Saving Images (
EggAche.h
,EggAche.cpp
,*_Impl.cpp
) - Using RAII
Singleton Patternto Maintain the Global Resource Manager (*_Impl.h
)