Migrate to OpenGUI 4.0.4 and obove from older versions

(18.march 2003)

NOTE: If you don't need QNX 4.x compatibility, stay with version 3.x.of OpenGUI.


There are big changes because of rewriting some parts of the library to get better performance clean design and the reentrant code.

Changes for 4.x in short:

  • the NASM assembler utility is no more required for compiling on any platform
  • reentrant code for all windowed code
  • thread-safe locking on critical sections
  • each drawable object contains PAPER, INK, FONT and PPOP and only these are used for drawing on them. DrawBuffer::set_fcolor(),
  • DrawBuffer::set_bcolor(), DrawBuffer::set_ppop() & DrawBuffer::set_font()as the DrawBuffer methods
  • global version of set_fcolor(), set_bcolor(), set_ppop() & set_font(), will be removed - affect only non object code (draw_line() , fill_box() etc)
  • no -fPIC compile flags are necessary under LINUX & shared linking
  • the API has been cleaned and changes are minor (and well documented)
  • the classes FileDialog() and ColorDialog may be instatiated more than once at the same time
  • on now there are no Watcom C++ or QNX OS support (because of banking video modes)
  • only C++ language is supported
  • the active EditBoxes are per window now
  • most of static variables are removed.
  • this version is still not very well optimized for speed
  • added macros for differentiate versions FG_MINOR, FG_MAJOR, FG_PATCH
  • you can remove file OpenGUI.def from your WIN32 projects

Convenience:

  • the old code or code to remove with new port is marked red
  • the new code is marked blue

1. redundant set_ppop() with global scope - this funcion is no more needed.

    static void InstalaterProc(GuiEvent *p)
    {
        switch(p->GetType()) {
            case INITEVENT:
                set_ppop(_GSET);
                p->wnd->AddPushButton(464, 168+36, 128, 23, "Koniec", 'k', Control::Quit);
                break;
            case TERMINATEEVENT:
                break;
        }
    }

2. replacement & new prototypes

    outp() -> outpb();
    inp() -> inpb();
    X_width -> GetXRes();
    Y_width -> GetYRes();
    X_max -> (GetXRes()-1);
    Y_max -> (GetYRes()-1);
    videobase -> GetFrameBuffer();
    class ListBox -> class FGListBox;
    template FGList<> -> template std::list<> ( or std::vector<> )

    fill_convex(vrcholov, pp, CGRAYED, _GSET);

    set_fcolor(CGRAYED);
    set_ppop(_GSET);
    fill_convex(vrcholov, pp);

    fill_convex(vrcholov, pp, CGRAYED, _GSET);


    set_fcolor(CGRAYED);
    set_ppop(_GXOR);
    draw_convex(vrcholov, pp);

    draw_convex(vrcholov, pp, CGRAYED, _GXOR);


    set_colors(CWHITE,CGRAYED);
    set_ppop(_GTRANSP);
    text_out(pp[0][0]/1000+XSTR, -pp[0][1]/1000+XSTR, name);
    set_ppop(_GSET);

    text_out(pp[0][0]/1000+XSTR, -pp[0][1]/1000+XSTR, name,CWHITE,CGRAYED,_GTRANSP);


    set_fcolor(color);

    draw_point(int(x/1000)+XSTR, int(-y/1000)+XSTR);

    draw_point(int(x/1000)+XSTR, int(-y/1000)+XSTR, color, _GSET);


    set_fcolor(0);
    fill_box(0, 0, XMAX, XMAX);

    fill_box(0, 0, XMAX, XMAX, 0, _GSET);


    set_colors(CWHITE,CBLACK);
    gprintf(100, 100, "Pocitam viditelnosti!!!");

    gprintf(CWHITE, CBLACK, 100, 100, "Pocitam viditelnosti!!!");

3. implementation for DrawBuffer class and its successors

    DrawBuffer *w;
    set_fcolor(bg);
    w->box(x, y, 30, 20);
    set_colors(HARD_BLACK, bg);
    w->text(x + 3, y + 3, s);

    w->box(x, y, 30, 20, bg);
    w->text(x + 3, y + 3, s, HARD_BLACK, bg);

    set_bcolor(CBLUE);
    w->WindowText(320, 150 + ss[j].sonda * 16, ss[j].nazov, CYELLOW);

    w->WindowText(320, 150 + ss[j].sonda * 16, ss[j].nazov, CYELLOW, CBLUE);

    set_font(1);
    set_colors(CREDLIGHT, CBLACK);
    set_ppop(_GTRANSP);
    rootwnd->WindowText(xoff-8, yoff, buf);

    rootwnd->set_font(1);
    rootwnd->set_ppop(_GTRANSP);
    rootwnd->WindowText(xoff-8, yoff, buf, CREDLIGHT, CBLACK);

Appendix A: prototypes

int get_point(int x, int y);
void draw_hline(int x, int y, int w, FGPixel ink, unsigned ppop);
void draw_box(int x, int y, int w, int h, FGPixel ink, unsigned ppop);
void fill_box(int x, int y, int w, int h, FGPixel ink, unsigned ppop);
void draw_point(int x, int y, FGPixel color, unsigned ppop);
int draw_line(int x, int y, int x1, int y1, FGPixel color, unsigned ppop);
int drawto_line(int x, int y, FGPixel ink, unsigned ppop);
void draw_pattern_line(int x, int y, int x1, int y1, Pattern *, unsigned ppop);
void drawto_pattern_line(int x, int y, Pattern *, unsigned ppop);
void draw_pattern_box(int x, int y, int a, int b, Pattern *pat, unsigned ppop);
void draw_spline(int points[8], FGPixel ink, unsigned ppop);
void calc_spline(int points[8], int npts, int *x, int *y);
void moveto(int x, int y);

void FGmemcpy(FGPixel * to, FGPixel * from, unsigned c);
void FGmemset(FGPixel * to, FGPixel data, unsigned c);
void FGmemcpy2(FGPixel * to, FGPixel * from, unsigned c, unsigned ppop);
void FGmemset2(FGPixel * to, FGPixel data, unsigned c, unsigned ppop);

void _set_default_palette(void);
void _set_fgl_palette(void);
unsigned int get_palette(unsigned int i);
void _palette(unsigned, unsigned int);

int text_out(int x, int y, char *text, FGPixel ink, FGPixel paper, unsigned ppop, int font=FONT0816);
int get_area_size(int x, int y);
void fill_convex(int c, int a[][2], FGPixel ink, unsigned ppop);
void draw_convex(int c, int a[][2], FGPixel ink, unsigned ppop);
void get_block(int x, int y, int a, int b, FGPixel * p);
void put_block(int x, int y, int a, int b, FGPixel * p, unsigned ppop);
void set_clip_rect(int w, int h, int x, int y);

void fill_ellipse(int x, int y, int rx, int ry, FGPixel ink, unsigned ppop);
void draw_ellipse(int x, int y, int rx, int ry, FGPixel ink, unsigned ppop);
void draw_arc(int x, int y, double ang1, double ang2, int r, FGPixel ink, unsigned ppop);
extern void draw_circle(int x, int y, int r, FGPixel ink, unsigned ppop);
extern void fill_circle(int xs, int ys, int r, FGPixel ink, unsigned ppop);

extern void RamToVideo(FGPixel * Image, int x, int y, int xm, int ym, int w, int h, int cx_max, int cy_max, int opcia, unsigned ppop);
extern void VideoToRam(FGPixel * Image, int x, int y, int xm, int ym, int w, int h, int cx_max, int cy_max);
extern void RamToRam(int x, int y, int xmax, int ymax, int xdst, int ydst, int xmaxdst, int ymaxdst, int w, int h, FGPixel * from, FGPixel * to, int alpha, int ppop);
int gprintf(FGPixel ink, FGPixel paper, int x, int y, const char *format,...);

int get_key(void);
int get_colordepth(void);
void set_transpcolor(FGPixel);

class DrawBuffer : public FGConnector
{
friend class GLSurface;
friend class _listbox;
private:
static int ID_counter;
int id;
FGMutex atomic;
inline void lock(void)
{
atomic.Lock();
}
inline void unlock(void)
{
atomic.Unlock();
}
public:
enum Type { WINDOW=0x4000, CHECKBUTTON, PUSHBUTTON, POINTBUTTON, EDITBOX, PROGRESSBAR,
BASEMENU, BASEMENUITEM, MENUWINDOW, SLIDEBAR, MULTILINEEDIT, LISTBOX, LABEL,
BMP_FILE, BMP_IMAGE, BMP_MEM, ROOTWINDOW, FGFRAMEBUFFER, COMBOBOX,
BMP_NONE=0 };
void Assign(int a, int b, void *c);
// modify pixel data
protected:
int w,h;
int xoff,yoff; // coor
int wwrk,hwrk; // sizes
unsigned long status;
FGPixel *image;
char *name;
int colorkey;
union { Type type; int _asd; };
FGPixel ink, paper;
FGPixel _ink, _paper;
int _font; // kod fontu
unsigned _ppop;
unsigned char alpha;

static const char *empty_string;
static int oldx, oldy;

FGPixel * SetArray(FGPixel *array) { return image = array; }

DrawBuffer(int ww, int hh, char * nm, Type t, FGPixel i, FGPixel p);
void modify_point(FGPixel *ptr, FGPixel ink);
void __line(int,int,int,int, FGPixel color);
void _init(int ww, int hh, Type t, FGPixel ii=CBLACK, FGPixel pp=CWHITE, char *nm=0);
void _symetry(int xs, int ys, int x, int y, FGPixel color);
void _symetry2(int xs, int ys, int x, int y, FGPixel color);
public:
inline FGPixel * CalcAddr(int x, int y)
{
return image + (w * y + x);
}
inline void set_font(int f)
{
// try get font image, and save requested font ID if success
if (FGFontManager::get_font_ptr(f))
_font = f;
}
inline int get_font(void)
{
return _font;;
}
inline int textwidth(char *txt)
{
return FGFontManager::textwidth(_font, txt);
}
inline int _textwidth(char *txt, int cnt)
{
return FGFontManager::_textwidth(_font, txt, cnt);
}
inline int charwidth(int c)
{
return FGFontManager::charwidth(_font, c);
}
inline int GetFontW(void)
{
return FGFontManager::GetW(_font);
}
inline int GetFontH(void)
{
return FGFontManager::GetH(_font);
}
inline int set_ppop(unsigned op)
{
int oldp = _ppop;
_ppop = op;
return oldp;
}
inline void set_fcolor(FGPixel val) { _ink = val; }
inline void set_bcolor(FGPixel val) { _paper = val; }
inline void set_colors(FGPixel i, FGPixel p) { _ink = i; _paper = p; }

int GetId(void) const { return id; }
static int GetCounter(void) { return ID_counter; }

// ww & hh are size!
inline int set_clip_rect(int xx, int yy, int ww, int hh)
{
if (hh<1 || ww<1 || xx<0 || yy<0) return 0;
xoff = xx;
yoff = yy;
if ((xx + ww) > w) ww -= ((xx + ww) - w);
if ((yy + hh) > h) hh -= ((yy + hh) - h);
wwrk = ww;
hwrk = hh;
return 1;
}
inline void get_clip_rect(int& x,int& y,int& w,int& h)
{
x = xoff;
y = yoff;
w = wwrk;
h = hwrk;
}
//
// clip coor and size to user space
//
inline int clip(int& xr, int& yr, int& wr, int& hr)
{
if (xr<xoff)
{
wr -= (xoff-xr);
xr = xoff;
}
if (yr<yoff)
{
hr -= (yoff-yr);
yr = yoff;
}
if (xr+wr > wwrk)
{
wr = wwrk-(xr-xoff);
}
int yoff2 = h - (hwrk+yoff);
if (yr+hr > h-yoff2)
{
hr = h-yr-yoff2;
}
return (wr<1 || hr<1) ? 0 : 1; // return if valid
}
inline int clip_shape(int& xr, int& yr, int& wr, int& hr)
{
if (xr<0)
{
wr += xr;
xr = 0;
}
if (yr<0)
{
hr += yr;
yr = 0;
}
if (xr+wr>w)
{
wr = w-xr;
}
if (yr+hr>h)
{
hr = h-yr;
}
return (wr<1 || hr<1) ? 0 : 1; // return if valid
}

DrawBuffer(int ww=0, int hh=0, Type=BMP_MEM, int color=CBLACK, FGPixel *buf=0);
DrawBuffer(int ww, int hh, FGPixel *buf);

virtual ~DrawBuffer();

// copy block from one buffer to other (with ppop or alpha)
// this is software blitter only
int bitblit(int xdst, int ydst, int xsrc, int ysrc, int ww, int hh, class DrawBuffer *src, int opcia=BITBLIT_COPY);

int hline(int x, int y, int size, FGPixel color);
int vline(int x, int y, int size, FGPixel color);
int line(int x, int y, int x2, int y2);
int line(int x, int y, int x2, int y2, FGPixel color);
int lineto(int x, int y);
int lineto(int x, int y, FGPixel color);
void moveto(int x, int y) { oldx = x; oldy = y; }
int pline(int x1, int y1, int x2, int y2, Pattern *p);
void spline(int points[8]);
void spline(int points[8], FGPixel color);

int rect(int xdst, int ydst, int ww, int hh);
int rect(int xdst, int ydst, int ww, int hh, FGPixel ink);
int box(int xdst, int ydst, int ww, int hh);
int box(int xdst, int ydst, int ww, int hh, FGPixel i);

int text(int x, int y, const char *txt);
int text(int x, int y, const char *txt, FGPixel i);
int text(int x, int y, const char *txt, FGPixel i, FGPixel p);
int printf(int , int , const char * , ... );
int putpixel(int x, int y);
int putpixel(int x, int y, FGPixel color);
int getpixel(int x, int y)
{
if (x<0 || y<0 || x>=wwrk || y>=hwrk)
return 0xFFFFFFFF;
return *(GetArray()+(x+xoff)+(y+yoff)*w);
}
void stretch(int _w, int _h);
void stretch(float ratiox, float ratioy);

int arc(int xs, int ys, double ang1, double ang2, int r);
int arc(int xs, int ys, double ang1, double ang2, int r, FGPixel color);
int ellipse(int x, int y, int rx, int ry);
int ellipse(int x, int y, int rx, int ry, FGPixel color);
int fellipse(int x, int y, int rx, int ry);
int fellipse(int x, int y, int rx, int ry, FGPixel color);
int circle(int xs, int ys, int r);
int circle(int xs, int ys, int r, FGPixel color);
int fcircle(int xs, int ys, int r);
int fcircle(int xs, int ys, int r, FGPixel color);
void polygon(int n, int pt[][2]);
void polygon(int n, int pt[][2], FGPixel color);
FGRect fpolygon(int n, int pt[][2]);
FGRect fpolygon(int n, int pt[][2], FGPixel color);
FGRect ftriangle(int x1, int y1, int x2, int y2, int x3, int y3);
FGRect ftriangle(int x1, int y1, int x2, int y2, int x3, int y3, FGPixel color);

FGPixel *GetArray(void) const { return image; }
int GetAlpha(void) const { return alpha; }
FGPixel GetInk(void) const { return (FGPixel)ink; }
FGPixel GetPaper(void) const { return (FGPixel)paper; }
long GetStatus(void) const { return status; }
int GetW(void) const { return w; }
int GetH(void) const { return h; }
int GetXW(void) const { return xoff; }
int GetYW(void) const { return yoff; }
int GetWW(void) const { return wwrk; }
int GetHW(void) const { return hwrk; }
int GetType(void) const { return type; }
int GetColorKey(void) const { return colorkey; }
char *GetName(void) const { return name; }
void SetStatus(long s) { status = s; }
void SetColors(void)
{
set_colors(ink, paper);
}
void SetColorKey(int ck)
{
colorkey = ck;
}
void SetName(char *s);
void SetAlpha(int a) { alpha = a; }
void Resize(int dx, int dy);
void clear(int c) { FGmemset(image, c, w*h); }

};

Appendix B: class App

class App
{
        int mouseflag;
        int mx, my, mb, oldx, oldy, oldb, drag, action;
        int XX, YY;

        int mousefirst, resize, tmp_event,
            resizex, resizey,
            dragx, dragy,
            clickx,    clicky,    clickw,    clickh,
            vyrez;

        Control *idcb;
        Control *idc2;
        Window *drag_okno;
        static int repeat_status, repeat_delay1, repeat_delay2;
        GuiEvent *hold_event;

        int  RemoveMousePointer(void);
        void ShowMousePointer(void);
        void blue_rect(int x, int y, int w, int h);
        void blue_rect2(int x, int y, int w, int h);
    protected:
        void AutoRepeatStart(Control *);
        void AutoRepeatDo(void);
        void DoubleClick(int& event);

        static    GuiEvent queque[MAX_EVENT_QUEQUE];
        static    void (*DelayProc)(void);
        static    int    quequeIndex;
        static    void (*OnEverySecond)(int);
        static  Window *Root;
        static    MainHwnd appHandler;
        static  unsigned long ticks;
        static  int ctrl_break;
        static  int startXdrag;
        static  int startYdrag;
        static  int endXdrag;
        static  int endYdrag;
        static void (*DragShape)(int , int ,int    , int );
        static FGPixel __p4[8];
        static Pattern __patt;
    public:
        static  FGMouseCursor *__fg_cursor;
        static  int     fulldrag;
        static    int        flags;
        static    int        video;
        static    int        Argc;
        static    int        background;
        static    char    **Argv;
        static    char    * name;
        static    char    *homedir;
        static  char    currdir[128];
        static    int     ttf_support;

        static    void SetDelayProc(void (*fnc)(void))
        {
            DelayProc =    fnc;
        }
        static    void CallDelayProc(void)
        {
            if (DelayProc) DelayProc();
            else delay(10);
        }

        void UpdateMousePointer(void);
        void SaveScreen(void);

        static void DisableCtrlBreak(void)
        {
            ctrl_break ^= 1;
        }
        static void SetWindowMoveStyle(int a)
        {
            fulldrag = a;
        }
        App(int, int &,    char **    &, int b, int f=APP_ENABLEALTX);
        virtual ~App();

        static    void SendToApp(GuiEvent    *x);
        void    Run(MainHwnd hwnd=0);
        void    FGYield(void);
        static    void AppDone(void)
        {
            GuiEvent e(QUITEVENT);
            SendToApp(&e);
        }
        static    void Timer(void);
        // NOTE! resolution is cca. 20ms
        static void    SetTimerProc(void ((*p)(int)), int t=1000)
        {
            OnEverySecond =    p;
            ticks = t;
        }
        static Window * GetRootWindow(void)
        {
            return Root;
        }
        void BroadcastMessage(GuiEvent *event);
        int RunModal(Window *which);

        static void    InitUserEvent(void);
        void GetUserEvent(GuiEvent& e, int);
        void TranslateUserEvent(GuiEvent& e);

        int    GetMouseX(void)
        {
            return mx;
        }
        int    GetMouseY(void)
        {
            return my;
        }

        FGMouseCursor * CursorLoad(FGMouseCursor *cur);

        int EnableBuffering(int mode);
        int Flip(void);
        void DisableBuffering(void);

        enum { OSTYPE_LINUX=1, OSTYPE_MSDOS, OSTYPE_WIN32, OSTYPE_QNX };

        int GetOS(void);

        static void    CloseUserEvent(void);
        static void AutoRepeatEnd(void);
        static void    GetDragVector(int &a, int &b, int &c, int &d);
        static void    SetDragShape(void(*a)(int,int,int,int)=0);
        static void SetRepeatDelay(int    c1,    int    c2);

        // Object-oriented API via overloaded methods
        virtual void OnKeyPress(int) { }
        virtual void OnMouseMove(int , int) { }
        virtual void OnClick(int, int) { }
        virtual void OnContextPopup(int, int) { }
        virtual void OnStartDrag(int , int, int) {}
        virtual void OnEndDrag(int ,int, int, int, int) {}
        virtual void OnCursorOut(int)

        {
        }
};