📄 eb_graphics.h
字号:
/***************************************************************************
EB_Graphics.h -
-------------------
begin : Tue Mar 3 2004
copyright : (C) 2004 by DigitalAirways
email : info@digitalairways.com
***************************************************************************/
/*
* Copyright (c) 2000-2004 DigitalAirways, sarl. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* DigitalAirways, sarl. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with DigitalAirways.
* A copy of this license is included in the licence.txt file included
* on this software package.
*/
/*
**************************************************************
* TODO
**************************************************************
-
**************************************************************
* HISTORY
**************************************************************
-
*/
#ifndef __EB_GRAPHICS__
#define __EB_GRAPHICS__
#include "EB_Defs.h"
#include "EB_GContext.h"
class PFWImage ;
class Font ;
class GContext ;
// The mode used for drawing are defined by:
// 0xaabbccdd
// aa : not yet defined
// bb : not yet defined
// cc : line styles
// dd : pixel operations
#define DRAW_LINE_MASK 0x0000ff00
#define DRAW_LINE_SOLID 0x00000000
#define DRAW_LINE_NO 0x00000100
#define DRAW_LINE_DOTTED 0x00000200
#define DRAW_LINE_DASHED 0x00000300
//
#define DRAW_PIXOP_MASK 0x000000ff
#define DRAW_PIXOP_NO 0x00000000
#define DRAW_PIXOP_OVER 0x00000001
// No default implementation for:
#define DRAW_PIXOP_XOR 0x00000002
#define GRAPHICSET_TRANSPARENT 0x00000001
#define GRAPHICSET_DRAWCOLOR 0x00000002
#define GRAPHICSET_TEXTCOLOR 0x00000004
#define GRAPHICSET_DRAWREGION 0x00000008
#define GRAPHICSET_RSVDREGION 0x00000010
// The pixel coding structure used by this Graphics may
// may be described by a unique 32 bit word where:
// Bit 20-31 : not assigned. Must be 0.
// Bit 19 : 1 if the surface is a primary one
// Bit 18 : 1 if the surface is in readonly mode
// Bit 17 : 1 if the RGB coding is not regular
// Bit 16 : 1 if alpha is supported
// Bit 12-15 : number of bits for the A channel
// Bit 8-11 : number of bits for the R channel
// Bit 4-7 : number of bits for the G channel
// Bit 0-3 : number of bits for the B channel
//
// NOTE: it is a good practise to consider that the macro
// PIXFORMAT_DYNAMIC_FORMAT must be used to contain the
// description of the channels + alpha used by the current
// PFWGraphics implementation. This is normamlly defined just
// after the include of EB_Graphics.h in EB_PFWGraphics.h
#define PIXFORMAT_PRIMARY 0x00080000
#define PIXFORMAT_READONLY 0x00040000
#define PIXFORMAT_REGULARCODING 0x00020000
#define PIXFORMAT_USINGALPHA 0x00010000
#define PIXFORMAT_ALLCHANNELS 0x0000FFFF
#define PIXFORMAT_CHANNELDESC (PIXFORMAT_REGULARCODING|PIXFORMAT_USINGALPHA|PIXFORMAT_ALLCHANNELS)
// Pixel formats' masks
#define IS_PRIMARY(X) (X&PIXFORMAT_PRIMARY)
#define IS_READONLY(X) (X&PIXFORMAT_READONLY)
#define IS_REGULARCODING(X) (!(X&PIXFORMAT_REGULARCODING))
#define IS_USEALPHA(X) (X&PIXFORMAT_USINGALPHA)
#define GET_A_BITNUM(X) ((X>>12)&0x0f)
#define GET_R_BITNUM(X) ((X>>8)&0x0f)
#define GET_G_BITNUM(X) ((X>>4)&0x0f)
#define GET_B_BITNUM(X) (X&0x0f)
#define GET_PIXEL_BITNUM(X) (GET_A_BITNUM(X)+GET_R_BITNUM(X)+GET_G_BITNUM(X)+GET_B_BITNUM(X))
#define L_IS_PRIMARY IS_PRIMARY(surfaceDesc)
#define L_IS_READONLY IS_READONLY(surfaceDesc)
#define L_IS_REGULARCODING IS_REGULARCODING(surfaceDesc)
#define L_IS_USEALPHA IS_USEALPHA(surfaceDesc)
#define L_GET_A_BITNUM GET_A_BITNUM(surfaceDesc)
#define L_GET_R_BITNUM GET_R_BITNUM(surfaceDesc)
#define L_GET_G_BITNUM GET_G_BITNUM(surfaceDesc)
#define L_GET_B_BITNUM GET_B_BITNUM(surfaceDesc)
#define L_GET_PIXEL_BITNUM GET_PIXEL_BITNUM(surfaceDesc)
// Standard pixel formats
// A : alpha channel
// R : red channel
// G : green channel
// B : blue channel
// X : unused channel
// WARNING: when a new format is added here, a reference to it must be added to
// refA, refB
// 8 bit RGB : TODO refA & refB not yet updated
#define PIXFORMAT_RGB332 0x00000332
// 16 bit RGB with transparency : TODO refA & refB not yet updated
#define PIXFORMAT_ARGB1555 0x00011555
// 16 bit RGB without transparency
#define PIXFORMAT_RGB565 0x00000565
#define PIXFORMAT_XRGB1555 0x00001555
// 32 bit alphaful RGB
#define PIXFORMAT_ARGB8888 0x00018888
// 32 bit alphaless RGB : TODO refA & refB not yet updated
#define PIXFORMAT_XRGB8888 0x00008888
// refA : and when a line is added here...
#define EXTRACT_XRGB1555_TO_RGB(PIXVAL, RVAL, GVAL, BVAL) RVAL = (PIXVAL>>7) & 0xf8; GVAL = (PIXVAL>>2) & 0xf8; BVAL = (PIXVAL<<3) & 0xf8;
#define EXTRACT_RGB565_TO_RGB(PIXVAL, RVAL, GVAL, BVAL) RVAL = (PIXVAL& 0xF800)>>8; GVAL = (PIXVAL&0x07E0)>>3; BVAL = (PIXVAL & 0x1F)<<3;
#define EXTRACT_BGR565_TO_RGB(PIXVAL, RVAL, GVAL, BVAL) BVAL = (PIXVAL& 0xF800)>>8; GVAL = (PIXVAL&0x07E0)>>3; RVAL = (PIXVAL & 0x1F)<<3;
#define EXTRACT_ARGB8888_TO_RGB(PIXVAL, RVAL, GVAL, BVAL) RVAL = (PIXVAL>>16) & 0xff; GVAL = (PIXVAL>>8) & 0xff; BVAL = PIXVAL & 0xff;
// ...a reference to it must also be added there.
#define EXTRACT_RGB(PIXTYPE, PIXVAL, RVAL, GVAL, BVAL) switch(PIXTYPE) { case PIXFORMAT_XRGB1555: EXTRACT_XRGB1555_TO_RGB(PIXVAL, RVAL, GVAL, BVAL); break; case PIXFORMAT_RGB565: EXTRACT_RGB565_TO_RGB(PIXVAL, RVAL, GVAL, BVAL) ; break; case PIXFORMAT_ARGB8888: default: EXTRACT_ARGB8888_TO_RGB(PIXVAL, RVAL, GVAL, BVAL); break; }
// refB : and when a line is added here...
#define ASSEMBLE_RGB_TO_XRGB1555(PIXVAL, RVAL, GVAL, BVAL) PIXVAL = ((RVAL & 0xf8) <<7) | ((GVAL & 0xf8) <<2) | ((BVAL & 0xf8) >>3);
#define ASSEMBLE_RGB_TO_RGB565(PIXVAL, RVAL, GVAL, BVAL) PIXVAL = (short) (((RVAL & 0xf8) <<8) | ((GVAL & 0xfc) <<3) | ((BVAL & 0xf8) >>3));
#define ASSEMBLE_RGB_TO_ARGB8888(PIXVAL, RVAL, GVAL, BVAL) PIXVAL = ((0xff<<24) | (RVAL<<16) | (GVAL<<8) | BVAL);
// ...a reference to it must also be added there.
#define ASSEMBLE_RGB(PIXTYPE, PIXVAL, RVAL, GVAL, BVAL) switch(PIXTYPE) { case PIXFORMAT_XRGB1555: ASSEMBLE_RGB_TO_XRGB1555(PIXVAL, RVAL, GVAL, BVAL); break; case PIXFORMAT_RGB565: ASSEMBLE_RGB_TO_RGB565(PIXVAL, RVAL, GVAL, BVAL) ; break; case PIXFORMAT_ARGB8888: default: ASSEMBLE_RGB_TO_ARGB8888(PIXVAL, RVAL, GVAL, BVAL); break; }
#define ARGB8888_TO_RGBARGS(C) (C>>16)&0xff,(C>>8)&0xff,C&0xff
#define ARGB8888_TO_ARGBARGS(C) (C>>24)&0xff,(C>>16)&0xff,(C>>8)&0xff,C&0xff
#define ARGB8888_TO_RGBAARGS(C) (C>>16)&0xff,(C>>8)&0xff,C&0xff,(C>>24)&0xff
class KREBDLIBS_API Graphics
{
protected:
int graphicSet ;
Font *currentFont;
GContext* gContext ;
int transparent ;
unsigned char alpha;
#ifdef USE_DEPRECATED
int onScreen ; // Deprecated: use surfaceDesc and PIXFORMAT_PRIMARY
#endif // NODEPRECATED
unsigned long surfaceDesc ;
char currentR ;
char currentG ;
char currentB ;
char currentA ;
char textR ;
char textG ;
char textB ;
char textA ;
void setChannelCoding(unsigned long newCoding)
{
// Reset the previous coding
surfaceDesc &= !PIXFORMAT_CHANNELDESC ;
// Reset the previous coding
surfaceDesc |= (newCoding&PIXFORMAT_CHANNELDESC) ;
return;
}
protected:
// This method is used to implement drawExtract and drawMask
void drawFrom(int xT, int yT, Graphics* from, int xF, int yF, int w, int h, boolean useMask, unsigned char tR, unsigned char tG, unsigned char tB) ;
public:
DEFINE_NEW(Graphics);
DEFINE_DELETE(Graphics);
/*
* Creates a new instance, without managing any content for the moment.
*/
Graphics(GContext* newGContext) ;
/*
* Creates a new instance, using a content that already exists.
* Note that the content is not duplicated, a new reference is just
* added on it.
*/
Graphics(GContext* newGContext, int handle);
/*
* Creates a new instance and sets as its content an Image whose
* src is provided.
*/
Graphics(GContext* newGContext, unsigned char* src) ;
/*
* Creates a new instance and initialize it with an empty surface.
* onScreen==TRUE when this graphics is using the screen as its surface.
*/
Graphics(GContext* newGContext, int width, int height, int newOnScreen=0) ;
/*
* This dtor is freeing all its resources. This may be dangerous if it
* as been created from existing ones.
*/
virtual ~Graphics() {;}
/*
* Init
*/
void init(GContext* newGContext, int newOnScreen) ;
/*
<api>
<class>Graphics</class>
<method>getHandle</method>
<java></java>
<cpp>virtual int getHandle()=0</cpp>
<descr>
<p>This method Returns a handle to the current Graphics. The semantics of this handle depends on the graphic toolkit actually used, but it is usually a pointer to the graphic surface's structure.</p>
</descr>
</api>
*/
virtual int getHandle()=0 ;
/*
* Return a pointer on the surface's buffer itself. Note that it may be dangerous to use the returned value
* without knowing its internal structure.
*/
virtual void* getSurfaceBuffer() { return NULL; }
/*
*
*/
virtual GContext* getContext() { return gContext; }
/*
<api>
<class>Graphics</class>
<method>duplicate</method>
<java>Graphics duplicate()</java>
<cpp>virtual Graphics* duplicate()</cpp>
<descr>
<p>This method returns a duplicated version of the current graphics. The surface is supposed to be fully duplicated. There is no assigned font.</p>
</descr>
</api>
*/
virtual Graphics* duplicate()=0 ;
/*
*
*/
virtual void clear()
{ ; } // There is not default implentation.
/*
*
*/
virtual void getImage(unsigned char* /*data*/, int /*dataLen*/)
{ ; }
/*
*
*/
virtual void getImage(unsigned char *szNewImageURL)=0 ;
/*
<api>
<class>Graphics</class>
<method>drawBitmap</method>
<java>public final void drawBitmap(int x, int y, PFWImage image) </java>
<cpp>virtual void drawBitmap(int x, int y, Graphics* gSource)</cpp>
<descr>
<p>This method draws a source Graphics or PFWImage on the current one.</p>
</descr>
</api>
*/
virtual void drawBitmap(int x, int y, Graphics* gSource) ;
/*
* This method must be called when the pending modifications on the
* surface must be committed.
*/
virtual void update()=0 ;
/*
<api>
<class>Graphics</class>
<method>getWidth</method>
<java>int getWidth(String string)</java>
<cpp>virtual int getWidth(char* string)</cpp>
<descr>
<p>Returns the width of a string in the current Font of the Graphics.</p>
</descr>
<notes></notes>
<examples></examples>
</api>
*/
virtual int getWidth()=0 ;
/*
<api>
<class>Graphics</class>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -