//
// Copyright (C) 1999-2004 WideStudio Development Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// WIDESTUDIO DEVELOPMENT TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// Except as contained in this notice, the name of WideStudio Development Team 
// shall not be used in advertising or otherwise to promote the sale, use or 
// other dealings in this Software without prior written authorization from  
// WideStudio Development Team.

#if !defined(_scrnx_h)
#define _scrnx_h

#ifndef WS
#define WS
#endif //WS

#ifdef WS
#include <WScom.h>
#include <WSDmwindowDev.h>
#include <WSDcolor.h>
#else
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#endif //WS

#include "screen.h"

const int PSEUDOCOLOR = 0;
const int TRUECOLOR   = 1;

class ScrnX : public TScreen {
    int ncol;
#ifdef WS
    WSDcolor*  colors[256];
    WSDmwindowDev* _mdev;
    WSDdev* _dev;
#else
    XColor  col[256];
    Display *d;
    Window  w;
    Font    f;
    GC      gc;
    GC      gcf;
    Pixmap  p;
    Colormap    cmap;
#endif
    int color_mode;
    int     mode;
    unsigned long rshift;
    unsigned long gshift;
    unsigned long bshift;
    unsigned long rbits;
    unsigned long gbits;
    unsigned long bbits;
#ifdef WS
    void initialize();
    WSDcolor* SearchColor(long r, long g, long b);
    void SetColorMap();
    short _whiteid,_blackid;
#else
    XSetWindowAttributes attr;
    XStandardColormap *stdcmap;
    unsigned long black, white;
    void OpenX();
    void SetupColorInfo();
    void SetColorMap(Visual* vis);
    unsigned long SearchColor(long r, long g, long b);
#endif
  public:
    ScrnX();
    virtual ~ScrnX();
#ifdef WS
    void setDev(WSDdev*);
    long beginDraw();
    long endDraw();
#else
    Display *GetDisplay();
    Window  *GetWindow();
#endif
    virtual int  set_mode(int mode);
    virtual void restore_mode();
    virtual void update();
    virtual void clear();
    virtual int  line(Vector2D p1, Vector2D p2, int color);
    virtual int  line_rgb(Vector2D p1, Vector2D p2, int r, int g, int b);
    virtual int  point(Vector2D p, int color);
    virtual int  polygon(Vector2D *vp, int vn, int color);
    virtual int  write_text(int x, int y,int color, char* text);
    virtual void SetPaletteEntry(int n, int r , int g, int b);
    virtual void UpdatePalette();
    int  polygon_rgb(Vector2D *vp, int vn, int r, int g, int b);
    int  GetColorMode() { return color_mode; };
};

#endif

