/*
 * UPIWIN - Micro Pi Windowing Framework Kernel
 * Copyright (C) 2019 Amy Bowersox/Erbosoft Metaverse Design Solutions
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *-------------------------------------------------------------------------
 */
#ifndef __DEVCTXT_H_INCLUDED
#define __DEVCTXT_H_INCLUDED

#include "wintype.h"
#include "gfxtype.h"
#include "gfxobj.h"
#include "bitmap.h"

#define DCTXT_SIG_WORD  0x78744344   /* "DCtx" */

/* Raster operation codes */
#define R2_BLACK        1
#define R2_NOTMERGEPEN  2
#define R2_MASKNOTPEN   3
#define R2_NOTCOPYPEN   4
#define R2_MASKPENNOT   5
#define R2_NOT          6
#define R2_XORPEN       7
#define R2_NOTMASKPEN   8
#define R2_MASKPEN      9
#define R2_NOTXORPEN    10
#define R2_NOP          11
#define R2_MERGENOTPEN  12
#define R2_COPYPEN      13
#define R2_MERGEPENNOT  14
#define R2_MERGEPEN     15
#define R2_WHITE        16

struct tagDCTXT; /* forward declaration */

typedef COLORREF (*DCtx_SetPixel)(PVOID privdata, INT32 x, INT32 y, COLORREF color, INT32 op);
typedef BOOL (*DCtx_Line)(PVOID privdata, INT32 x1, INT32 y1, INT32 x2, INT32 y2, COLORREF color, INT32 op);
typedef BOOL (*DCtx_SolidRect)(PVOID privdata, PRECT rect, COLORREF color, INT32 op);
typedef struct tagDCTXT *(*DCtx_CreateCompat)(PVOID privdata);
typedef BOOL (*DCtx_NewBitmap)(PVOID privdata, PBITMAP pbmp);
typedef BOOL (*DCtx_BitBlt)(PVOID p_dest, PRECT r_dest, PVOID p_src, PRECT r_src, UINT32 op);

typedef struct tagDCFUNTABLE {
  DCtx_SetPixel set_pixel;          /* sets a single pixel on the display */
  DCtx_Line line;                   /* draws a line on the display */
  DCtx_SolidRect solid_rect;        /* draws a solid rectangle on the display */
  DCtx_CreateCompat create_compat;  /* create a memory DC compatible with this one */
  DCtx_NewBitmap new_bitmap;        /* new bitmap selected notification */
  DCtx_BitBlt bitblt;               /* bit block transfer */
} DCFUNTABLE;

typedef const DCFUNTABLE *PDCFUNTABLE;

typedef struct tagDCTXT {
  GFXOBJECT hdr;      /* the header of all objects */
  PDCFUNTABLE funcs;  /* device context functions */
  PVOID privdata;     /* private data for the type of DC */
  UINT32 flags;       /* flags for the DC */
  RECT baserect;      /* base rectangle */
  RECT cliprect;      /* clipping rectangle */
  POINT pos;          /* current position */
  UINT32 rop2;        /* current raster operation */
  COLORREF color;     /* current drawing color (XXX replace with pens later) */
  PBITMAP cur_bitmap; /* current selected bitmap */
} DCTXT, *PDCTXT;

#define DCFLG_TYPES      0x03
#define DCFLG_IS_SCREEN  0x00
#define DCFLG_IS_MEMORY  0x01

extern PDCTXT _DC_Allocate(PDCFUNTABLE funcs, PVOID privdata);
extern void _DC_FinalizeCommon(PDCTXT pdctxt);

extern COLORREF DC_SetPixel(PDCTXT pdctxt, INT32 x, INT32 y, COLORREF color);
extern BOOL DC_LineTo(PDCTXT pdctxt, INT32 x, INT32 y);
extern BOOL DC_MoveTo(PDCTXT pdctxt, INT32 x, INT32 y, PPOINT oldpt);
extern BOOL DC_Rectangle(PDCTXT pdctxt, INT32 left, INT32 top, INT32 right, INT32 bottom);
extern BOOL DC_SolidRectangle(PDCTXT pdctxt, INT32 left, INT32 top, INT32 right, INT32 bottom);
extern UINT32 DC_GetROP2(PDCTXT pdctxt);
extern UINT32 DC_SetROP2(PDCTXT pdctxt, UINT32 rop);
extern COLORREF DC_GetTextColor(PDCTXT pdctxt);
extern COLORREF DC_SetTextColor(PDCTXT pdctxt, COLORREF cr);
extern BOOL DC_GetClipRect(PDCTXT pdctxt, PRECT prect);
extern BOOL DC_SetClipRect(PDCTXT pdctxt, PRECT prect);
extern PDCTXT DC_CreateCompatible(PDCTXT pdctxt);
extern PGFXOBJECT DC_SelectObject(PDCTXT pdctxt, PGFXOBJECT pobj);
extern BOOL DC_BitBlt(PDCTXT dest, INT32 x, INT32 y, INT32 width, INT32 height, PDCTXT source, INT32 x1, INT32 y1, UINT32 rop);

#define DC_addref(pdctxt)   Go_addref(&(pdctxt->hdr))
#define DC_release(pdctxt)  Go_release(&(pdctxt->hdr))

#endif /* __DEVCTXT_H_INCLUDED */
