Btk
Btk Namespace Reference

This header include many useful containers. More...

Namespaces

 FontUtils
 Some useful function about font.
 
 Platform
 Platfrom functions.
 

Classes

struct  _NoSignal
 A type to tell the async don't emit the signal in main thread. More...
 
class  AbstructButton
 Basic button. More...
 
class  AsyncTask
 The AsyncTask. More...
 
struct  Atomic
 
class  BadFunctionCall
 
class  BoxLayout
 
class  Button
 A simple pushbutton. More...
 
class  Canvas
 
struct  Color
 Color structure. More...
 
struct  Connection
 
class  Container
 A Container of Widget. More...
 
struct  CountedBackInserter
 A helper class for count the length we inserted. More...
 
class  Cursor
 Mouse's cursor. More...
 
class  DockWidget
 
struct  DragEvent
 A event about mouse drag. More...
 
struct  DrawCallback
 The Internal Window Draw Callback. More...
 
class  Event
 A base event of all events. More...
 
struct  ExceptionData
 
class  Font
 Font Class. More...
 
struct  FontImpl
 Font Impl. More...
 
class  FontSet
 
struct  FPoint
 
struct  FRect
 
class  FSelectBox
 A Dialog of file selecting. More...
 
struct  FSelectBoxImpl
 
class  Function
 
class  Function< RetT(Args...)>
 
struct  FunctionBase
 
class  Gif
 Gif Decoding class. More...
 
class  GridLayout
 
class  GroupBox
 
struct  HasSlots
 
class  HBoxLayout
 
class  ImageView
 
struct  KeyEvent
 A event about keyboard. More...
 
class  Lable
 Lable widget. More...
 
class  Layout
 
class  Line
 
struct  LockGuard
 Generic LockGuard. More...
 
struct  LockGuard< Texture >
 Lock Guard for Texture locking. More...
 
class  MemBuffer
 
class  MessageBox
 
struct  MessageBoxImpl
 
class  MixerError
 
struct  Module
 
struct  MotionEvent
 A event about mouse motion. More...
 
struct  MouseEvent
 A event about mouse click. More...
 
class  PixBuf
 
struct  PixelFormat
 Pixels format. More...
 
class  PixFmt
 Pixels format detail. More...
 
struct  Point
 
class  PStream
 Pipe stream to or from a process. More...
 
struct  Rect
 a SDL_Rect with methods More...
 
class  RendererError
 
class  ResizeEvent
 
class  RWops
 
class  ScrollBar
 
class  SDLError
 
struct  SetRectEvent
 A event about set Widget rect. More...
 
struct  Signal
 
struct  Signal< RetT(Args...)>
 Btk Signal. More...
 
struct  SignalBase
 
struct  Size
 Size of a Widget or Window. More...
 
class  SpinLock
 
struct  System
 
struct  Task
 
class  TextBox
 
struct  TextBoxInserter
 
class  TextBuffer
 A container of utf16 encoded string for TextEditer. More...
 
struct  TextInputEvent
 A Event of text input. More...
 
class  TextSelection
 
class  Texture
 
struct  Theme
 
class  Thread
 
struct  ThreadPool
 
class  Timer
 
struct  TimerBase
 The Timer Impl. More...
 
struct  TimerInvoker
 
class  VBoxLayout
 
struct  WheelEvent
 
class  Widget
 
struct  WidgetAttr
 
class  Window
 A Basic Window. More...
 
struct  WindowImpl
 
struct  Worker
 
class  XError
 

Typedefs

typedef bool(* ExceptionHandler) (std::exception *)
 
typedef MouseEvent ClickEvent
 
typedef std::runtime_error RuntimeError
 
typedef SDL_Keycode Keycode
 
typedef SDL_Scancode Scancode
 
using MixerMusic = Mixer::Music
 
using MixerAudio = Mixer::Music
 
using MixerChunk = Mixer::Chunk
 
using MixerChannal = Mixer::Channal
 
template<class T >
using lock_guard = LockGuard< T >
 
typedef Point Vec2
 
typedef FPoint FVec2
 

Enumerations

enum  Lauch { Async = 0, Defered = 1 }
 
enum  SystemCursor {
  Arrow, Ibeam, Wait, Crosshair,
  Hand
}
 SystemCursor from SDL_mouse.h. More...
 
enum  ThreadType { AsyncWorker, Renderer, Unknown }
 
enum  FontStyle : int {
  Normal = 0x00, Bold = 0x01, Italic = 0x02, Underline = 0x04,
  Strikethrough = 0x08
}
 FontStyle from SDL_ttf. More...
 
enum  Keymode : Uint16 { Ctrl = KMOD_CTRL, Shift = KMOD_SHIFT }
 
enum  TextureAccess : int { Static, Streaming, Target }
 TextureAccess(same def in SDL_render.h) More...
 
enum  FocusPolicy { None, KeyBoard, Click, Wheel }
 
enum  Align : unsigned int {
  Center, Top, Buttom, Right,
  Left
}
 
enum  Orientation : unsigned int { Vertical = 0, Horizontal = 1, V = Vertical, H = Horizontal }
 

Functions

BTKAPI void DeferCall (void(*fn)(void *), void *data)
 This function will be called in main EventLoop. More...
 
template<class T , class ... Args>
AsyncTask< true, T, Args... > Async (T &&callable, Args ...args)
 Create a Async Task. More...
 
template<class T , class ... Args>
AsyncTask< false, T, Args... > Async (_NoSignal, T &&callable, Args ...args)
 Create a Async Task(No signal) More...
 
void AsyncInit ()
 
void AsyncQuit ()
 
BTKAPI ExceptionHandler SetExceptionHandler (ExceptionHandler)
 
BTKAPI void Exit (int code=EXIT_SUCCESS)
 End the event loop. More...
 
BTKAPI void Init ()
 
BTKAPI void AtExit (void(*fn)(void *), void *data)
 Regitser atexit callback. More...
 
BTKAPI void AtExit (void(*fn)())
 
template<class Callable , class ... Args>
void AtExit (Callable &&callable, Args ...args)
 
BTKAPI void DeferCall (void(*fn)())
 
template<class Callable , class ... Args>
void DeferCall (Callable &&callable, Args ...args)
 
BTKAPI bool IsMainThread ()
 Check is main thread(which call Btk::run) More...
 
BTKAPI bool CouldBlock ()
 Check is not the main thread or Main EventLoop is not running. More...
 
BTKAPI int run ()
 Enter the EventLoop. More...
 
void PushEvent (Event *event, Window &receiver)
 Push event to queue. More...
 
void PushEvent (Event *event, Widget &receiver)
 
bool SendEvent (Event &event, Window &receiver)
 Dispatched event right now. More...
 
bool SendEvent (Event &event, Widget &receiver)
 
void DispatchEvent (const SDL_Event &ev, void *)
 This function was called by System to dispatch our event. More...
 
void BTKAPI throwRuntimeError (const char *)
 
void BTKAPI throwSDLError (const char *)
 
void BTKAPI throwSDLError ()
 
void BTKAPI throwBadFunctionCall ()
 
void BTKAPI throwRendererError (const char *msg)
 
void BTKAPI throwRendererError ()
 
FontStyle operator| (FontStyle s1, FontStyle s2) noexcept
 
FontStyle operator+ (FontStyle s1, FontStyle s2) noexcept
 
FontStyle operator& (FontStyle s1, FontStyle s2) noexcept
 
FontStyle operator+= (FontStyle s1, FontStyle s2) noexcept
 
FontStyle operator|= (FontStyle s1, FontStyle s2) noexcept
 
std::u16string Utf8ToUtf16 (std::string_view utf8)
 
SystemInstance ()
 
int CalculateXByAlign (const Rect &rect, int w, Align v_align)
 Calcaute a area's X in a Rect by alignment. More...
 
int CalculateYByAlign (const Rect &rect, int h, Align h_align)
 Calcaute a area's Y in a Rect by alignment. More...
 
Rect CalculateRectByAlign (const Rect &rect, int w, int h, Align v_align, Align h_align)
 Calcaute a area in a Rect by alignment. More...
 
MotionEvent TranslateEvent (const SDL_MouseMotionEvent &event)
 
MouseEvent TranslateEvent (const SDL_MouseButtonEvent &event)
 
WheelEvent TranslateEvent (const SDL_MouseWheelEvent &event)
 
KeyEvent TranslateEvent (const SDL_KeyboardEvent &event)
 
TextInputEvent TranslateEvent (const SDL_TextInputEvent &event)
 
Keymode operator| (Keymode a, Keymode b)
 
Keymode operator& (Keymode a, Keymode b)
 
bool operator== (Keymode a, Uint16 b)
 
bool operator!= (Keymode a, Uint16 b)
 
void BTKAPI throwMixerError (const char *msg)
 
void BTKAPI throwMixerError ()
 
BTKAPI void LoadModule (std::string_view module_name)
 
BTKAPI bool HasModule (std::string_view module_name)
 
std::string getcwd ()
 Get current working dir. More...
 
std::string getcwd (size_t bufsize)
 
bool exists (std::string_view fname)
 Check the file exists. More...
 
bool chdir (std::string_view path)
 Change the current work dir. More...
 
PStreamoperator>> (PStream &stream, std::string &str)
 
PStreamoperator<< (PStream &stream, std::string_view data)
 
BTKAPI void CreatePipe (RWops &r, RWops &w)
 Create a two binary pipes. More...
 
void throwEmptySignal ()
 
BTKAPI size_t U16Strlen (const char16_t *str)
 
BTKAPI int U16Strcmp (const char16_t *s1, const char16_t *s2)
 
BTKAPI int U16Strcasecmp (const char16_t *s1, const char16_t *s2)
 
BTKAPI size_t Utf16To8 (std::string &, std::u16string_view)
 Convert u16string to u8string. More...
 
BTKAPI size_t Utf8To16 (std::u16string &, std::string_view)
 Convert u8string to u16string. More...
 
BTKAPI bool IsValidUtf8 (std::string_view)
 Check a string is vaid utf8. More...
 
BTKAPI Sint64 ParseHex (std::string_view txt)
 Parse a hex string. More...
 
BTKAPI Sint64 ParseInt (std::string_view txt)
 
template<class T , auto Alloc = std::malloc>
T * Memdup (const T *ptr, size_t size)
 A helper template for dup memory. More...
 
template<class T , auto Alloc = std::malloc>
T * Memdup (const T *ptr)
 A helper template for dup memory. More...
 
template<class T , auto Alloc = std::malloc>
T * Memdup (const T &ref)
 
std::string Utf16To8 (std::u16string_view utf16)
 Convert utf16 string to utf8 strubg. More...
 
std::u16string Utf8To16 (std::string_view utf8)
 Convert utf8 string to utf16 strubg. More...
 
template<class T , class U >
event_cast (U &&u)
 
int vscprintf (const char *fmt, va_list varg)
 
std::string get_typename (const std::type_info &info)
 Get the typename of a type. More...
 
template<class T >
std::string get_typename (const T *ptr)
 
std::string cformat (const char *fmt,...)
 Using c-syle formatting. More...
 
void cformat (std::string &str, const char *fmt,...)
 Append text to the string. More...
 
SDL_SystemCursor TranslateCursor (SystemCursor cursor)
 
MemBufferGetMemBuffer (SDL_RWops *ctxt)
 
std::ostream & operator<< (std::ostream &str, const MemBuffer &buf)
 
Uint32 SDLCALL TimerRun (Uint32, void *timerbase)
 

Variables

constexpr _NoSignal NoSignal {}
 

Detailed Description

This header include many useful containers.

Enumeration Type Documentation

◆ FontStyle

enum Btk::FontStyle : int
strong

FontStyle from SDL_ttf.

◆ SystemCursor

enum Btk::SystemCursor
strong

SystemCursor from SDL_mouse.h.

◆ TextureAccess

enum Btk::TextureAccess : int
strong

TextureAccess(same def in SDL_render.h)

Function Documentation

◆ Async() [1/2]

template<class T , class ... Args>
AsyncTask<true,T,Args...> Btk::Async ( T &&  callable,
Args ...  args 
)

Create a Async Task.

Template Parameters
TThe callable type
ArgsThe args type
Parameters
callableThe callable
argsThe args
Returns
AsyncTask object

◆ Async() [2/2]

template<class T , class ... Args>
AsyncTask<false,T,Args...> Btk::Async ( _NoSignal  ,
T &&  callable,
Args ...  args 
)

Create a Async Task(No signal)

Template Parameters
TThe callable type
ArgsThe args type
Parameters
nosignalA flag of nosignal
callableThe callable
argsThe args
Returns
AsyncTask object(No signal)

◆ AtExit()

void Btk::AtExit ( void(*)(void *)  fn,
void *  data 
)

Regitser atexit callback.

Parameters
fnCallback function
dataUser data

◆ CalculateRectByAlign()

Rect Btk::CalculateRectByAlign ( const Rect rect,
int  w,
int  h,
Align  v_align,
Align  h_align 
)
inline

Calcaute a area in a Rect by alignment.

Parameters
rectThe Rect
warea w
harea h
v_alignV alignment
h_alignH alignment
Returns
aligned rect empty() if failed

◆ CalculateXByAlign()

int Btk::CalculateXByAlign ( const Rect rect,
int  w,
Align  v_align 
)
inline

Calcaute a area's X in a Rect by alignment.

Parameters
rectThe rect
wThe W
v_alignV alignment
Returns
-1 if failed

◆ CalculateYByAlign()

int Btk::CalculateYByAlign ( const Rect rect,
int  h,
Align  h_align 
)
inline

Calcaute a area's Y in a Rect by alignment.

Parameters
rectThe rect
hThe height
h_alignH alignment
Returns
-1 if failed

◆ cformat() [1/2]

std::string Btk::cformat ( const char *  fmt,
  ... 
)
inline

Using c-syle formatting.

Parameters
fmtThe c-style fmt string
...The args you want to format
Returns
std::string

◆ cformat() [2/2]

void Btk::cformat ( std::string &  str,
const char *  fmt,
  ... 
)
inline

Append text to the string.

Parameters
strThe container
fmtThe c-style fmt string
...The args you want to format

◆ chdir()

bool Btk::chdir ( std::string_view  path)
inline

Change the current work dir.

Parameters
pathThe work dir
Returns
true
false

◆ CouldBlock()

bool Btk::CouldBlock ( )

Check is not the main thread or Main EventLoop is not running.

Returns
true on we can do sth blcok the thread

◆ CreatePipe()

void Btk::CreatePipe ( RWops r,
RWops w 
)

Create a two binary pipes.

Parameters
r
w

◆ DeferCall()

void Btk::DeferCall ( void(*)(void *)  fn,
void *  data 
)

This function will be called in main EventLoop.

Parameters
fnThe function you want to call
dataUser data

◆ DispatchEvent()

void Btk::DispatchEvent ( const SDL_Event &  ev,
void *   
)

This function was called by System to dispatch our event.

Parameters
evSDL_Event structure

◆ exists()

bool Btk::exists ( std::string_view  fname)
inline

Check the file exists.

Parameters
fnameThe filename
Returns
true
false

◆ Exit()

void Btk::Exit ( int  code = EXIT_SUCCESS)

End the event loop.

Parameters
codeThe exit code

◆ get_typename()

std::string Btk::get_typename ( const std::type_info &  info)
inline

Get the typename of a type.

Note
It usually used in debugging
Parameters
infoThe typeinfo
Returns
The name of the typeinfo(no demangled)

◆ getcwd()

std::string Btk::getcwd ( )
inline

Get current working dir.

Returns
The current working dir

◆ IsMainThread()

bool Btk::IsMainThread ( )

Check is main thread(which call Btk::run)

Returns
true,if is the main thread

◆ IsValidUtf8()

bool Btk::IsValidUtf8 ( std::string_view  input)

Check a string is vaid utf8.

◆ Memdup() [1/2]

template<class T , auto Alloc = std::malloc>
T* Btk::Memdup ( const T *  ptr,
size_t  size 
)

A helper template for dup memory.

Template Parameters
TThe memory block type
AllocThe Allocator
Parameters
ptrSource Pointer
sizeThe memory block size
Returns
The new memory block

◆ Memdup() [2/2]

template<class T , auto Alloc = std::malloc>
T* Btk::Memdup ( const T *  ptr)

A helper template for dup memory.

Template Parameters
TThe memory block type
AllocThe Allocator
Parameters
ptrSource Pointer
Returns
The new memory block

◆ operator<<()

PStream& Btk::operator<< ( PStream stream,
std::string_view  data 
)
inline
Returns
PStream& The stream ref

◆ operator>>()

PStream& Btk::operator>> ( PStream stream,
std::string &  str 
)
inline
Parameters
streamThe stream
strThe string ref
Returns
PStream& The stream ref

◆ ParseHex()

Sint64 Btk::ParseHex ( std::string_view  txt)

Parse a hex string.

Parameters
txtThe hex text
Returns
Sint64,INT64_MAX on error

◆ PushEvent()

void Btk::PushEvent ( Event event,
Window receiver 
)

Push event to queue.

Parameters
eventThe event pointer we want to send
receiverThe receiver

◆ run()

int Btk::run ( )

Enter the EventLoop.

Returns
0 if succeed

◆ SendEvent()

bool Btk::SendEvent ( Event event,
Window receiver 
)

Dispatched event right now.

Parameters
receiver
Returns
true - If the receiver processed it
false - If the receiver unprocessed it

◆ Utf16To8() [1/2]

size_t Btk::Utf16To8 ( std::string &  ret,
std::u16string_view  input 
)

Convert u16string to u8string.

Returns
The string length we inserted

◆ Utf16To8() [2/2]

std::string Btk::Utf16To8 ( std::u16string_view  utf16)
inline

Convert utf16 string to utf8 strubg.

Parameters
utf16Utf16 encoded string
Returns
Utf8 encoded string

◆ Utf8To16() [1/2]

size_t Btk::Utf8To16 ( std::u16string &  ret,
std::string_view  input 
)

Convert u8string to u16string.

Returns
The string length we inserted

◆ Utf8To16() [2/2]

std::u16string Btk::Utf8To16 ( std::string_view  utf8)
inline

Convert utf8 string to utf16 strubg.

Parameters
utf8Utf8 encoded string
Returns
Utf16 encoded string