Initial community commit
This commit is contained in:
3
Src/tataki/canvas/PaintCanvas.h
Normal file
3
Src/tataki/canvas/PaintCanvas.h
Normal file
@ -0,0 +1,3 @@
|
||||
#ifdef __APPLE__
|
||||
#include "mac/PaintCanvas.h"
|
||||
#endif
|
5
Src/tataki/canvas/bltcanvas.h
Normal file
5
Src/tataki/canvas/bltcanvas.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifdef _WIN32
|
||||
#include "win/bltcanvas.h"
|
||||
#elif defined(__APPLE__)
|
||||
#include "mac/bltcanvas.h"
|
||||
#endif
|
5
Src/tataki/canvas/canvas.h
Normal file
5
Src/tataki/canvas/canvas.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifdef _WIN32
|
||||
#include "win/canvas.h"
|
||||
#elif defined(__APPLE__)
|
||||
#include "mac/canvas.h"
|
||||
#endif
|
1
Src/tataki/canvas/ifc_canvas.cpp
Normal file
1
Src/tataki/canvas/ifc_canvas.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "ifc_canvas.h"
|
165
Src/tataki/canvas/ifc_canvas.h
Normal file
165
Src/tataki/canvas/ifc_canvas.h
Normal file
@ -0,0 +1,165 @@
|
||||
#ifndef NULLSOFT_TATAKI_IFC_CANVAS_H
|
||||
#define NULLSOFT_TATAKI_IFC_CANVAS_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include <bfc/platform/platform.h>
|
||||
#include <api/service/svcs/svc_font.h> // for STDFONT_* stuff. should make a std_font thingy later
|
||||
#include <bfc/wasabi_std.h> // for WASABI_DEFAULT_FONTNAMEW
|
||||
|
||||
namespace Wasabi
|
||||
{
|
||||
// benski> move this to std_font later
|
||||
struct FontInfo
|
||||
{
|
||||
FontInfo()
|
||||
{
|
||||
// defaults
|
||||
face = WASABI_DEFAULT_FONTNAMEW;
|
||||
pointSize = 12;
|
||||
bold = 0;
|
||||
opaque = false;
|
||||
underline = false;
|
||||
italic = false;
|
||||
alignFlags = STDFONT_LEFT;
|
||||
antialias = 1;
|
||||
bgColor = RGBA(255, 255, 255, 255);
|
||||
color = RGBA(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
const wchar_t *face;
|
||||
unsigned int pointSize;
|
||||
int bold; // bold level
|
||||
bool opaque;
|
||||
bool underline;
|
||||
bool italic;
|
||||
int alignFlags;
|
||||
int antialias; // anti-alias level
|
||||
ARGB32 color;
|
||||
ARGB32 bgColor;
|
||||
};
|
||||
}
|
||||
|
||||
class ifc_window;
|
||||
// abstract base class: safe to use in API
|
||||
class NOVTABLE ifc_canvas : public Dispatchable
|
||||
{
|
||||
protected:
|
||||
ifc_canvas()
|
||||
{} // protect constructor
|
||||
~ifc_canvas()
|
||||
{}
|
||||
|
||||
public:
|
||||
DISPATCH_CODES
|
||||
{
|
||||
GETHDC = 100,
|
||||
GETROOTWND = 200,
|
||||
GETBITS = 300,
|
||||
GETOFFSETS = 400,
|
||||
ISFIXEDCOORDS = 500,
|
||||
GETDIM = 600,
|
||||
GETTEXTFONT = 700,
|
||||
GETTEXTSIZE = 710,
|
||||
GETTEXTBOLD = 720,
|
||||
GETTEXTOPAQUE = 730,
|
||||
GETTEXTALIGN = 740,
|
||||
GETTEXTCOLOR = 750,
|
||||
GETTEXTBKCOLOR = 760,
|
||||
GETTEXTAA = 770,
|
||||
GETTEXTUNDERLINE = 780,
|
||||
GETTEXTITALIC = 790,
|
||||
GETCLIPBOX = 800,
|
||||
};
|
||||
public:
|
||||
HDC getHDC();
|
||||
ifc_window *getRootWnd();
|
||||
void *getBits();
|
||||
void getOffsets(int *x, int *y);
|
||||
bool isFixedCoords(); //FG> allows onPaint to handle double buffers as well as normal DCs
|
||||
bool getDim(int *w, int *h = NULL, int *p = NULL); // w & h in pixels, pitch in bytes. 0 on success.
|
||||
int getClipBox(RECT *r); // returns 0 if no clipping region
|
||||
const wchar_t *getTextFont();
|
||||
int getTextSize();
|
||||
int getTextBold();
|
||||
int getTextAntialias();
|
||||
int getTextOpaque();
|
||||
int getTextUnderline();
|
||||
int getTextItalic();
|
||||
int getTextAlign();
|
||||
ARGB32 getTextColor();
|
||||
ARGB32 getTextBkColor();
|
||||
};
|
||||
|
||||
|
||||
inline HDC ifc_canvas::getHDC()
|
||||
{
|
||||
return _call(ifc_canvas::GETHDC, (HDC)0);
|
||||
}
|
||||
inline ifc_window *ifc_canvas::getRootWnd()
|
||||
{
|
||||
return _call(ifc_canvas::GETROOTWND, (ifc_window*)0);
|
||||
}
|
||||
inline void *ifc_canvas::getBits()
|
||||
{
|
||||
return _call(ifc_canvas::GETBITS, (void *)0);
|
||||
}
|
||||
inline void ifc_canvas::getOffsets(int *x, int *y)
|
||||
{
|
||||
_voidcall(ifc_canvas::GETOFFSETS, x, y);
|
||||
}
|
||||
inline bool ifc_canvas::isFixedCoords()
|
||||
{ //FG> allows onPaint to handle double buffers as well as normal DCs
|
||||
return _call(ifc_canvas::ISFIXEDCOORDS, false);
|
||||
}
|
||||
inline bool ifc_canvas::getDim(int *w, int *h, int *p)
|
||||
{ // w & h in pixels, pitch in bytes. 0 on success.
|
||||
return _call(ifc_canvas::GETDIM, false, w, h, p);
|
||||
}
|
||||
inline int ifc_canvas::getClipBox(RECT *r)
|
||||
{ // returns 0 if no clipping region
|
||||
return _call(ifc_canvas::GETCLIPBOX, 0, r);
|
||||
}
|
||||
|
||||
inline const wchar_t *ifc_canvas::getTextFont()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTFONT, L"");
|
||||
}
|
||||
inline int ifc_canvas::getTextSize()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTSIZE, -1);
|
||||
}
|
||||
inline int ifc_canvas::getTextBold()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTBOLD, 0);
|
||||
}
|
||||
inline int ifc_canvas::getTextAntialias()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTAA, 0);
|
||||
}
|
||||
inline int ifc_canvas::getTextOpaque()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTOPAQUE, 0);
|
||||
}
|
||||
inline int ifc_canvas::getTextUnderline()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTUNDERLINE, 0);
|
||||
}
|
||||
inline int ifc_canvas::getTextItalic()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTITALIC, 0);
|
||||
}
|
||||
inline int ifc_canvas::getTextAlign()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTALIGN, -1);
|
||||
}
|
||||
inline ARGB32 ifc_canvas::getTextColor()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTCOLOR, RGB(0, 0, 0));
|
||||
}
|
||||
inline ARGB32 ifc_canvas::getTextBkColor()
|
||||
{
|
||||
return _call(ifc_canvas::GETTEXTBKCOLOR, RGB(255, 255, 255));
|
||||
}
|
||||
|
||||
typedef ifc_canvas api_canvas;
|
||||
#endif
|
51
Src/tataki/canvas/mac/PaintCanvas.cpp
Normal file
51
Src/tataki/canvas/mac/PaintCanvas.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "PaintCanvas.h"
|
||||
|
||||
PaintCanvas::PaintCanvas()
|
||||
{
|
||||
qdcontext=0;
|
||||
}
|
||||
|
||||
bool PaintCanvas::beginPaint(BaseWnd *wnd)
|
||||
{
|
||||
HIWindowRef macWnd = wnd->getOsWindowHandle();
|
||||
|
||||
qdcontext = GetWindowPort(macWnd);
|
||||
QDBeginCGContext(qdcontext, &context);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PaintCanvas::~PaintCanvas()
|
||||
{
|
||||
if (qdcontext)
|
||||
QDEndCGContext(qdcontext, &context);
|
||||
}
|
||||
|
||||
WndCanvas::WndCanvas()
|
||||
{
|
||||
qdcontext=0;
|
||||
}
|
||||
|
||||
WndCanvas::~WndCanvas()
|
||||
{
|
||||
if (qdcontext)
|
||||
QDEndCGContext(qdcontext, &context);
|
||||
}
|
||||
|
||||
int WndCanvas::attachToClient(BaseWnd *basewnd)
|
||||
{
|
||||
HIWindowRef macWnd = basewnd->getOsWindowHandle();
|
||||
|
||||
qdcontext = GetWindowPort(macWnd);
|
||||
QDBeginCGContext(qdcontext, &context);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
TextInfoCanvas::TextInfoCanvas(BaseWnd */*unused*/)
|
||||
{
|
||||
}
|
||||
|
||||
TextInfoCanvas::~TextInfoCanvas()
|
||||
{
|
||||
}
|
46
Src/tataki/canvas/mac/PaintCanvas.h
Normal file
46
Src/tataki/canvas/mac/PaintCanvas.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef NULLSOFT_WASABI_OSX_PAINTCANVAS_H
|
||||
#define NULLSOFT_WASABI_OSX_PAINTCANVAS_H
|
||||
|
||||
#include <tataki/export.h>
|
||||
#include <tataki/canvas/canvas.h>
|
||||
#include <api/wnd/basewnd.h>
|
||||
|
||||
class TATAKIAPI PaintCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
PaintCanvas();
|
||||
~PaintCanvas();
|
||||
bool beginPaint(BaseWnd *wnd);
|
||||
protected:
|
||||
CGrafPtr qdcontext;
|
||||
};
|
||||
|
||||
class TATAKIAPI PaintBltCanvas : public PaintCanvas
|
||||
{
|
||||
public:
|
||||
bool beginPaintNC(BaseWnd *wnd)
|
||||
{
|
||||
return beginPaint(wnd);
|
||||
}
|
||||
};
|
||||
#warning port PaintBltCanvas
|
||||
class TATAKIAPI WndCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
WndCanvas();
|
||||
virtual ~WndCanvas();
|
||||
|
||||
// address client area
|
||||
int attachToClient(BaseWnd *basewnd);
|
||||
|
||||
private:
|
||||
CGrafPtr qdcontext;
|
||||
};
|
||||
|
||||
class TATAKIAPI TextInfoCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
TextInfoCanvas(BaseWnd *baseWnd);
|
||||
virtual ~TextInfoCanvas();
|
||||
};
|
||||
#endif
|
27
Src/tataki/canvas/mac/bltcanvas.h
Normal file
27
Src/tataki/canvas/mac/bltcanvas.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef _BLTCANVAS_H
|
||||
#define _BLTCANVAS_H
|
||||
|
||||
#include <tataki/export.h>
|
||||
#include "canvas.h"
|
||||
|
||||
class TATAKIAPI BltCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
BltCanvas();
|
||||
BltCanvas(int width, int height, OSWINDOWHANDLE wnd);
|
||||
|
||||
// override blit and stretchblit so we can use CGContextDrawLayerAtPoint/CGContextDrawLayerInRect
|
||||
virtual void blit(int srcx, int srcy, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
|
||||
void blitToRect(api_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
|
||||
|
||||
virtual void stretchblit(int srcx, int srcy, int srcw, int srch, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
|
||||
void stretchToRectAlpha(api_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
|
||||
|
||||
void DestructiveResize(int w, int h, int nb_bpp = 32); // resizes the bitmap, destroying the contents
|
||||
void fillBits(ARGB32 color);
|
||||
|
||||
protected:
|
||||
CGLayerRef layer;
|
||||
};
|
||||
|
||||
#endif
|
70
Src/tataki/canvas/mac/canvas.h
Normal file
70
Src/tataki/canvas/mac/canvas.h
Normal file
@ -0,0 +1,70 @@
|
||||
#ifndef NULLSOFT_WASABI_CANVAS_H
|
||||
#define NULLSOFT_WASABI_CANVAS_H
|
||||
|
||||
#include <tataki/export.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <tataki/canvas/api_canvas.h>
|
||||
#include <bfc/platform/platform.h>
|
||||
#include <api/service/svcs/svc_font.h> // for STDFONT_* stuff. should make a std_font thingy later
|
||||
#include <bfc/std.h> // for WASABI_DEFAULT_FONTNAMEW
|
||||
class BaseWnd;
|
||||
class api_region;
|
||||
|
||||
class TATAKIAPI Canvas : public api_canvas
|
||||
{
|
||||
public:
|
||||
Canvas() :context(0), wnd(0) {}
|
||||
Canvas(CGContextRef _context) : context(_context), wnd(0) {}
|
||||
Canvas(CGrafPtr _context);
|
||||
HDC getHDC();
|
||||
void fillRect(const RECT *r, RGB32 color);
|
||||
void fillRgn(api_region *r, RGB32 color);
|
||||
void setBaseWnd(BaseWnd *_wnd) { wnd=_wnd; }
|
||||
void selectClipRgn(api_region *r);
|
||||
|
||||
virtual void blit(int srcx, int srcy, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
|
||||
virtual void stretchblit(int srcx, int srcy, int srcw, int srch, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
|
||||
|
||||
void textOut(int x, int y, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
|
||||
static float getSystemFontScale() { return 1.0f; }
|
||||
|
||||
int getTextWidth(const wchar_t *text, const Wasabi::FontInfo *fontInfo);
|
||||
int getTextHeight(const wchar_t *text, const Wasabi::FontInfo *fontInfo);
|
||||
int getTextHeight(const Wasabi::FontInfo *fontInfo)
|
||||
{
|
||||
return getTextHeight(L"M", fontInfo);
|
||||
}
|
||||
void getTextExtent(const wchar_t *text, int *w, int *h, const Wasabi::FontInfo *fontInfo);
|
||||
void textOutCentered(RECT *r, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
void textOut(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
void textOutEllipsed(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
|
||||
void drawSysObject(const RECT *r, int sysobj, int alpha=255);
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
|
||||
CGContextRef context;
|
||||
BaseWnd *wnd; // TODO: not 100% sure we'll need this. win32 version has it so we'll keep it for now
|
||||
};
|
||||
|
||||
class TATAKIAPI BaseCloneCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
BaseCloneCanvas(api_canvas *cloner=NULL);
|
||||
virtual ~BaseCloneCanvas();
|
||||
|
||||
int clone(api_canvas *cloner);
|
||||
};
|
||||
|
||||
namespace DrawSysObj {
|
||||
enum {
|
||||
BUTTON, BUTTON_PUSHED, BUTTON_DISABLED,
|
||||
OSBUTTON, OSBUTTON_PUSHED, OSBUTTON_DISABLED,
|
||||
OSBUTTON_CLOSE, OSBUTTON_CLOSE_PUSHED, OSBUTTON_CLOSE_DISABLED,
|
||||
OSBUTTON_MINIMIZE, OSBUTTON_MINIMIZE_PUSHED, OSBUTTON_MINIMIZE_DISABLED,
|
||||
OSBUTTON_MAXIMIZE, OSBUTTON_MAXIMIZE_PUSHED, OSBUTTON_MAXIMIZE_DISABLED,
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
95
Src/tataki/canvas/mac/osx_canvas_layer.cpp
Normal file
95
Src/tataki/canvas/mac/osx_canvas_layer.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
#include <tataki/canvas/bltcanvas.h>
|
||||
|
||||
inline float QuartzBlue(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[0] / 255.f;
|
||||
}
|
||||
|
||||
inline float QuartzGreen(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[1] / 255.f;
|
||||
}
|
||||
|
||||
inline float QuartzRed(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[2] / 255.f;
|
||||
}
|
||||
|
||||
inline float QuartzAlpha(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[3] / 255.f;
|
||||
}
|
||||
|
||||
BltCanvas::BltCanvas(int width, int height, OSWINDOWHANDLE wnd)
|
||||
{
|
||||
CGrafPtr qdcontext = GetWindowPort(wnd);
|
||||
CGContextRef temp;
|
||||
QDBeginCGContext(qdcontext, &temp);
|
||||
CGSize size = CGSizeMake(width, height);
|
||||
layer = CGLayerCreateWithContext(temp, size, NULL);
|
||||
context = CGLayerGetContext(layer);
|
||||
QDEndCGContext(qdcontext, &temp);
|
||||
}
|
||||
|
||||
void BltCanvas::blit(int srcx, int srcy, Canvas *dest, int dstx, int dsty, int dstw, int dsth)
|
||||
{
|
||||
CGPoint point = CGPointMake(dstx-srcx, dsty-srcy);
|
||||
CGContextDrawLayerAtPoint(dest->getHDC(), point, layer);
|
||||
}
|
||||
|
||||
void BltCanvas::blitToRect(api_canvas *canvas, RECT *src, RECT *dst, int alpha)
|
||||
{
|
||||
CGContextRef dest = canvas->getHDC();
|
||||
CGContextSaveGState(dest);
|
||||
CGContextSetAlpha(dest, (float)alpha/255.f);
|
||||
// TODO: deal with width properly
|
||||
CGRect rect = CGRectMake(dst->left - src->left, dst->top - src->top, dst->right - dst->left, dst->bottom - dst->top);
|
||||
CGContextDrawLayerInRect(dest, rect, layer);
|
||||
CGContextRestoreGState(dest);
|
||||
}
|
||||
|
||||
void BltCanvas::stretchblit(int srcx, int srcy, int srcw, int srch, Canvas *dest, int dstx, int dsty, int dstw, int dsth)
|
||||
{
|
||||
CGContextSaveGState(context);
|
||||
CGContextTranslateCTM(context, srcx, srcy);
|
||||
CGRect rect = CGRectMake(dstx, dsty, dstw, dsth);
|
||||
CGContextDrawLayerInRect(dest->getHDC(), rect, layer);
|
||||
CGContextRestoreGState(context);
|
||||
}
|
||||
|
||||
void BltCanvas::stretchToRectAlpha(api_canvas *canvas, RECT *src, RECT *dst, int alpha)
|
||||
{
|
||||
CGContextRef dest = canvas->getHDC();
|
||||
CGContextSaveGState(dest);
|
||||
CGContextSetAlpha(dest, (float)alpha/255.f);
|
||||
// TODO: deal with width properly
|
||||
CGRect rect = CGRectMake(dst->left - src->left, dst->top - src->top, dst->right - dst->left, dst->bottom - dst->top);
|
||||
CGContextDrawLayerInRect(dest, rect, layer);
|
||||
CGContextRestoreGState(dest);
|
||||
}
|
||||
|
||||
void BltCanvas::DestructiveResize(int w, int h, int nb_bpp)
|
||||
{
|
||||
CGSize size = CGSizeMake(w, h);
|
||||
CGLayerRef newlayer = CGLayerCreateWithContext(context, size, NULL);
|
||||
CGContextRelease(context);
|
||||
CGLayerRelease(layer);
|
||||
layer = newlayer;
|
||||
context = CGLayerGetContext(layer);
|
||||
}
|
||||
|
||||
void BltCanvas::fillBits(ARGB32 color)
|
||||
{
|
||||
CGContextSetRGBFillColor(context,
|
||||
QuartzRed(color), // red
|
||||
QuartzGreen(color), // green
|
||||
QuartzBlue(color), // blue
|
||||
QuartzAlpha(color) // alpha
|
||||
);
|
||||
|
||||
CGContextFillRect(context, CGRectInfinite);
|
||||
}
|
275
Src/tataki/canvas/mac/osx_canvas_quartz.cpp
Normal file
275
Src/tataki/canvas/mac/osx_canvas_quartz.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
#include <bfc/platform/types.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <tataki/canvas/canvas.h>
|
||||
#include <api/wnd/basewnd.h>
|
||||
#include <tataki/region/api_region.h>
|
||||
|
||||
|
||||
|
||||
/* various functions that might help out
|
||||
|
||||
for drawSysObject:
|
||||
HIThemeDrawButton
|
||||
HIThemeDrawTitleBarWidget for minimize, maximize, exit
|
||||
*/
|
||||
|
||||
inline float QuartzBlue(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[0] / 255.f;
|
||||
}
|
||||
|
||||
inline float QuartzGreen(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[1] / 255.f;
|
||||
|
||||
}
|
||||
|
||||
inline float QuartzRed(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[2] / 255.f;
|
||||
|
||||
}
|
||||
|
||||
inline float QuartzAlpha(RGB32 color)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)&color;
|
||||
return pixel[3] / 255.f;
|
||||
|
||||
}
|
||||
|
||||
Canvas::Canvas(CGrafPtr _context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Canvas::fillRect(const RECT *r, ARGB32 color)
|
||||
{
|
||||
CGContextSetRGBFillColor(context,
|
||||
QuartzRed(color), // red
|
||||
QuartzGreen(color), // green
|
||||
QuartzBlue(color), // blue
|
||||
QuartzAlpha(color) // alpha
|
||||
);
|
||||
|
||||
HIRect rect = HIRectFromRECT(r);
|
||||
CGContextFillRect(context, rect);
|
||||
}
|
||||
|
||||
void Canvas::fillRgn(api_region *r, ARGB32 color)
|
||||
{
|
||||
CGContextSetRGBFillColor(context,
|
||||
QuartzRed(color), // red
|
||||
QuartzGreen(color), // green
|
||||
QuartzBlue(color), // blue
|
||||
QuartzAlpha(color) // alpha
|
||||
);
|
||||
|
||||
HIShapeRef shape = r->getOSHandle();
|
||||
HIShapeReplacePathInCGContext(shape, context);
|
||||
CGContextFillPath(context);
|
||||
}
|
||||
|
||||
void Canvas::blit(int srcx, int srcy, Canvas *dest, int dstx, int dsty, int dstw, int dsth)
|
||||
{
|
||||
// clip dest
|
||||
// Create CGImage from context
|
||||
// CGContextDrawImage
|
||||
}
|
||||
|
||||
HDC Canvas::getHDC()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
void Canvas::selectClipRgn(api_region *r)
|
||||
{
|
||||
if (r)
|
||||
{
|
||||
HIShapeRef shape = r->getOSHandle();
|
||||
HIShapeReplacePathInCGContext(shape, context);
|
||||
CGContextClip(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
CGContextClipToRect(context, CGRectInfinite);
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::stretchblit(int srcx, int srcy, int srcw, int srch, Canvas *dest, int dstx, int dsty, int dstw, int dsth)
|
||||
{
|
||||
// Create CGImage from context
|
||||
// CGContextDrawImage
|
||||
}
|
||||
|
||||
void Canvas::textOut(int x, int y, const wchar_t *txt, const Wasabi::FontInfo *fontInfo)
|
||||
{
|
||||
// TODO: turn this code into a svc_fontI, and use api_font here instead
|
||||
size_t len = wcslen(txt);
|
||||
UniChar *unistr = (UniChar *)malloc((len + 1) * sizeof(UniChar));
|
||||
UniChar *copy = unistr;
|
||||
while (*txt)
|
||||
*copy++=*txt++;
|
||||
*copy=0;
|
||||
|
||||
ATSUStyle style;
|
||||
ATSUCreateStyle(&style);
|
||||
|
||||
CGContextSaveGState(context);
|
||||
CGContextSetRGBFillColor(context,
|
||||
QuartzRed(fontInfo->color), // red
|
||||
QuartzGreen(fontInfo->color), // green
|
||||
QuartzBlue(fontInfo->color), // blue
|
||||
QuartzAlpha(fontInfo->color) // alpha
|
||||
);
|
||||
|
||||
ATSUTextLayout layout;
|
||||
ATSUCreateTextLayout(&layout);
|
||||
|
||||
ATSUSetTextPointerLocation(layout, unistr, kATSUFromTextBeginning, kATSUToTextEnd, len);
|
||||
|
||||
ATSUSetRunStyle(layout, style, kATSUFromTextBeginning, kATSUToTextEnd);
|
||||
|
||||
Rect imageRect;
|
||||
ATSUMeasureTextImage(layout, kATSUFromTextBeginning, kATSUToTextEnd, 0, 0, &imageRect);
|
||||
y-=(imageRect.bottom - imageRect.top);
|
||||
CGContextScaleCTM(context, 1.0, -1.0);
|
||||
|
||||
ATSUAttributeTag tags[] = {kATSUCGContextTag};
|
||||
ATSUAttributeValuePtr values[] = {&context};
|
||||
ByteCount sizes[] = {sizeof(CGContextRef)};
|
||||
ATSUSetLayoutControls(layout, 1, tags, sizes, values);
|
||||
ATSUDrawText(layout, kATSUFromTextBeginning, kATSUToTextEnd, FloatToFixed(x), FloatToFixed(y));
|
||||
ATSUDisposeTextLayout(layout);
|
||||
ATSUDisposeStyle(style);
|
||||
CGContextRestoreGState(context);
|
||||
free(unistr);
|
||||
}
|
||||
|
||||
void Canvas::drawSysObject(const RECT *r, int sysobj, int alpha)
|
||||
{
|
||||
#warning TODO
|
||||
using namespace DrawSysObj;
|
||||
switch(sysobj)
|
||||
{
|
||||
case OSBUTTON:
|
||||
{
|
||||
HIRect buttonRect = HIRectFromRECT(r);
|
||||
HIThemeButtonDrawInfo buttonDrawInfo;
|
||||
buttonDrawInfo.version=0;
|
||||
buttonDrawInfo.state = kThemeStateActive;
|
||||
buttonDrawInfo.kind = kThemePushButton;
|
||||
buttonDrawInfo.value = kThemeButtonOn;
|
||||
buttonDrawInfo.adornment = kThemeAdornmentNone;
|
||||
buttonDrawInfo.animation.time.start = 0;
|
||||
buttonDrawInfo.animation.time.current=0;
|
||||
HIThemeDrawButton(&buttonRect, &buttonDrawInfo, context, /*kHIThemeOrientationNormal*/kHIThemeOrientationInverted, 0);
|
||||
}
|
||||
break;
|
||||
case OSBUTTON_PUSHED:
|
||||
{
|
||||
HIRect buttonRect = HIRectFromRECT(r);
|
||||
HIThemeButtonDrawInfo buttonDrawInfo;
|
||||
buttonDrawInfo.version=0;
|
||||
buttonDrawInfo.state = kThemeStatePressed;
|
||||
buttonDrawInfo.kind = kThemePushButton;
|
||||
buttonDrawInfo.value = kThemeButtonOn;
|
||||
buttonDrawInfo.adornment = kThemeAdornmentNone;
|
||||
buttonDrawInfo.animation.time.start = 0;
|
||||
buttonDrawInfo.animation.time.current=0;
|
||||
HIThemeDrawButton(&buttonRect, &buttonDrawInfo, context, /*kHIThemeOrientationNormal*/kHIThemeOrientationInverted, 0);
|
||||
}
|
||||
break;
|
||||
case OSBUTTON_DISABLED:
|
||||
{
|
||||
HIRect buttonRect = HIRectFromRECT(r);
|
||||
HIThemeButtonDrawInfo buttonDrawInfo;
|
||||
buttonDrawInfo.version=0;
|
||||
buttonDrawInfo.state = kThemeStateInactive;
|
||||
buttonDrawInfo.kind = kThemePushButton;
|
||||
buttonDrawInfo.value = kThemeButtonOn;
|
||||
buttonDrawInfo.adornment = kThemeAdornmentNone;
|
||||
buttonDrawInfo.animation.time.start = 0;
|
||||
buttonDrawInfo.animation.time.current=0;
|
||||
HIThemeDrawButton(&buttonRect, &buttonDrawInfo, context, /*kHIThemeOrientationNormal*/kHIThemeOrientationInverted, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::getTextExtent(const wchar_t *text, int *w, int *h, const Wasabi::FontInfo *fontInfo)
|
||||
{
|
||||
// TODO: turn this code into a svc_fontI, and use api_font here instead
|
||||
size_t len = wcslen(text);
|
||||
UniChar *unistr = (UniChar *)malloc((len + 1) * sizeof(UniChar));
|
||||
UniChar *copy = unistr;
|
||||
while (*text)
|
||||
*copy++=*text++;
|
||||
*copy=0;
|
||||
|
||||
ATSUStyle style;
|
||||
ATSUCreateStyle(&style);
|
||||
|
||||
ATSUTextLayout layout;
|
||||
ATSUCreateTextLayout(&layout);
|
||||
|
||||
ATSUSetTextPointerLocation(layout, unistr, kATSUFromTextBeginning, kATSUToTextEnd, len);
|
||||
|
||||
ATSUSetRunStyle(layout, style, kATSUFromTextBeginning, kATSUToTextEnd);
|
||||
|
||||
Rect imageRect;
|
||||
ATSUMeasureTextImage(layout, kATSUFromTextBeginning, kATSUToTextEnd, 0, 0, &imageRect);
|
||||
*h=(imageRect.bottom - imageRect.top);
|
||||
*w = (imageRect.right - imageRect.left);
|
||||
|
||||
ATSUDisposeTextLayout(layout);
|
||||
ATSUDisposeStyle(style);
|
||||
free(unistr);
|
||||
}
|
||||
|
||||
void Canvas::textOutCentered(RECT *r, const wchar_t *txt, const Wasabi::FontInfo *fontInfo)
|
||||
{
|
||||
textOut(r->left, r->top, txt, fontInfo);
|
||||
}
|
||||
|
||||
|
||||
#define CBCLASS Canvas
|
||||
START_DISPATCH;
|
||||
CB(GETHDC, getHDC);
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
||||
|
||||
BaseCloneCanvas::BaseCloneCanvas(api_canvas *cloner)
|
||||
{
|
||||
if (cloner != NULL) clone(cloner);
|
||||
}
|
||||
|
||||
int BaseCloneCanvas::clone(api_canvas *cloner)
|
||||
{
|
||||
ASSERTPR(context == NULL, "can't clone twice");
|
||||
context = cloner->getHDC();
|
||||
CGContextRetain(context);
|
||||
// bits = cloner->getBits();
|
||||
// cloner->getDim(&width, &height, &pitch);
|
||||
// srcwnd = cloner->getBaseWnd();
|
||||
// cloner->getOffsets(&xoffset, &yoffset);
|
||||
// setTextFont(cloner->getTextFont());
|
||||
// setTextSize(cloner->getTextSize());
|
||||
// setTextBold(cloner->getTextBold());
|
||||
// setTextOpaque(cloner->getTextOpaque());
|
||||
// setTextUnderline(cloner->getTextUnderline());
|
||||
// setTextItalic(cloner->getTextItalic());
|
||||
// setTextAlign(cloner->getTextAlign());
|
||||
// setTextColor(cloner->getTextColor());
|
||||
// setTextBkColor(cloner->getTextBkColor());
|
||||
return (context != NULL);
|
||||
}
|
||||
|
||||
BaseCloneCanvas::~BaseCloneCanvas()
|
||||
{
|
||||
CGContextRelease(context);
|
||||
context = NULL;
|
||||
}
|
||||
|
295
Src/tataki/canvas/win/BltCanvas.cpp
Normal file
295
Src/tataki/canvas/win/BltCanvas.cpp
Normal file
@ -0,0 +1,295 @@
|
||||
#include "bltcanvas.h"
|
||||
#include <tataki/bitmap/bitmap.h>
|
||||
|
||||
BltCanvas::~BltCanvas()
|
||||
{
|
||||
if (hdc == NULL) return ;
|
||||
|
||||
// kill the bitmap and its DC
|
||||
SelectObject(hdc, prevbmp);
|
||||
if (ourbmp)
|
||||
{
|
||||
//GdiFlush();
|
||||
DeleteObject(hbmp);
|
||||
}
|
||||
DeleteDC(hdc);
|
||||
hdc = NULL;
|
||||
|
||||
if (skinbmps)
|
||||
{
|
||||
for (int i=0;i<skinbmps->getNumItems();i++)
|
||||
skinbmps->enumItem(i)->Release();
|
||||
|
||||
delete skinbmps;
|
||||
}
|
||||
if (envelope)
|
||||
envelope->Release();
|
||||
}
|
||||
|
||||
BltCanvas::BltCanvas(HBITMAP bmp)
|
||||
{
|
||||
prevbmp = NULL;
|
||||
bits = NULL;
|
||||
fcoord = TRUE;
|
||||
ourbmp = FALSE;
|
||||
skinbmps = NULL;
|
||||
envelope = NULL;
|
||||
|
||||
hbmp = bmp;
|
||||
ASSERT(hbmp != NULL);
|
||||
|
||||
// create tha DC
|
||||
hdc = CreateCompatibleDC(NULL);
|
||||
prevbmp = (HBITMAP)SelectObject(hdc, hbmp);
|
||||
}
|
||||
|
||||
BltCanvas::BltCanvas()
|
||||
{
|
||||
hbmp = NULL;
|
||||
prevbmp = NULL;
|
||||
bits = NULL;
|
||||
fcoord = TRUE;
|
||||
ourbmp = FALSE;
|
||||
bpp = 32; // TODO: benski> pass as parameter?
|
||||
skinbmps = NULL;
|
||||
envelope = NULL;
|
||||
hdc = CreateCompatibleDC(NULL);
|
||||
}
|
||||
|
||||
BltCanvas::BltCanvas(int w, int h, HWND wnd, int nb_bpp/*, unsigned char *pal, int palsize*/)
|
||||
{
|
||||
hbmp = NULL;
|
||||
prevbmp = NULL;
|
||||
bits = NULL;
|
||||
fcoord = TRUE;
|
||||
ourbmp = FALSE;
|
||||
bpp = nb_bpp;
|
||||
skinbmps = NULL;
|
||||
envelope = NULL;
|
||||
hdc = CreateCompatibleDC(NULL);
|
||||
AllocBitmap(w,h,nb_bpp);
|
||||
|
||||
if (hbmp)
|
||||
{
|
||||
// create tha DC
|
||||
|
||||
if (!hdc) {
|
||||
// int x = GetLastError();
|
||||
}
|
||||
prevbmp = (HBITMAP)SelectObject(hdc, hbmp);
|
||||
}
|
||||
}
|
||||
|
||||
void BltCanvas::AllocBitmap(int w, int h, int nb_bpp)
|
||||
{
|
||||
ASSERT(!hbmp);
|
||||
ASSERT(w != 0 && h != 0);
|
||||
if (w == 0) w = 1;
|
||||
if (h == 0) h = 1;
|
||||
|
||||
BITMAPINFO bmi;
|
||||
MEMZERO(&bmi, sizeof(BITMAPINFO));
|
||||
//bmi.bmiHeader.biClrUsed = 0; // we memzero above, no need
|
||||
//bmi.bmiHeader.biClrImportant = 0; // we memzero above, no need
|
||||
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmi.bmiHeader.biWidth = ABS(w);
|
||||
bmi.bmiHeader.biHeight = -ABS(h);
|
||||
bmi.bmiHeader.biPlanes = 1;
|
||||
bmi.bmiHeader.biBitCount = nb_bpp;
|
||||
bmi.bmiHeader.biCompression = BI_RGB;
|
||||
//bmi.bmiHeader.biSizeImage = 0; // we memzero above, no need
|
||||
//bmi.bmiHeader.biXPelsPerMeter = 0; // we memzero above, no need
|
||||
//bmi.bmiHeader.biYPelsPerMeter = 0; // we memzero above, no need
|
||||
//GdiFlush();
|
||||
hbmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
|
||||
if (hbmp == NULL)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
ourbmp=TRUE;
|
||||
GetObject(hbmp, sizeof(BITMAP), &bm);
|
||||
width = bm.bmWidth;
|
||||
height = ABS(bm.bmHeight);
|
||||
pitch = bm.bmWidthBytes;
|
||||
}
|
||||
|
||||
void *BltCanvas::getBits()
|
||||
{
|
||||
return bits;
|
||||
}
|
||||
|
||||
HBITMAP BltCanvas::getBitmap()
|
||||
{
|
||||
return hbmp;
|
||||
}
|
||||
|
||||
SkinBitmap *BltCanvas::getSkinBitmap()
|
||||
{
|
||||
// make a SkinBitmap envelope
|
||||
if (!envelope)
|
||||
envelope = new SkinBitmap(getBitmap(), getHDC(), 1, getBits());
|
||||
|
||||
// do not delete envelope, it's deleted in destructor
|
||||
return envelope;
|
||||
}
|
||||
|
||||
SkinBitmap *BltCanvas::makeSkinBitmap()
|
||||
{
|
||||
// make a clone of the bitmap - JF> what was that crap about envelopes?
|
||||
SkinBitmap *clone = new SkinBitmap(getBitmap(), getHDC(), 1);
|
||||
|
||||
if (!skinbmps)
|
||||
skinbmps = new PtrList<SkinBitmap>;
|
||||
skinbmps->addItem(clone);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
void BltCanvas::disposeSkinBitmap(SkinBitmap *b)
|
||||
{
|
||||
if (skinbmps->haveItem(b))
|
||||
{
|
||||
skinbmps->removeItem(b);
|
||||
b->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugString("disposeSkinBitmap called on unknown pointer, you should call it from the object used to makeSkinBitmap()\n");
|
||||
}
|
||||
}
|
||||
|
||||
void BltCanvas::fillBits(COLORREF color)
|
||||
{
|
||||
if (bpp == 32)
|
||||
{ // clear out the bits
|
||||
DWORD *dwbits = (DWORD *)bits;
|
||||
MEMFILL<DWORD>(dwbits, color, bm.bmWidth * bm.bmHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void BltCanvas::vflip(int vert_cells)
|
||||
{
|
||||
ASSERT(bits != NULL);
|
||||
// BITMAP bm;
|
||||
// int r = GetObject(hbmp, sizeof(BITMAP), &bm);
|
||||
// if (r == 0) return;
|
||||
int w = bm.bmWidth, h = bm.bmHeight;
|
||||
int bytes = 4 * w;
|
||||
__int8 *tmpbuf = (__int8 *)MALLOC(bytes);
|
||||
if (tmpbuf)
|
||||
{
|
||||
int cell_h = h / vert_cells;
|
||||
for (int j = 0; j < vert_cells; j++)
|
||||
for (int i = 0; i < cell_h / 2; i++)
|
||||
{
|
||||
char *p1, *p2;
|
||||
p1 = (__int8 *)bits + bytes * i + (j * cell_h * bytes);
|
||||
p2 = (__int8 *)bits + bytes * ((cell_h - 1) - i) + (j * cell_h * bytes);
|
||||
if (p1 == p2) continue;
|
||||
MEMCPY(tmpbuf, p1, bytes);
|
||||
MEMCPY(p1, p2, bytes);
|
||||
MEMCPY(p2, tmpbuf, bytes);
|
||||
}
|
||||
FREE(tmpbuf);
|
||||
}
|
||||
}
|
||||
|
||||
void BltCanvas::hflip(int hor_cells)
|
||||
{
|
||||
ASSERT(bits != NULL);
|
||||
// todo: optimize
|
||||
int w = bm.bmWidth, h = bm.bmHeight;
|
||||
for (int i = 0;i < hor_cells;i++)
|
||||
for (int x = 0;x < w / 2 / hor_cells;x++)
|
||||
for (int y = 0;y < h;y++)
|
||||
{
|
||||
int *p = ((int *)bits) + x + y * w + (i * w / hor_cells);
|
||||
int *d = ((int *)bits) + ((w / hor_cells) - x) + y * w + (i * w / hor_cells) - 1;
|
||||
int t = *p;
|
||||
*p = *d;
|
||||
*d = t;
|
||||
}
|
||||
}
|
||||
|
||||
void BltCanvas::maskColor(COLORREF from, COLORREF to)
|
||||
{
|
||||
int n = bm.bmWidth * bm.bmHeight;
|
||||
//GdiFlush();
|
||||
DWORD *b = (DWORD *)getBits();
|
||||
from &= 0xffffff;
|
||||
while (n--)
|
||||
{
|
||||
if ((*b & 0xffffff) == from)
|
||||
{
|
||||
*b = to;
|
||||
}
|
||||
else *b |= 0xff000000; // force all other pixels non masked
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
void BltCanvas::makeAlpha(int newalpha)
|
||||
{
|
||||
int w, h;
|
||||
getDim(&w, &h, NULL);
|
||||
premultiply((ARGB32 *)getBits(), w*h, newalpha);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void BltCanvas::premultiply(ARGB32 *m_pBits, int nwords, int newalpha)
|
||||
{
|
||||
if (newalpha == -1)
|
||||
{
|
||||
for (; nwords > 0; nwords--, m_pBits++)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)m_pBits;
|
||||
unsigned int alpha = pixel[3];
|
||||
if (alpha == 255) continue;
|
||||
pixel[0] = (pixel[0] * alpha) >> 8; // blue
|
||||
pixel[1] = (pixel[1] * alpha) >> 8; // green
|
||||
pixel[2] = (pixel[2] * alpha) >> 8; // red
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; nwords > 0; nwords--, m_pBits++)
|
||||
{
|
||||
unsigned char *pixel = (unsigned char *)m_pBits;
|
||||
pixel[0] = (pixel[0] * newalpha) >> 8; // blue
|
||||
pixel[1] = (pixel[1] * newalpha) >> 8; // green
|
||||
pixel[2] = (pixel[2] * newalpha) >> 8; // red
|
||||
pixel[3] = (pixel[3] * newalpha) >> 8; // alpha
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// benski> this may not be completely safe. it's meant for skinbitmap::blittorect
|
||||
// it doesn't take into account skin bitmaps, enveloped bitmaps, or any other things like that
|
||||
void BltCanvas::DestructiveResize(int w, int h, int nb_bpp)
|
||||
{
|
||||
if (hdc != NULL)
|
||||
{
|
||||
SelectObject(hdc, prevbmp);
|
||||
prevbmp=0;
|
||||
}
|
||||
|
||||
if (ourbmp && hbmp)
|
||||
{
|
||||
DeleteObject(hbmp);
|
||||
hbmp=NULL;
|
||||
ourbmp=FALSE;
|
||||
}
|
||||
|
||||
// create tha DC
|
||||
if (hdc == NULL)
|
||||
hdc = CreateCompatibleDC(NULL);
|
||||
|
||||
AllocBitmap(w,h,nb_bpp);
|
||||
|
||||
prevbmp = (HBITMAP)SelectObject(hdc, hbmp);
|
||||
if (envelope) envelope->Release();
|
||||
envelope=0;
|
||||
}
|
41
Src/tataki/canvas/win/bltcanvas.h
Normal file
41
Src/tataki/canvas/win/bltcanvas.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef _BLTCANVAS_H
|
||||
#define _BLTCANVAS_H
|
||||
|
||||
#include "canvas.h"
|
||||
#include <tataki/export.h>
|
||||
#include <bfc/ptrlist.h>
|
||||
class TATAKIAPI BltCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
BltCanvas();
|
||||
BltCanvas(int w, int h, HWND wnd=NULL, int nb_bpp=32/*, unsigned __int8 *pal=NULL,int palsize=0*/);
|
||||
BltCanvas(HBITMAP bmp);
|
||||
virtual ~BltCanvas();
|
||||
void *getBits();
|
||||
HBITMAP getBitmap();
|
||||
SkinBitmap *makeSkinBitmap(); // this one makes a new, with own bits
|
||||
SkinBitmap *getSkinBitmap(); // this one gives a skinbitmap envoloppe of this bltcanvas
|
||||
void disposeSkinBitmap(SkinBitmap *b); // call only after makeSkinBitmap
|
||||
|
||||
void fillBits(COLORREF color);
|
||||
|
||||
void vflip(int vert_cells=1);
|
||||
void hflip(int hor_cells=1);
|
||||
void maskColor(COLORREF from, COLORREF to);
|
||||
void makeAlpha(int newalpha=-1); // -1 = premultiply using current alpha
|
||||
|
||||
void DestructiveResize(int w, int h, int nb_bpp = 32); // resizes the bitmap, destroying the contents
|
||||
private: // NONPORTABLE
|
||||
|
||||
void AllocBitmap(int w, int h, int nb_bpp);
|
||||
HBITMAP hbmp, prevbmp;
|
||||
PtrList<SkinBitmap> *skinbmps;
|
||||
SkinBitmap *envelope;
|
||||
BITMAP bm;
|
||||
bool ourbmp;
|
||||
int bpp;
|
||||
|
||||
//void premultiply(ARGB32 *m_pBits, int nwords, int newalpha=-1);
|
||||
};
|
||||
|
||||
#endif
|
368
Src/tataki/canvas/win/canvas.h
Normal file
368
Src/tataki/canvas/win/canvas.h
Normal file
@ -0,0 +1,368 @@
|
||||
//NONPORTABLE: the interface is portable, but the implementation sure isn't
|
||||
#ifndef _CANVAS_H
|
||||
#define _CANVAS_H
|
||||
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
#include <ddraw.h>
|
||||
#endif
|
||||
|
||||
//#include <bfc/common.h>
|
||||
#include <tataki/export.h>
|
||||
|
||||
class Canvas;
|
||||
class MemCanvasBmp;
|
||||
class BaseWnd;
|
||||
class ifc_window;
|
||||
class api_region;
|
||||
class SkinBitmap;
|
||||
|
||||
#include <bfc/stack.h>
|
||||
#include <api/service/svcs/svc_font.h> // for STDFONT_* stuff. should make a std_font thingy later
|
||||
#include <bfc/dispatch.h>
|
||||
|
||||
enum {
|
||||
#ifdef WIN32
|
||||
PENSTYLE_SOLID = PS_SOLID,
|
||||
PENSTYLE_DASH = PS_DASH,
|
||||
PENSTYLE_DOT = PS_DOT,
|
||||
#else
|
||||
PENSTYLE_SOLID = LineSolid,
|
||||
PENSTYLE_DASH = LineDoubleDash,
|
||||
PENSTYLE_DOT = LineDoubleDash,
|
||||
#endif
|
||||
};
|
||||
|
||||
#include <tataki/canvas/ifc_canvas.h>
|
||||
class ifc_canvas;
|
||||
class RegionI;
|
||||
typedef struct
|
||||
{
|
||||
int style;
|
||||
int width;
|
||||
COLORREF color;
|
||||
HPEN hpen;
|
||||
}
|
||||
penstruct;
|
||||
|
||||
class TATAKIAPI NOVTABLE Canvas : public ifc_canvas
|
||||
{
|
||||
protected:
|
||||
Canvas();
|
||||
public:
|
||||
virtual ~Canvas();
|
||||
|
||||
// ifc_canvas stuff
|
||||
HDC getHDC();
|
||||
ifc_window *getRootWnd();
|
||||
void *getBits();
|
||||
void getOffsets(int *x, int *y);
|
||||
bool isFixedCoords();
|
||||
bool getDim(int *w, int *h, int *p);
|
||||
void setBaseWnd(BaseWnd *b);
|
||||
// end ifc_canvas stuff
|
||||
|
||||
virtual BaseWnd *getBaseWnd();
|
||||
|
||||
// graphics commands
|
||||
void fillRect(const RECT *r, COLORREF color);
|
||||
void fillRectAlpha(const RECT *r, COLORREF color, int alpha);
|
||||
void fillRgn(RegionI *r, COLORREF color);
|
||||
void drawRect(const RECT *r, int solid, COLORREF color, int alpha = 255);
|
||||
|
||||
// text commands
|
||||
const wchar_t *getTextFont();
|
||||
int getTextSize();
|
||||
int getTextBold();
|
||||
int getTextAntialias();
|
||||
int getTextOpaque();
|
||||
int getTextUnderline();
|
||||
int getTextItalic();
|
||||
int getTextAlign();
|
||||
COLORREF getTextColor();
|
||||
COLORREF getTextBkColor();
|
||||
|
||||
void pushPen(COLORREF color);
|
||||
void pushPen(int style, int width, COLORREF color);
|
||||
void popPen();
|
||||
|
||||
int getPenStyle();
|
||||
COLORREF getPenColor();
|
||||
int getPenWidth();
|
||||
|
||||
// normal text
|
||||
void textOut(int x, int y, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
void textOut(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
void textOutEllipsed(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
// returns height used
|
||||
void textOutWrapped(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
void textOutWrappedPathed(int x, int y, int w, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
void textOutCentered(RECT *r, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
|
||||
|
||||
int getTextWidth(const wchar_t *text, const Wasabi::FontInfo *fontInfo);
|
||||
int getTextHeight(const wchar_t *text, const Wasabi::FontInfo *fontInfo);
|
||||
void getTextExtent(const wchar_t *text, int *w, int *h, const Wasabi::FontInfo *fontInfo);
|
||||
int getTextHeight(const Wasabi::FontInfo *fontInfo)
|
||||
{
|
||||
return getTextHeight(L"M", fontInfo);
|
||||
}
|
||||
|
||||
void selectClipRgn(api_region *r);
|
||||
int getClipBox(RECT *r); // returns 0 if no clipping region
|
||||
int getClipRgn(api_region *r); // returns 0 if no clipping region
|
||||
|
||||
// Deprecated?
|
||||
void moveTo(int x, int y);
|
||||
void lineTo(int x, int y);
|
||||
|
||||
void lineDraw(int fromX, int fromY, int toX, int toY);
|
||||
|
||||
void drawSysObject(const RECT *r, int sysobj, int alpha = 255);
|
||||
|
||||
void blit(int srcx, int srcy, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
|
||||
void blitAlpha(ifc_canvas *canvas, int x, int y, int alpha = 255);
|
||||
void blitToRect(ifc_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
|
||||
void stretch(ifc_canvas *canvas, int x, int y, int w, int h);
|
||||
// src* are in 16.16 fixed point
|
||||
void stretchblit(int srcx, int srcy, int srcw, int srch, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
|
||||
void stretchToRectAlpha(ifc_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
|
||||
void antiAliasTo(Canvas *dest, int w, int h, int aafactor);
|
||||
|
||||
int getXOffset() const
|
||||
{
|
||||
return xoffset;
|
||||
}
|
||||
int getYOffset() const
|
||||
{
|
||||
return yoffset;
|
||||
}
|
||||
void offsetRect(RECT *r);
|
||||
void debug();
|
||||
|
||||
void colorToColor(COLORREF from, COLORREF to, RECT *r);
|
||||
double getSystemFontScale();
|
||||
static void premultiply(ARGB32 *m_pBits, int nwords, int newalpha = -1);
|
||||
|
||||
protected:
|
||||
const Wasabi::FontInfo *getFontInfo()
|
||||
{
|
||||
if (userFontInfo)
|
||||
return userFontInfo;
|
||||
else
|
||||
return &canvasFontInfo;
|
||||
}
|
||||
|
||||
RECVS_DISPATCH;
|
||||
|
||||
HDC hdc;
|
||||
void *bits;
|
||||
int width, height, pitch;
|
||||
bool fcoord;
|
||||
int xoffset, yoffset;
|
||||
BaseWnd *srcwnd;
|
||||
Wasabi::FontInfo canvasFontInfo; // to hold our defaults
|
||||
const Wasabi::FontInfo *userFontInfo; // passed from someone calling this function. usually is NULL
|
||||
|
||||
private:
|
||||
Stack<penstruct> penstack;
|
||||
|
||||
int penstyle;
|
||||
COLORREF pencolor;
|
||||
int penwidth;
|
||||
|
||||
#ifdef WIN32
|
||||
HPEN defpen;
|
||||
HPEN curpen;
|
||||
#endif
|
||||
#ifdef LINUX
|
||||
int raster_x, raster_y;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
namespace DrawSysObj
|
||||
{
|
||||
enum {
|
||||
BUTTON, BUTTON_PUSHED, BUTTON_DISABLED,
|
||||
OSBUTTON, OSBUTTON_PUSHED, OSBUTTON_DISABLED,
|
||||
OSBUTTON_CLOSE, OSBUTTON_CLOSE_PUSHED, OSBUTTON_CLOSE_DISABLED,
|
||||
OSBUTTON_MINIMIZE, OSBUTTON_MINIMIZE_PUSHED, OSBUTTON_MINIMIZE_DISABLED,
|
||||
OSBUTTON_MAXIMIZE, OSBUTTON_MAXIMIZE_PUSHED, OSBUTTON_MAXIMIZE_DISABLED,
|
||||
};
|
||||
};
|
||||
|
||||
class TATAKIAPI WndCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
WndCanvas();
|
||||
WndCanvas(BaseWnd *basewnd);
|
||||
virtual ~WndCanvas();
|
||||
|
||||
// address client area
|
||||
int attachToClient(BaseWnd *basewnd);
|
||||
//CUT // address entire window
|
||||
//CUT int attachToWnd(HWND _hWnd); // NONPORTABLE: avoid! mostly for mainwnd
|
||||
|
||||
private:
|
||||
HWND hWnd;
|
||||
};
|
||||
|
||||
class TATAKIAPI PaintCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
PaintCanvas();
|
||||
virtual ~PaintCanvas();
|
||||
|
||||
int beginPaint(BaseWnd *basewnd);
|
||||
int beginPaint(HWND wnd);
|
||||
void getRcPaint(RECT *r);
|
||||
|
||||
private: // NONPORTABLE
|
||||
HWND hWnd;
|
||||
PAINTSTRUCT ps;
|
||||
};
|
||||
|
||||
class BltCanvas;
|
||||
class TATAKIAPI PaintBltCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
PaintBltCanvas();
|
||||
virtual ~PaintBltCanvas();
|
||||
int beginPaint(BaseWnd *basewnd);
|
||||
int beginPaintNC(BaseWnd *basewnd);
|
||||
|
||||
void *getBits();
|
||||
void getRcPaint(RECT *r);
|
||||
|
||||
private: // NONPORTABLE
|
||||
HWND hWnd;
|
||||
PAINTSTRUCT ps;
|
||||
HDC wnddc;
|
||||
HBITMAP hbmp, prevbmp;
|
||||
bool nonclient;
|
||||
#ifdef LINUX
|
||||
BltCanvas *blitter;
|
||||
#endif
|
||||
};
|
||||
|
||||
class TATAKIAPI MemCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
MemCanvas();
|
||||
virtual ~MemCanvas();
|
||||
|
||||
int createCompatible(Canvas *canvas);
|
||||
private:
|
||||
};
|
||||
|
||||
class TATAKIAPI DCCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
DCCanvas(HDC clone = NULL, BaseWnd *srcWnd = NULL);
|
||||
virtual ~DCCanvas();
|
||||
|
||||
int cloneDC(HDC clone, BaseWnd *srcWnd = NULL);
|
||||
};
|
||||
|
||||
class TATAKIAPI SysCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
SysCanvas();
|
||||
virtual ~SysCanvas();
|
||||
};
|
||||
|
||||
/* benski>
|
||||
a quick Canvas class to be created on-the-fly when you need to retrieve information about fonts
|
||||
e.g. getTextExtent
|
||||
don't try to draw with it or bad things will happen.
|
||||
|
||||
*/
|
||||
class TATAKIAPI TextInfoCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
TextInfoCanvas(BaseWnd *basewnd);
|
||||
virtual ~TextInfoCanvas();
|
||||
private:
|
||||
HWND hWnd;
|
||||
};
|
||||
|
||||
class TATAKIAPI DCBltCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
DCBltCanvas();
|
||||
virtual ~DCBltCanvas();
|
||||
|
||||
int cloneDC(HDC clone, RECT *r, BaseWnd *srcWnd = NULL);
|
||||
int setOrigDC(HDC neworigdc); // set to null to prevent commitdc on delete, non null to change destination dc
|
||||
int commitDC(void); // allows commit to DC without deleting
|
||||
#if 0
|
||||
int cloneCanvas(ifc_canvas *clone, RECT *r);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
HDC origdc;
|
||||
RECT rect;
|
||||
HBITMAP hbmp, prevbmp;
|
||||
};
|
||||
|
||||
class TATAKIAPI DCExBltCanvas : public DCBltCanvas
|
||||
{
|
||||
public:
|
||||
DCExBltCanvas(HWND hWnd, HRGN hrgnClip, DWORD flags);
|
||||
|
||||
~DCExBltCanvas();
|
||||
private:
|
||||
HWND hwnd;
|
||||
};
|
||||
|
||||
|
||||
// note: getBaseWnd() returns NULL for this class
|
||||
class TATAKIAPI BaseCloneCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
BaseCloneCanvas(ifc_canvas *cloner = NULL);
|
||||
virtual ~BaseCloneCanvas();
|
||||
|
||||
int clone(ifc_canvas *cloner);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
class TATAKIAPI DDSurfaceCanvas : public Canvas
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
DDSurfaceCanvas(LPDIRECTDRAWSURFACE surface, int w, int h);
|
||||
virtual ~DDSurfaceCanvas();
|
||||
|
||||
int isready();
|
||||
void enter();
|
||||
void exit();
|
||||
|
||||
private:
|
||||
LPDIRECTDRAWSURFACE surf;
|
||||
int _w, _h;
|
||||
};
|
||||
#endif
|
||||
|
||||
class TATAKIAPI BitsCanvas : public Canvas
|
||||
{
|
||||
public:
|
||||
BitsCanvas(void *_bits, int _w, int _h)
|
||||
{
|
||||
bits=_bits;
|
||||
width=_w;
|
||||
height=_h;
|
||||
pitch=_w;
|
||||
}
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ALIGN_LEFT,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT
|
||||
};
|
||||
|
||||
#endif
|
1489
Src/tataki/canvas/win/win32_canvas.cpp
Normal file
1489
Src/tataki/canvas/win/win32_canvas.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user