dx framework | Graphics, UI, events and more!
DX Framework
Small and neat Event based Windows library with graphics, ui and many more interfaces!
Small and neat Event based Windows library with graphics, ui and many more interfaces!
Scopes:
- dx
- Lib
- FileIO
- Graphics
- UI
- Window
- Math
- Net
- Lib
Types layout(Sorted by scope order):
- typedef uint
- typedef ulong
- typedef byte
- enum Key
- class Colors
- struct is_pointer<T>
- struct is_reference<T>
- struct is_array<T>
- struct remove_pointer<T>
- struct remove_reference<T>
- struct remove_array<T>
- struct remove_all<T>
- class String
- class Iterator<T>
- class ReverseIterator<T>
- class AsyncKeeper
- class AsyncGuard
- class FlexibleGuard
- class StopWatch
- using Clock = StopWatch
- class DeltaTimer
- using Timer = DeltaTimer
- class TimedTask<T>
- class timed_function<T>
- class EventHandler<T>
- class Event<T>
- class EventArgs
- class Path
- enum Token_t
- class Token
- class Tokenizer
- struct TokenizerMessage
- class Buffer<T>
- class Vector2
- class Region
- class BasePainter
- class Font
- class Line
- class Painter
- class Pen
- class Text
- class Circle
- class Texture
- class Window
- class MsgBox
- class WindowMovedArgs
- class WindowClosingArgs
- class KeyDownArgs
- class KeyUpArgs
- class KeyDownCharArgs
- class MouseMovedArgs
- class MouseClickedArgs
- class MouseReleasedArgs
- class ScrollArgs
- class MessageDataArgs
- enum Style
- Theme Theme
- class StyleManager
- class Component
- class Button
- class Checkbox
- class Textbox
Documentation
All methods in classes are documented, just find the function you wanna check out and look at the summary.
Examples!
Here is an example on how to create a window and register a few events.
Code:
/// [...]
#include <src/api>
/// [...]
/// [...]
auto application = dx::Application::Create( );
/// [...]
// Create a window at position 300x300 with the size of 930x690.
auto window = dx::Window::Create( "ClassName", "Title! | dx framework", dx::Region{ dx::Vector2{ 300, 300 }, dx::Vector2{ 930, 590 } } );
// You can specialize when 'OnPaint' event will be raised using SpecializePaint
window->SpecializePaint( dx::Window::OnEvent_t ); // Now it will only be raised when the WindowProc receives a 'WM_PAINT' or dx::Window::ForcePaint is called.
// This is good if you dont need to update the frame very often
// You can also draw every tick, you can adjust the frequency of each tick in dx::Application::setTickRate
window->SpecializePaint( dx::Window::OnTick_t ); // Now it will be raised every tick.
// Show the window
window->Show( );
// Bring the window to the top
window->BringToTop( );
// Optionally load your icons
window->LoadIcon( "MyTaskBarIcon.ico" );
window->LoadIconSm( "MyWindowIcon.ico" );
// Lets handle the OnClosingEvent, maybe the user accidentally pressed the 'X' icon, so we'll open a dialog and ask if he is sure.
window->OnWindowClosing( ) += []( dx::Window *sender, dx::WindowClosingArgs& args )
{
if ( dx::MsgBox( "Are you sure you want to exit?", "Sure?", dx::YesNo | dx::IconQuestion ).Show( ) == dx::dx::MsgBox::Yes )
args.ShouldClose = true;
else
args.ShouldClose = false;
};
// Now handle the actual real closing of the window (If the user was sure he wanted to exit)
window->OnWindowClosed( ) += []( dx::Window *sender )
{
dx::Application::get( )->exit( ); // Exit the application loop, this just makes sure application->run( ) stops running.
};
// There are alot more events and methods inside dx::Window, I urge you check them out to get a understanding
// of how the window is handled in the backend.
// Now lets run the application
application->run( );
Code:
/// [...]
/// Creation of window and application
/// [...]
dx::Hotkey my_hotkey{ { dx::key_shift, dx::key_up }, "my_hotkey" };
// You can register the hotkey by binding it with a event handler, or manually raising
/ dx::Hotkey::OnKeyDown/OnKeyUp event.
// Here I manually raise the events whenever the dx::Window::OnKeyDown/OnKeyUp is raised
// Lets also store them in an event handler so we can possibly remove the specific event handlers
// if we no longer want the event to raised
window->OnKeyDown( ) += dx::EventHandler<dx::Window::OnKeyDownSig>( "HandleHotkey_down", [&/*Capture all*/]( dx::Window *sender, dx::KeyDownArgs& args )
{
my_hotkey.OnKeyDown( sender, args );
});
// Now you also need to the handle the OnKeyUp otherwise my_hotkey wont know if the key is no longer held down.
window->OnKeyUp( ) += dx::EventHandler<dx::Window::OnKeyUpSig>( "HandleHotkey_up", [&/*Capture all*/]( dx::Window *sender, dx::KeyUpArgs& args )
{
my_hotkey.OnKeyUp( sender, args );
});
// Lets remove the handlers so that they hotkey is not fired twice, since I'm gonna show you how to bind the hotkey with the window.
window->OnKeyDown( ) -= "HandleHotkey_down"; // Remove Handler "HandleHotkey_down"
window->OnKeyUp( ) -= "HandleHotkey_up"; // Remove handler "HandleHotkey_up"
// Now lets do the binding:
window->OnKeyDown( ) += dx::EventHandler<dx::Window::KeyDownSig>("HandleHotkey_down", BIND_METHOD_2( &dx::Hotkey::OnKeyDown, &my_hotkey) );
window->OnKeyUp( ) += dx::EventHandler<dx::Window::KeyUpSig>( "HandleHotkey_up", BIND_METHOD_2( &dx::Hotkey::OnKeyUp, &my_hotkey ) );
// Oh and dont forget to handle the Hotkeys 'OnHotkey' event.
my_hotkey.OnHotkey( ) += [&]( dx::Hotkey *sender, dx::EventArgs &args )
{
// Simply print it out
std::cout << "Shift and key up pressed! :D" << std::endl;
// If we were really cool we could add a simple task
// that would do something, lets add a task to the application
// window was captured in the lambda capture list
window->addTask( dx::Clock::now( ), // Perform the task right now
[]( dx::Window *sender )
{
// Force a repaint
sender->ForcePaint( );
std::cout << "Forced repaint!\n";
} ).Completed( ) += []( dx::TimedTask<dx::Window*> *sender ) { std::cout << "Wowzers completed task!" << std::endl; };
};
/// [...]
application->run( );
/// [...]
Code:
/// [...]
/// Creation of application and window and everything needed for the window
/// [...]
// Simply, just create a Painter using dx::Painter
auto painter = dx::Painter::Create( window /*, true */ ); // The second argument is optional, if true it will set BasePainter::Singleton as this instance.
// You can do safety checks to see if it failed, you can check if painter is a nullptr, if it is a nullptr Application::getLastError will have the error code.
// Lets handle the OnPaint event
window->OnPaint( ) += []( dx::Window *sender, dx::BasePainter *painter )
{
// Lets paint the background in DimGray
painter->PaintRect( { { 0, 0 }, { sender->Width( ), sender->Height( ) } }, dx::Pen( dx::Colors::DimGray, 1 ) );
};
Code:
// [...]
/// Create window, painter and application
// [...]
// The UI is quite complex, but extremely easy to write UI in,
// There are local and global regions, the local region is how far
// the item is placed from the global region, the global region
// is usually the parent position or similiar
// Now instead of writing the local and global region for every single item
// you can localy index them next to each other using methods like
// leftOf, rightOf, bottomOf, topOf, allignedOf
// Left and right modify the X axis, whilst bottom and top modify the Y axis
// But if you want the item to left of N, how do you level the Y axis with N?
// Thats where allignedOf comes into play, it will simply allign the axis
// that is not modified with left/right/top/bottom to N.
// Lets create a button
auto button = new dx::Button( );
button->setText( "Button 1" ); // The text
button->setUIID( 1 ); // The UI Identifier.
button->setLocalRegion( { { 15, 45 }, { 125, 30 } } ); // Local region, setting position to 15x45 and size to 125x30 (Note that global/local size is always the same)
button->setFont( painter->defaultFont( ) ); // Lets use the default font, you could create your own one using dx::Font::Create.
button->setStyle( dx::StyleManager( dx::Theme::Dark, dx::Style::Blue ) ); // Set the theme as dark and style as blue.
button->setAllignment( dx::Allignment::Center ); // The allignment of this components text.
// Lets create a checkbox left of button
auto cbx = new dx::Checkbox( );
cbx->setText( "Checkbox" ); // The Text
cbx->setUIID( 2 ); // The UI Identifier
cbx->setLeftOf( button ); // Left of button
cbx->setAllignedOf( button ); // Allign the Y axis
cbx->setSize( { 30, 30 } ); // Set the box size
cbx->setFont( painter->defaultFont( ) ); // Use default font, you dont need to set the font as it will be automatically set to defaultFont if it has not been set.
cbx->setStyle( dx::StyleManager( dx::Theme::Dark, dx::Style::Blue ) ); // Set the theme as dark and style as blue.
cbx->setAllignment( dx::Allignment::Center ); // Allign the text.
// Now create another button BELOW button
auto below = new dx::Button( );
below->setText( "Button 2" ); // The Text
below->setUIID( 3 ); // The UI Identifier
below->setBottomOf( button ); // Left of button
below->setAllignedOf( button ); // Allign the X axis
below->setSize( { 125, 30 } ); // Set the box size
below->setFont( painter->defaultFont( ) ); // Use default font, you dont need to set the font as it will be automatically set to defaultFont if it has not been set.
below->setStyle( dx::StyleManager( dx::Theme::Dark, dx::Style::Blue ) ); // Set the theme as dark and style as blue.
below->setAllignment( dx::Allignment::Center ); // Allign the text.
// Now make sure the window handles the components and draws them at the correct time.
window->HandleComponent( button );
window->HandleComponent( cbx );
window->HandleComponent( below );
// [...]
application->run( );
// [...]
The custom string class contains alot of needed functions for this framework, alot more than the standard string class, hence why I created it.
The FileIO library is almost done, there is some cleaning up needed to be done for Buffer<T>, Token and Tokenizer.
Preview
Dependencies
DirectX 9.
Alot of C++11 and C++14 features-
Credits
Merccy
The repository can be found here, if you find bugs or similiar post it there, not on my skype.
https://bitbucket.org/Yamiez/dxlib/src


![=]](/forum/images/emotions/=].gif)

.......................
x