STK - Simple ToolKit | Documentation | Download | Screenshots | Links | Contact

STK v2.0 documentation

(2006-03-28)
by Dusan Halicky
dvh.tosomja@post.sk

Index

  • 1. Introduction
  • 1.1 About STK
  • 1.2 Requirements
  • 1.3 Compilation
  • 1.4 Compatibility
  • 1.5 Author
  • 2. Components
  • 2.1 StkComponent
  • 2.2 StkWindow
  • 2.3 StkLabel
  • 2.4 StkButton
  • 2.5 StkRadiobutton
  • 2.6 StkCheckbox
  • 2.7 StkImage
  • 2.8 StkSlider
  • 2.9 StkShortcut
  • 2.10 StkMenuitem
  • 2.11 StkEdit
  • 2.12 StkPanel
  • 3. Other parts
  • 3.1 Constants
  • 3.2 Functions
  • 3.3 Display
  • 3.4 Keyboard
  • 3.5 Mouse
  • 3.6 Fonts
  • 3.7 Colors
  • 3.8 Initialization
  • 3.9 Bitmaps
  • 3.10 Graphics
  • 3.11 Callbacks
  • 3.12 Components
  • 4. Examples
  • 4.1 Hello world
  • 5. Appendix
  • 5.1 Table of component's constructors
  • 1. Introduction

    This is main and official documentation of the STK project. All materials related to the STK included this documentation is free and open. You can redistrubute it. STK is distributed under GNU GPL licence (see file doc/COPYING for more details).

    Terms and abbreviations:

  • STK - Simple ToolKit, version v2.0 (when not mentioned version)
  • toolkit - set of components such as label, button and rest of the application framework
  • X - X Window System
  • 1.1 About STK

    STK is a shortcut for Simple ToolKit. It is a very simple, light and fast toolkit written in C/C++ language for X Window System. STK is based on the the Xlib, the basic X library. STK contain few basic components such as label, button, checkbox and so on.

    Main aims of STK are:

  • To be a C/C++ toolkit for X Window System under Linux
  • To be small and easy to understand
  • To be simple for using in programs for programmers
  • To be ergonomic for users
  • To be fast and light and not fritt with system resources
  • To be well documented
  • Not to be forwad nor backward compatible at any costs
  • 1.2 Requirements

  • X Window System
  • Xlib library (X.h, Xlib.h, Xutil.h, keysymdef.h)
  • xpm library or Imlib library
  • GNU C Compiler (with c++ support)
  • 1.3 Compilation

    Currently, STK is distributed in a single tarball which contain directory "stksrc" which contain STK itself. There is shell script named "_make_libstk". Run it anytime you want to create static STK library "libstk.a". Then, when you compilig your project, whereever it is placed, you will need to tell compiler where to search for the stk library (assume that there is yourapp directory with yourapplication.cc and stksrc directory).

    If you want to use Imlib (PNG, JPEG, GIF, XPM) insted of libxpm (XPM), you must define the STK_IMLIB_USED directive in the stk_constants.h this way:

    #define STK_IMLIB_USED

    STK application compilation example:

    gcc -o yourapplication yourapplication.cc -L./stksrc/ -lstk -lXpm -lXext -lImlib

    where:

  • -L./stksrc/ - path to STK (whole stksrc directory)
  • -lstk - tell compiler to include STK library /stksrc/libstk.a
  • Note: Running "./stksrc/_make_libstk" before compilation of your application is highly recomended.

    1.4 Compatibility

    STK was tested successfully on this platforms:

  • Fedora Core 4, kernel 2.6.11, gcc 4.0.0, bash 3.0.0, X Window System v6.8.2 (X11R6)
  • RedHat 7.2, kernel 2.4.7, gcc 2.96, X Window System v??? (X11R6)
  • SuSE linux, kernel 2.4.x, gcc 3.x, (only compiled)
  • Gentoo linux (compiled but no display images!)
  • 1.5 Author

    Original author of STK and this documentation is me, Dusan Halicky (dvh.tosomja@post.sk). Feel free to contact me via email if you have any question about STK or if you have any suggestion or ide how to improve STK, or if you want to participate on STK development. Contact me also if you find a bug in the STK. Finaly, if you have lots of money and you want to sponsor future development of STK send any small financial contribution. Thanks.

    Dusan Halicky jr.
    Wuppertalska 41
    04023 Kosice
    Slovakia

    2. Components

    Every single visual or invisible component in STK is inherited from basic stk component called StkComponent. It contain most basic attributes and methods which use all components. Every real component has theese attributes and methods inderited from StkComponent and has also other methods and attributes related only to that real component.

    2.1 StkComponent

    Description

    StkComponent is basic component, it is ancestor of all components.

    Constructor

    StkComponent (Window parwin, int x, int y, int w, int h, int borderwidth, int bordercolor, int bgcolor, unsigned int eventmask);

    Where:

  • parwin - parent component's window
  • x, y - position of the window in pixels from top-left corner of the parent component's window (parwin)
  • w, h - size of the component, must be nonzero
  • borderwidth - width of the component border in pixels, additive to (w,h), may be 0
  • bordercolor - index of color for the border in local palette
  • bgcolor - index of the window's color in local palette
  • eventmask - event mask for the window, may be logically or-ed by one or more of the following:
  • KeyPressMask, KeyReleaseMask - if you want to catch key press/release event
  • ButtonPressMask, ButtonReleaseMask - mouse button press/release event
  • PointerMotionMask - movement of the mouse cursor above component
  • ExposureMask - when covered component (by other window) is exposed and need redraw
  • EnterWindowMask, LeaveWindowMask - when mouse pointer move over component first time or if pointer leave window
  • StructureNotifyMask, SubstructureNotifyMask, PropertyChangeMask, FocuseChangeMask - recomended, internally required for some configuration events
  • Interface

    typeattributeGetSetDescription
    WindowwindowGetWindow()-ID of the window, an rectangle described component, used for drawing and handling all events
    GCgcGetGC()-ID of window's graphics context, used for drawings on component's window
    StkComponent*previousGetPrevious()SetPrevious(StkComponent *p)previous component in the bidirectional linked list of components
    StkComponent*nextGetNext()SetNext(StkComponent *p)next component in the bidirectional linked list of components
    intleft, topGetPosition(int *x,*y)
    GetLeft(),GetTop()
    SetPosition(int x,y)position from left-top corner of parent component (window)
    intwidth, heightGetSize(int *w,*h)
    GetWidth(),GetHeight()
    SetSize(int w,h)size of component
    intborder_width--border thicknes in pixels, 0 for no border
    intborder_color--color indexes of component's border
    intbackground_colorGetColor()SetColor(int)color indexes of component's window
    intevent_mask, event_mask_old--event mask for window, event_mask_old is for remember original mask when component is disabled but not removed from components list
    boolfocusGetFocus()SetFocus(bool f)Get or set focus to the component, component which has focus lost it and focus will be passed to this component, both component will be redrawn, only component which has focus can receiving keyboard events
    boolfocusableGetFocusable()SetFocusable(bool fa)true if component can get focus (e.g. button), false otherwise (e.g. label)
    KeySymshortcutGetShortcut()SetShortcut(KeySym s)shortcut key for the component, keysyms are defined in keysymdef.h
    unsigned intmodifiersGetModifiers()SetModifiers(uint m)modifier keys such as CTRL, ALT, ... see constants
    boolvisibleGetVisible()Show(),Hide()true if component is visible on the screen, components are usually automatically displayed after creation
    boolresizeableGetResizeable()SetResizeable(bool r)true if component can be resized, most important for windows
    intpenfgcolor-SetPenForeground(int i)color for the line drawing on the component's window
    boolenabledGetEnabled()SetEnabled(bool b)true if component is enabled (e.g. button can be pressed)
    StkBasicCallback*callback-CreateCallback(StkBasicCallback* bcb)component's callback function, pointer to function which will be called after component is activated (e.g. button is pressed)
    inttag-SetTag(int i)User-purpose ineger variable called "tag"

    Events

    EventAttributesDescription
    OnExpose-when component need to be redrawn
    OnChangeFocusbool fwhen component get (f=true) or lost (f=false) focus, automatical redraw is NOT provided
    OnMouseDownint x, int y, int button, int state when user click with mouse onto component at position (x,y) using mouse button button which has state state
    OnMouseUpwhen user release mouse button above component
    OnMouseMovewhen user move with mouse cursor above component
    OnMouseOverwhenever user first time move the cursor above component
    OnMouseOutwhenever user left the component with mouse cursor
    OnKeyPressKeySym keysym, unsigned int mods, char *name, int namesize, bool *change_focus when user press keyboard key if component has a focus
    OnKeyReleaseKeySym keysym, unsigned int mods, char *name, int namesize, bool *change_focus when user release key if component has focus
    OnShortcutKeySym keysym, unsigned int mods, char *name, int namesize when user press shortcut key specified to this component, no matter if component has or has not focus
    OnClose-when component is closed (no longer active), it is most important for windows
    OnShow-when component is shown first time
    OnHide-when component is hidden
    OnResizeint w, int h when component is resized, (w,h) is new size, most important for windows

    Notes:

  • not all real components use all these events!
  • change_focus in OnKeyPress/OnKeyRelease indicate if the currently pressed/release key will change focus. Variable change_focus CAN BE modified inside OnKeyPress/OnKeyRelease event. Some components (e.g. memo) may want to block focus change on som keys (e.g. TAB in memo will be used like normal TAB but not for focus changing)
  • Methods

    MethodAttributesDescription
    CreateWindow parwin, int x, int y, int w, int h, int borderwidth, int bordercolor, int bgcolor, unsigned int eventmaskauxiliary method, contain most commom part of constructor for components which is often called (create window, set up event mask), attributes is the same as StkComponent's constructor
    Redraw-this draw component on the screen (lines, strings, ...), it usually call one or more methods from shapes.
    DrawLineint x1,y2,x2,y2draw line on the component's window with selected pen color
    bool IsFocusable-return true if component has focusable=true and component is enabled (disabled component can't be focused)
    CallBackObject*,&Type::Method Create callback for Object->Method, e.g. button1->CallBack(dialog1,&TMyDialog::Close);

    2.2 StkWindow

    Description

    StkWindow is descendant of StkComponent but has special position in a set of components because it may contain other components. Every other real component has StkWindow as parent in their own constructor!

    Constructor

    StkWindow (Window parwin, int x, int y, int w, int h, const char *cap);

    Where:

  • parwin - parent component's window
  • x, y, w, h - position and size of the window in pixels from top-left corner of parent window (parwin)
  • *cap - caption, string which will be displayed at the top of window and in the taskbar icon
  • Interface

    typeattributeGetSetDescription
    char*caption-SetCaption(const char *cap) set the window's caption, memory will be reallocated automaticaly
    boolclosedGetClosed()Close()true if component was closed by Close() or by user (hit [X] button on the window's top rail)
    StkComponents*components--interface to bidirectional linked list of components in this window, see components

    Events

    OnExpose, OnChangeFocus, OnMouseDown, OnMouseUp, OnMouseMove, OnMouseOver, OnMouseOut, OnKeyPress, OnKeyRelease, OnShortcut, OnClose, OnShow, OnHide, (OnResize) ... see StkComponent for details

    Methods

    MethodAttributesDescription
    Minimize-minimize the window to the taskbar (depend on window manager implementation)

    2.3 StkLabel

    Description

    StkLabel is most basic visual component. It provide only simple plain text in one line, but it will be automatically redrawn when required so programer must not take care of redrawing. It also may have associated shortcut key. Because label is no focusable component, it will forward focus to another component specified in focus_control attribute. Label can be also clicked by mouse.

    Constructor

    StkLabel (StkWindow *parwin, int x, y, w, h, char *cap, StkComponent *focuscontrol=NULL);

    Where:

  • parwin - parent component's window (StkWindow)
  • x, y, w, h - position and size of component
  • *cap - caption of component, string, will be displayed as simple text, may be encoded by & to set up shortcut key (e.g. "H&ello" will set shortcut to "a" with ALT modifier - Alt+a, "&Hello" will set shortkut to Alt+h but NOT Alt+H)
  • focuscontrol - another (but focusable) component which will receive focus when user call label's shortcut or click onto label, this paremeter may be omitted
  • Interface

    typeattributeGetSetDescription
    char*caption-SetCaption(char *cap, bool redraw=true) - set the label's caption and automatically redraw it when it is changed

    Events

    OnExpose, OnMouseDown, OnMouseUp, OnMouseMove, OnMouseOver, OnMouseOut, OnShortcut, OnClose ... see StkComponent for details

    Methods

    MethodAttributesDescription
    Redraw-redraw the label

    2.4 StkButton

    Description

    StkButton is a basic clickable component. It seems like rectangular area with the label inside. User can click on it with a mouse cursor or take a focus to it with TAB or Ctrl+TAB key. If button has a focus, it may be pressed by Enter or Spacebar key. If button is disabled, it can NOT be pressed nor focused. When button is pressed, a callback is called. Button can also has "&" encoded label.

    Constructor

    StkButton (StkWindow *parwin, int x, int y, int w, int h, char *cap);

    Where:

  • parwin - parent component's window (StkWindow)
  • x, y, w, h - position and size of component
  • *cap - caption of component, string, will be displayed as simple text, may be encoded by & to set up shortcut key (e.g. "H&ello" will set shortcut to "a" with ALT modifier - Alt+a, "&Hello" will set shortkut to Alt+h but NOT Alt+H)
  • Interface

    typeattributeGetSetDescription
    char*caption-SetCaption(char *cap)Sets the button's caption
    boolpressed--true if button is pressed (down)
    intunderscore_start--position if the underscore ("&" encoded label)
    intunderscore_length--length of the underscore

    Events

    OnExpose, OnChangeFocus, OnMouseDown, OnMouseUp, OnMouseMove, OnMouseOver, OnMouseOut, OnKeyPress, OnKeyRelease, OnShortcut, OnClose, OnShow, OnHide ... see StkComponent for details

    Methods

    MethodAttributesDescription
    Redraw-draw the button on the screen

    2.5 StkRadiobutton

    Description

    StkRadiobutton is component which seems like label but has small rectangle area in front of it. There is small picture indicated where radiobutton is checked or not. Label can be encoded, radiobutton can be disabled. Radiobutton is focusable component, it's state can be changed with enter or spacebar when radiobutton has focus.

    Constructor

    StkRadiobutton (StkWindow *parwin, int x, y, w, h, char *cap, int grp = 0, bool chckd = false);

    Where:

  • parwin - parent component's window (StkWindow)
  • x, y, w, h - position and size of component
  • *cap - caption of component, string, will be displayed as simple text, may be encoded by & to set up shortcut key (e.g. "H&ello" will set shortcut to "a" with ALT modifier - Alt+a, "&Hello" will set shortkut to Alt+h but NOT Alt+H)
  • grp - group index, few radiobuttons can be grouped into groups, only one radiobutton can be checked in the group
  • chckd - true if radiobutton is checked
  • Interface

    typeattributeGetSetDescription
    boolcheckedGetChecked()SetChecked() get the state of checked attribute or set checked attribute to true, radiobutton cannot be unchecked!
    intgroupGetGroup()-only one radiobutton in a set of radiobuttons with the same group can be checked

    Events

    OnChangeFocus, OnMouseDown, OnKeyPress, OnShortcut ... see StkComponent for details

    Methods

    MethodAttributesDescription
    Redraw-draw the component on the screen

    Inherited

    StkRadiobutton is descendant of StkLabel.

    2.6 StkCheckbox

    Description

    StkCheckbox is similar to StkRadiobutton but any checkbox can be checked at any time, because checkboxes are not divided into groups.

    Constructor

    StkCheckbox (StkWindow *parwin, int x, y, w, h, char *cap, bool chckd=false);

    Where:

  • parwin - parent component's window (StkWindow)
  • x, y, w, h - position and size of component
  • *cap - caption of component, string, will be displayed as simple text, may be encoded by & to set up shortcut key (e.g. "H&ello" will set shortcut to "a" with ALT modifier - Alt+a, "&Hello" will set shortkut to Alt+h but NOT Alt+H)
  • chckd - true if checkbox is checked
  • Interface

    typeattributeGetSetDescription
    boolcheckedGetChecked()SetChecked(bool b) true if checkbox is checked, false if not

    Events

    OnChangeFocus, OnMouseDown, OnKeyPress, OnShortcut ... see StkComponent for details

    Methods

    MethodAttributesDescription
    Redraw-draw component on the screen

    Inherited

    StkCheckbox is descendant of StkLabel.

    2.7 StkImage

    Description

    StkImage is basic picture component. It can contain picture (bitmap), STK support two ways of image handlings. First way is only XPM support via libxpm. Second way is use of Imlib library by STK_IMLIB_USED directive in stk_constants.h. Imlib support PNG, JPEG, GIF, XPM and few others formats. The XPM images can be included in the source code or can be in external file, other files must be in external files.

    Constructor

    StkImage (StkWindow *parwin, int x, y, char **data); StkImage (StkWindow *parwin, int x, y, char *fname);

    Where:

  • parwin - parent component's window (StkWindow)
  • x, y - position of component
  • **data - pointer to XPM data structure included in the source code (by #include "images/image.xpm")
  • *fname - string which contain filename of the image ("images/image.xpm")
  • Interface

    typeattributeGetSetDescription
    StkBitmap*bmp--bitmap which store the image

    Events

    OnExpose, OnMouseDown, OnMouseUp, OnMouseMove, OnMouseOver, OnMouseOut ... see StkComponent for details

    Methods

    MethodAttributesDescription
    Redraw-draw the image on the screen

    2.8 StkSlider

    Description

    StkSlider is component for setting numerical values (such as audio volume) with a mouse cursor or with a keyboard arrow keys (it is focusable).

    Constructor

    StkSlider (Window parwin, int x, y, len, orient, val, rang, incr);

    Where:

  • parwin - parent component's window (StkWindow)
  • x, y - position of component
  • len - pixel length of the slider (i.e. height for vertical and width for horizontal slider)
  • orient - slider orientation (STK_SLIDER_HORIZONTAL, STK_SLIDER_VERTICAL)
  • val - initial value of the slider (from left or top)
  • rang - range for the slider's value
  • incr - increment for the value, important only for keyboard adjustments
  • Interface

    typeattributeGetSetDescription
    int valueGetValue SetValue(int v) set the value from left or from top
    int valueGetValueR SetValueR(int v) set the value "Reversaly" so from right or bottom

    Events

    OnExpose, OnChangeFocus, OnMouseDown, OnMouseUp, OnMouseMove, OnMouseOver, OnMouseOut, OnKeyPress, OnKeyRelease, OnShortcut ... see StkComponent for details

    Methods

    MethodAttributesDescription
    Redraw-draw component on the screen

    2.9 StkShortcut

    Description

    StkShortcut is nonvisual component which call the callbach function when user hit the specific keyboard key with selected modifiers.

    Constructor

    StkShortcut (StkWindow *parwin, KeySym key, int mods, StkComponent *focuscontrol = NULL);

    Where:

  • parwin - parent component's window
  • key - shortcut key, see keysymdef.h for propper key codes (e.g. XK_F1, XK_space, XK_a, XK_B, XK_Escape, XK_Delete, ...)
  • mods - shortcut modifiers (e.g. STK_MODIFIER_ALT, see stk_constants)
  • Interface

    typeattributeGetSetDescription
    - - - - -

    Events

    OnShortcut ... see StkComponent for details

    Methods

    MethodAttributesDescription
    ---

    2.10 StkMenuitem

    Description

    StkMenuitem is similar to button but it become blue when mouse is over it and it has no frame! Typical usage is in the popup and main menu. However, mainmenu and popupmenu component is not yet implemented in STK v2.0 alpha 3.

    Constructor

    StkMenuitem (StkWindow *parwin, left, top, width, height, caption, enabled=true);

    Where:

  • parwin - parent component's window
  • left, top - position of the menu item
  • width, height - size of the menu item
  • caption - caption of the menu item, should be & encoded for shortcuts, if "-" it will be replaced with horizontal line
  • enabled - if true (default), menu item can be clicked, else it will be gray and disabled
  • Interface

    typeattributeGetSetDescription
    - - - - -

    Events

    OnClick ... see StkComponent for details

    Methods

    MethodAttributesDescription
    ---

    2.11 StkEdit

    Description

    StkEdit is basic component for text input in STK. However, in STK v2.0 alpha 3 it is not yet fully implemented. It is usable only when text do not exceed width of edit.

    Constructor

    StkEdit (StkWindow *parwin, left, top, width, height, char* text);

    Where:

  • parwin - parent component's window
  • left, top - position
  • width, height - size
  • text - initial text in edit
  • Interface

    typeattributeGetSetDescription
    - - - - -

    Events

    OnClick ... see StkComponent for details

    Methods

    MethodAttributesDescription
    char* GetText()-return the text stored in the edit

    2.12 StkPanel

    Description

    StkPanel is basic component for placing other component. Now, it has only border feature. Other things will be implemented later!

    Constructor

    StkPanel (StkWindow *parwin, left, top, width, height);

    Where:

  • parwin - parent component's window
  • left, top - position
  • width, height - size
  • Interface

    typeattributeGetSetDescription
    TPanelBorderborderGetBorder()SetBorder(value)Border specify the appearance of panel's border:
    pbNone, pbSingle, pbLowered, pbRaised, pbPressed, pbRelief

    Events

    see StkComponent for details

    Methods

    MethodAttributesDescription
    ---

    3. Other parts

    In this section will be described other part of the STK (non-components) which make core of the STK.

    3.1 Constants

    Files stk_constants.h and stk_constants.cc contain most basic constants of the STK, such as debugging constants (STK_something_DEBUG, used in #ifdef directive), mouse button constants, keyboard constants (modifiers), and some other STK constants.

    3.2 Functions

    Files stk_functions.h and stk_functions.cc contain some common and usefull functions.

    Functions

    TypeFunction NameAttributesDescription
    -stk_sleeplong mssleep for [ms] miliseconds from 0 up to 35 minutes
    KeySymstk_decode_caption_shortcutchar* captiondecode caption and return KeySym encoded by this caption with & character, e.g. &Hello will return XK_h (mean "h")
    char*stk_decode_captionchar* caption, char* c, char** cap_prefdecode &encoded caption, return encoded character (e.g. "h") in *c and allocate and set caption prefix (from caption start to first & character) into cap_pref string

    Examples

    stk_sleep(1000); 					// sleep for 1s
    KeySym K = stk_decode_caption_shortcut("&Hello"); 	// set variable K to value XK_h
    char c, *cp;						// local variables 
    cap = stk_decode_caption("Butt&on", &c, &cp);		// decode caption
    
    After last function call, variables will have these values: cap = "Button", c = "o", cp = "Butt"

    3.3 Display

    Files stk_display.h and stk_display.cc contain function and variables related to visual display (screen), such as handle for display and it's appearance, initialization functions and more.

    Functions

    TypeFunction NameAttributesDescription
    Display*stk_display_openchar* display_nameopen display specified by name, default is NULL or ":0.0"
    -stk_display_init-initialize stk_display
    -stk_display_done-close stk_display

    Variables

    TypeIdentifierDescription
    Display*stkdisplayhandle to the display, all X functions calls need this
    intstkdisplay_screenhandle for main screen of the display
    intstkdisplay_width, stkdisplay_heightsize of the display (screen)
    Windowstkdisplay_roothandle for the main (root) window ("desktop")

    Examples

    stkdisplay = stk_display_open(0);
    

    3.4 Keyboard

    Files stk_keys.h and stk_keys.cc contain keyboard handling routines and variables.

    Functions

    TypeFunction NameAttributesDescription
    -stk_keys_updateXKeyEvent ke, bool pressedupdate all keyboard variables, such as modifiers

    Variables

    TypeIdentifierDescription
    KeySymstkkeys_keysymcurrently pressed keycode, see keysymdef.h for details
    intstkkeys_modifiercurrent modifiers (Shift, Alt, ...)
    intstkkeys_statecurrent modifiers
    char*stkkeys_namekey string name, e.g. "Space", "A", "b", ...
    intstkkeys_namesizelength of the stkkeys_name
    boolstkkeys_ctrl, stkkeys_ctrl_l, stkkeys_ctrl_rCTRL modifiers (any, left, right)
    boolstkkeys_alt, stkkeys_alt_l, stkkeys_alt_rALT modifiers (any, left, right)
    boolstkkeys_shift, stkkeys_shift_l, stkkeys_shift_rSHIFT modifiers (any, left, right)
    boolstkkeys_meta, stkkeys_meta_l, stkkeys_meta_rMETA modifiers (any, left, right)

    3.5 Mouse

    Files stk_mouse.h and stk_mouse.cc contain mouse related variables and functions.

    Functions

    TypeFunction NameAttributesDescription
    -stk_get_mouse_root_position-get the mouse position in root window now and set stk_mouse_root_* variables

    Variables

    TypeIdentifierDescription
    intstkevent_root_x, stkevent_root_ymouse cursor position in root window

    Examples

    stk_get_mouse_root_position();
    if (stkevent_root_x >= stkdisplay_width - 10)
      printf("Right screen edge!\n");
    

    3.6 Fonts

    Files stk_font.h and stk_font.cc contain interface to the default STK font.

    Constants

    NameDescription
    STK_FONT_DEFAULTfont name for default font
    STK_FONT_BOLDfont name for default bold font
    STK_FONT_ITALICfont name for default italic font

    Functions

    TypeFunction NameAttributesDescription
    -stk_font_init-initialize default font
    -stk_font_done-release default font
    -stk_font_clip_rectXFontStruct* fs, char* s, int *w, *h, bool decode=falsecalculate clipping rectangle for string "s", if decode is true decode string first, return width and height in *w, *h
    XFontStruct*stk_font_loadchar* fontnameload font into stkfont variable, font is specified by fontname string

    Variables

    TypeIdentifierDescription
    XFontStruct*stkfontcurrent (default) font
    intstkfont_corbaseline correction for last loaded font

    Examples

    stkfont = stk_font_load(STK_FONT_DEFAULT);
    

    3.7 Colors

    Files stk_colors.h and stk_colors.cc contain default STK palette.

    Constants

    NameDescription
    STK_COLOR_BLACKblack color (black)
    STK_COLOR_WHITEwhite color (white)
    STK_COLOR_DARK_GRAYdark gray color (dark gray)
    STK_COLOR_GRAYgray color (gray)
    STK_COLOR_LIGHT_GRAYlight gray color (light gray)
    STK_COLOR_REDred color (red)
    STK_COLOR_GREENgreen color (green)
    STK_COLOR_BLUEblue color (blue)
    STK_COLOR_VERY_LIGHT_GRAYvery light gray color (very light gray)
    STK_COLOR_YELLOWyellow color (yellow)
    STK_COLOR_MAGENTAmagenta color (magenta)
    STK_COLOR_CYANcyan color (cyan)
    STK_COLOR_DARK_REDdark red color (dark red)
    STK_COLOR_DARK_MAGENTAdark magenta color (dark magenta)
    STK_COLOR_DARK_BLUEdark blue color (dark blue)
    STK_COLOR_DARK_CYANdark cyan color (dark cyan)
    STK_COLOR_DARK_GREENdark green color (dark green)
    STK_COLOR_DARK_YELLOWdark yellow color (dark yellow)
    STK_COLOR_WINDOWwindow color (window)
    STK_COLOR_ACTIVEactive color (active)
    STK_COLOR_LASTlast used color (with highest number)
    STK_COLORS_COUNTnumber of colors (last color + 1)

    Functions

    TypeFunction NameAttributesDescription
    -stk_colors_init-allocate and set up all colors defined in stkcolors[] array
    -stk_colors_done-release colors

    Variables

    TypeIdentifierDescription
    XColorstkcolors[STK_COLORS_COUNT]array of colors

    Examples

    XColor color = stkcolors[STK_COLOR_RED].pixel;
    

    3.8 Initialization

    Files stk_init.h and stk_init.cc contains STK initialization functions and some variables.

    Functions

    TypeFunction NameAttributesDescription
    -stk_init-initialize STK, must be first STK call in your application
    -stk_done-release STK, must be last STK call in your application

    Variables

    TypeIdentifierDescription
    AtomWM_PROTOCOLS, WM_DELETE_WINDOWwindow manager atoms used for correct close window
    Windowstkmessage_windowcontain handle of window (i.e. component) which receive the event
    Atomstkmessage_atom, stkmessage_stateadditional window event attributes
    boolstkmessage_quittrue if main window is getting close, use your_window->Closed() instead

    Examples

    stk_init();
    ... any STK functions
    stk_done();
    

    3.9 Bitmaps

    Files stk_bitmap.h and stk_bitmap.cc contain basic image handling object. If is used libxpm, only XPM images are supported. If is used Imlib, PNG, GIF, JPEG and XPM images are supported. If you only want to draw one picture on the window, use StkImage instead.

    Constructor

    StkComponent (Window parwin, char **data);
    StkComponent (Window parwin, char *fname);

    Where:

  • parwin - parent component's window
  • **data - pointer to XPM data structure included in source code (#include "image.xpm")
  • *fname - file name of the image on the disk
  • Interface

    typeattributeGetSetDescription
    Pixmap, GCpixmap, mask, GCbool Load(char **data),bool Load(char *fname)-load image from source code or from external file, return true on success
    intwidthGetWindth()-get loaded bitmap width
    intheightGetHeight()-get loaded bitmap height

    Events

    None, not a component!

    Methods

    MethodAttributesDescription
    Loadchar **dataload image from source code (XPM must be include in source code, e.g. #include "xpm/image.xpm")
    Loadchar *fnameload from external file e.g. "xpm/image.xpm"
    Drawint x,ydraw bitmap on the parent window at the position [x,y] measured from left-top corner

    Examples

    #include "xpm/image.xpm"						// include XPM file into source code
    StkWindow *window1 = new StkWindow(...);				// create window1
    StkBitmap *bmp1 = new StkBitmap(window1->GetWindow(), image_xpm);	// create the bitmap on the window1 from the source
    StkBitmap *bmp2 = new StkBitmap(window1->GetWindow(), "xpm/image.xpm");	// create the bitmap on the window1 from the file
    bmp1->Draw(10,10);							// draw bmp1 on window1
    bmp2->Draw(100,10);							// draw bmp2 on window1
    

    3.10 Graphics

    Files stk_shapes.h and stk_shapes.cc contain all graphics of the STK components. If you want to change appearance of the components, simple change this files. STK doesn't support themes! (more appearances in one moment)

    Functions

    TypeFunction NameAttributesDescription
    -stk_draw_slider_buttonDisplay* di, Drawable dr, GC gc, int x,y,w,h, orient, bool activedraw StkSlider button
    -stk_draw_frameDisplay* di, Drawable dr, GC gc, int x,y,w,h, bool enableddraw impressed white area (slider, edit, memo, ..)
    -stk_draw_labelDisplay* di, Drawable dr, GC gc, XFontStruct *fs, int x,y,*w,*h,oldw,oldh, char* caption, bool enabled,active,correction=truedraw label
    -stk_draw_radiobuttonDisplay* di, Drawable dr, GC gc, XFontStruct *fs, int x,y,w,h,oldw,oldh,button_width, char* caption, bool enabled,active,focused,checkeddraw radiobutton (except bitmap)
    -stk_draw_buttonDisplay* di, Drawable dr, GC gc, XFontStruct *fs, int x,y,w,h, char *caption, bool enabled,focused,pressed,activedraw button
    -stk_draw_rectangleDisplay* di, Drawable dr, GC gc, int x,y,w,h, uint colordraw simple rectangle
    -stk_draw_focus_rectangleDisplay* di, Drawable dr, GC gc, int x,y,w,hdraw focus rectangle (dotted)
    -stk_fill_rectangleDisplay* di, Drawable dr, GC gc, int x,y,w,h, uint colorfill rectangle
    -stk_draw_slider_bg_horizDisplay *di, Drawable dr, GC gc, int x,y,w,h,a,bdraw the bacgrouund of slider
    -stk_draw_slider_bg_vertDisplay *di, Drawable dr, GC gc, int x,y,w,h,a,bdraw the bacgrouund of slider

    Examples

    // from StkButton.Draw()
    stk_draw_button(stkdisplay,window,gc,stkfont,0,0,width,height,caption,enabled,focused,pressed,active);
    

    3.11 Callbacks

    Files stk_callback.h and stk_callback.cc contain component's callback functions definitions and templates.

    Objects

    NameConstructorDescription
    StkBasicCallback-abstract class, parent of both callback methods
    StkGlobalCallback*functioncallback for global functions
    StkCallback*object,&object::methodcallback for object's method

    Methods

    TypeMethod NameAttributesDescription
    -Execute-call the callback

    Examples

    class SomeHigherClass 		// some object
    { 
     public: 
       StkButton *button1;		// button1
       void button1click(void) 	// button1 method callback
         { 
           printf("Method\n"); 
         };
    };
    
    void global1click() 		// button1 global callback
    { 
      printf("Global\n"); 
    }			
    
    ...
    SomeHigherClass *shc = new ...;		// create instance shc which "contain" few components and it's callbacks
    shc->button1->CreateCallback
        (new StkCallback(&global1click));		   			      // set the global callback
    shc->button1->CreateCallback
        (new StkCallback<SomeHigherClass>(shc,&SomeHigherClass::button1click));   // set the method callback
    

    3.12 Components

    Files stk_components.h and stk_components.cc contain object which handle array of all components in window throw bidirectional linked list and event handler implementation. Each component which may contain other component (e.g. window) has it's own instance of StkComponents class.

    Functions

    TypeFunction NameAttributesDescription
    voidstk_next_event-wait for next keyboard/mouse/other event and set the stkevent and other variables

    Variables

    TypeIdentifierDescription
    XEventstkeventcurrent event from the X Server

    Methods (of StkComponents class)

    MethodAttributesDescription
    AddStkComponent*add component into components list
    RemoveStkComponent*remove component from the list
    SetFocusStkComponent*unset focus of focused component and set focus to the specified component
    Update-update event handler and call the component events
    StkComponent *FindWindow find the component by the window which receive the event
    Debug-display list of components
    ECNFWindowdebug when Event Component Not Found
    CallShortcut-check the shortcuts and call OnShortcut if it match

    4. Examples

    4.1 Hello world

    Description

    This example show popular "Hello world!" demo using STK toolkit.

    Source

    #include "../../stk.h"		// path to STK library
    
    int main()
    {
      // initialize STK
      stk_init(); 			
      
      // create the window1
      StkWindow *window1 = new StkWindow(stkdisplay_root, -1, -1, 150, 50, "Demo");
      
      // create label1 component
      StkLabel *label1 = new StkLabel(window1, 10, 10, -1, -1, "Hello world!");
    
      // main loop
      do {
        stk_next_event();
        window1->components->Update();
      } while (! (window1->Closed()) );
      
      // done STK
      stk_done();
    }
    

    5. Appendix

    5.1 Table of component's constructors

    StkLabelStkWindow* parwin, int x,y,w,h, char* cap, StkComponent* focuscontrol
    StkCheckboxStkWindow* parwin, int x,y, char* cap, bool chckd=false
    StkRadiobuttonStkWindow* parwin, int x,y, char* cap, int grp=0, bool chckd=false
    StkButtonStkWindow* parwin, int x,y,w,h, char* cap
    StkImageStkWindow* parwin, int x,y,w,h, char** data
    StkWindow* parwin, int x,y,w,h, char* fname
    StkSliderStkWindow* parwin, int x,y,len, orient, val, rang, incr
    StkShortcutStkWindow* parwin, KeySym key, int mods, StkComponent* focuscontrol=null
    StkMenuitemStkWindow* parwin, left, top, width, height, char* cap, enabled=true
    StkEditStkWindow* parwin, left, top, width, height, char* text
    StkPanelStkWindow *parwin, left, top, width, height