⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwin.h

📁 Very very small GUI. Usefull for small system, without OS or small OS. Event driven, support user m
💻 H
📖 第 1 页 / 共 4 页
字号:
#ifndef PWIN_H
#define PWIN_H

/* -------------------------------------------------------------------------- */

/** False definition. */
#ifndef FALSE
  #define FALSE 0
#endif

/** True definition. */
#ifndef TRUE
  #define TRUE (!FALSE)
#endif

/** NULL definition. */
#define PW_NULL 0
#ifndef NULL
	#define		NULL		0
#endif

#ifdef  GLOBAL_PW_VARS
#define GLOBAL_PW_ EXTRN
#else
#define GLOBAL_PW_EXTRN  extern
#endif

/* -------------------------------------------------------------------------- */

/** Maximum number of extra input events. */
#define PW_XINPUTS_MAX_NUM  22 

/* -------------------------------------------------------------------------- */

#define	BLACK_COLOR			0
#define WHITE_COLOR			255

#define PW_UP_KEY_CODE     1 
#define PW_DOWN_KEY_CODE   2 
#define PW_LEFT_KEY_CODE   3
#define PW_RIGHT_KEY_CODE  4 
#define PW_NEXT_KEY_CODE   5 
#define PW_PREV_KEY_CODE   6 
#define PW_YES_KEY_CODE    7 
    
#define OK_BUTT_ID			0x0100
#define CANCEL_BUTT_ID		0x0200
#define INPUTTEXT_ID		0x0400
#define STATICTEXT_ID		0x0800
#define PROGRESSBAR_ID		0x1000
#define ONOFFTEXT_ID		0x2000

typedef enum _DEV_GUI_MessageType {
	DEV_NONE_MSG,
	GUI_BUTTON_PRESSED,
	GUI_QUERY_CANCELED,
	DEV_STOPPED_MSG,
	DEV_STATUS_MSG,

	DEV_WAIT_MSG,
	DEV__HIDE_WAIT_MSG,
//	Add you message ID
} DEV_GUI_MessageType;

/* -------------------------------------------------------------------------- */
#define MSG_ERROR		1
#define MSG_WARNING		2
#define MSG_INFO		3

/* -------------------------------------------------------------------------- */
/**
 *  Returns the greater of two numbers.
 *  @param _a_ number 1
 *  @param _b_ number 2
 *  @return the greater of @p a and @p b
 */
#define PW_MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_))

/**
 *  Returns the smaller of two numbers.
 *  @param _a_ number 1
 *  @param _b_ number 2
 *  @return the smaller of @p a and @p b
 */
#define PW_MIN(_a_, _b_) ((_a_) < (_b_) ? (_a_) : (_b_))

/**
 *  Returns the absolute value of @p a.
 *  @param _a_ number 
 *  @return the absolute value of @p a 
 */
#define PW_ABS(_a_)      ((_a_) <  0  ? (-(_a_)) : (_a_))

#define	pw_black_pixel		BLACK_COLOR
#define	pw_white_pixel		WHITE_COLOR
/* -------------------------------------------------------------------------- */

typedef unsigned char      Pw_Byte;    /**< Byte type. */
typedef char               Pw_Char;    /**< Charachter type. */
typedef unsigned char      Pw_uChar;   /**< Unsigned charachter type. */
typedef short              Pw_Short;   /**< Short integer type. */
typedef unsigned short     Pw_uShort;  /**< Unsigned short integer type. */
typedef int                Pw_Int;     /**< Integer type. */
typedef signed char        Pw_Int8;    /**< 8 bit integer type. */
typedef short              Pw_Int16;   /**< 16 bit integer type. */
typedef int                Pw_Int32;   /**< 32 bit integer type. */
typedef unsigned int       Pw_uInt;    /**< Unsigned integer type. */
typedef unsigned char      Pw_uInt8;   /**< 8 bit unsigned integer type. */
typedef unsigned short     Pw_uInt16;  /**< 16 bit unsigned integer type. */
typedef unsigned int       Pw_uInt32;  /**< 32 bit unsigned integer type. */
typedef long               Pw_Long;    /**< Long integer type. */
typedef unsigned long      Pw_uLong;   /**< Unsigned long integer type. */
typedef float              Pw_Float;   /**< Float type. */
typedef double             Pw_Double;  /**< Double type. */
typedef int                Pw_Bool;    /**< Boolean type. */
typedef void*              Pw_Pointer; /**< Generic pointer type. */
typedef Pw_uInt32          Pw_Addr;    /**< Address type. */
typedef Pw_Int16           Pw_Coord;   /**< Coordinate type. */

/* -------------------------------------------------------------------------- */
//int _Pw_Color;
//int	 Pw_Color; 
     			  /**< Color type. */ // mvd
typedef struct _Pw_Point        Pw_Point;        /**< Point type. */
typedef struct _Pw_Segment      Pw_Segment;      /**< Line segment type. */
typedef struct _Pw_Rectangle    Pw_Rectangle;    /**< Rectangle type. */
typedef struct _Pw_Mat3d        Pw_Mat3d;        /**< 3D matrix type. */
typedef struct _Pw_Region       Pw_Region;       /**< Region type. */
typedef struct _Pw_RegionList   Pw_RegionList;   /**< Region list type. */
//typedef struct _Pw_Color        Pw_Color;      /**< Color type. */ // mvd
//typedef int				        Pw_Color;    /**< Color type. */ // mvd
typedef struct _Pw_Bitmap       Pw_Bitmap;       /**< Bitmap type. */
typedef struct _Pw_Font         Pw_Font;         /**< Font type. */
typedef struct _Pw_FontCharInfo Pw_FontCharInfo; /**< Font char info type. */
typedef struct _Pw_Drawable     Pw_Drawable;     /**< Drawable type. */
typedef struct _Pw_DD           Pw_DD;           /**< Display driver fn type. */
typedef struct _Pw_LLD          Pw_LLD;          /**< LL drawing fn type. */
typedef struct _Pw_GC           Pw_GC;           /**< Graphic context type. */
typedef struct _Pw_EventData    Pw_EventData;    /**< Event data type. */
typedef struct _Pw_KeyEvent     Pw_KeyEvent;     /**< Key event type. */
typedef struct _Pw_XInputEvent  Pw_XInputEvent;  /**< Extra input event type. */
typedef struct _Pw_FocusEvent   Pw_FocusEvent;   /**< Focus event type. */
typedef struct _Pw_MappingEvent Pw_MappingEvent; /**< Mapping event type. */
typedef struct _Pw_ReshapeEvent Pw_ReshapeEvent; /**< Reshape event type. */
typedef struct _Pw_DestroyEvent Pw_DestroyEvent; /**< Destroy event type. */
typedef union  _Pw_Event        Pw_Event;        /**< Event union type. */
typedef struct _Pw_Timeout      Pw_Timeout;      /**< Timeout type. */
typedef struct _Pw_Window       Pw_Window;       /**< Window type. */
typedef struct _Pw_Display      	Pw_Display;  /**< Display type. */
typedef struct _Pw_UserEvent	Pw_UserEvent;
			   
/* -------------------------------------------------------------------------- */
/**
 *  A type name for event callback.
 *  @param Pw_Event event
 */

typedef Pw_Bool (*Pw_EventCb)(Pw_Event*);

/**
 *  A type name for repaint callback.
 *  @param Pw_GC graphic context
 */
typedef void (*Pw_RepaintCb)(Pw_GC*);

/**
 *  A type name for timeout callback.
 *  @param Pw_Display display
 *  @param Pw_Pointer client data
 */
typedef Pw_Bool (*Pw_TimeoutCb) (Pw_Display*, Pw_Pointer);

/* -------------------------------------------------------------------------- */

/**
 *  Types of drawables.
 */
typedef enum _Pw_DrawableType {
    Pw_DrawableWindowType, /**< Type of drawable wich applies to windows. */
    Pw_DrawableBitmapType  /**< Type of drawable wich applies to bitmaps. */
} Pw_DrawableType;

/**
 *  Types of events.
 */
typedef enum _Pw_EventType {
    Pw_KeyPressEventType,   /**< Type of key pressed event. */
    Pw_KeyReleaseEventType, /**< Type of key released event. */
    Pw_XInputEventType,     /**< Type of xinput event. */
    Pw_FocusInEventType,    /**< Type of focus in (gained) event. */
    Pw_FocusOutEventType,   /**< Type of focus out (lost) event. */
    Pw_MapEventType,        /**< Type of window mapped event. */
    Pw_UnmapEventType,      /**< Type of window unmapped event. */
    Pw_ReshapeEventType,    /**< Type of window reshaped event. */
    Pw_DestroyEventType,     /**< Type of window destroyed event. */
	Pw_UserEventType
} Pw_EventType;

/* -------------------------------------------------------------------------- */

/**
 *  Point.
 *  A 2D point.
 *  @see Pw_Segment
 *  @see Pw_Rectangle
 */
struct _Pw_Point {
    Pw_Coord x; /**< Point's x coord. */
    Pw_Coord y; /**< Point's y coord. */
};

/**
 *  Line segment.
 *  A 2D line segment.
 *  @see Pw_Point
 *  @see Pw_Rectangle
 */
struct _Pw_Segment {
    Pw_Coord x1; /**< Segment start point x coord. */
    Pw_Coord y1; /**< Segment start point y coord. */
    Pw_Coord x2; /**< Segment end point x coord. */
    Pw_Coord y2; /**< Segment end point y coord. */
};

/**
 *  Rectangle.
 *  A 2D rectangle.
 *  @see Pw_Point
 *  @see Pw_Segment
 */
struct _Pw_Rectangle {
    Pw_Coord x; /**< Rectangle top left corner x coord. */
    Pw_Coord y; /**< Rectangle top left corner y coord. */
    Pw_Coord w; /**< Rectangle width. */
    Pw_Coord h; /**< Rectangle height. */
};

/**
 *  3D Matrix.
 */ 
struct _Pw_Mat3d {
    Pw_Float xx, xy, xz, xo;
    Pw_Float yx, yy, yz, yo;
    Pw_Float zx, zy, zz, zo;
};

/**
 *  Rectangular region.
 *  Rectangular region element used in forming a list of regions.
 *  @see Pw_Rectangle
 *  @see Pw_RegionList
 */
struct _Pw_Region {
    Pw_Rectangle area; /**< Rectangular area. */
    Pw_Region*   next; /**< Pointer to next region in list. */
};

/**
 *  Region List.
 *  Region list is a list of regions including regions count and bounds.
 *  @see Pw_Region
 */
struct _Pw_RegionList {
    Pw_Region*   regs;     /**< List of rectangular regions. */
    Pw_Int       regs_num; /**< Number of regions in list. */ 
    Pw_Rectangle bounds;   /**< Bounds of regions in list. */
};

/**
 *  Color.
 *  A color defined by its red, green and blue components.
 */
/*struct _Pw_Color
{    Pw_Byte red;  
    Pw_Byte green; 
    Pw_Byte blue;  
};*/	

/**
 *  Bitmap.
 *  A bitmap is a B/W picture, the pixels are represented by bits.
 *  NOTE: each line ends at byte border.
 */
struct _Pw_Bitmap{
    Pw_uInt  width;  /**< Bitmap width. */
    Pw_uInt  height; /**< Bitmap height. */
    Pw_uInt  width8; /**< Bitmap width in bytes. */
    Pw_Byte* bits;   /**< Array of bitmap bits. */
};

/**
 *  Font.
 *  A font carries information about its vertical position
 *  according to the 0 line, information about each charachter
 *  position according to the previous charachter and the 
 *  bitmaps of all charachters.
 *  @see Pw_FontCharInfo
 */
struct _Pw_Font	{
    Pw_uInt           ascent;    /**< Font charachter ascent. */
    Pw_uInt           descent;   /**< Font charachter descent. */
    Pw_uInt           chars_num; /**< Number of charachters in font. */
    Pw_FontCharInfo*  info;      /**< Array of charachters info. */
    Pw_Byte*          bits;      /**< Array of charachters bitmaps bits. */
};

/**
 *  Font charachter info.
 *  A Font charachter info describes the charachters bounds,
 *  the location of this charachter according to the location of
 *  previous charachter in the string and the charachter bitmap
 *  location in its font bits array.
 *  @see Pw_Font
 */
struct _Pw_FontCharInfo	{
    Pw_Int8   bbx, bby;    /**< Charachter x and y offset from origin. */
    Pw_Int8   bbw, bbh;    /**< Charachter width and height. */
    Pw_Int8   dwx;         /**< X offset of next charachter origin. */
    Pw_uInt32 bits_offset; /**< Offset of bitmap bits in font bits array. */
};

/**
 *  Drawable.
 *  A drawable describes a component that supports drawing.
 *  @see Pw_DrawableType
 *  @see Pw_LLD
 *  @see Pw_GC
 */
struct _Pw_Drawable	{
    Pw_DrawableType type;  /**< Type of this drawable. */
    union  {
        Pw_Window* window; /**< Window component. */
        Pw_Bitmap* bitmap; /**< Bitmap component. */
    } comp;                /**< Component to which this drawable reffers. */
    Pw_LLD* lld;           /**< Low level drawing funs of this drawable. */
};

/**
 *  Display driver functions.
 *  Display specific functions. 
 *  @see Pw_LLD
 */
struct _Pw_DD {
    /** Low level drawing funs used to draw on this display. */
    Pw_LLD* lld;

    /** Function that refreshes the display. */
    void (*display_refresh)(Pw_Display* dpy, Pw_Rectangle* area);

    /** Function that gets the current value of given xinput. */
    Pw_Int (*get_xinput_value)(Pw_Display* dpy, Pw_uInt num);

    /** Function that initializes display components. */
    Pw_Bool (*init_components)(Pw_Display* dpy);
};

/**
 *  Low level drawing functions.
 *  Low level functions that draw directly into specified drawable.
 *  @see Pw_Drawable
 *  @see Pw_GC
 *  @see Pw_DD
 */
struct _Pw_LLD
{
    /** Function that draws a point. */
    void (*draw_point)(Pw_GC*   gc, 
                       Pw_Coord x, 
                       Pw_Coord y);

    /** Function that draws up to 8 points (in row). */
    void (*draw_points)(Pw_GC*   gc, 
                        Pw_Coord x, 
                        Pw_Coord y, 
                        Pw_Byte  bits);

    /** Function that draws a horizontal line. */
    void (*draw_hor_line)(Pw_GC*   gc, 
                          Pw_Coord x1, 
                          Pw_Coord y1, 
                          Pw_Coord x2);

    /** Function that draws a vertical line. */
    void (*draw_ver_line)(Pw_GC*   gc, 
                          Pw_Coord x1, 
                          Pw_Coord y1, 
                          Pw_Coord y2);

    /** Function that fills a rectangular area. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -