瀏覽 EGE 源碼隨記
[編輯] [转简体] (简体译文)
|
作者:huidong
| 分類:【編程】EasyX
[
36 瀏覽
0 評論
11 贊
13 踩
]
概要
記錄一下 EGE 中一些也許有用的實現細節
正文
鏈接 GDI+ 需要考慮 x64 的情況(ege.h)
#if !defined(EGE_GRAPH_LIB_BUILD) && !defined(EGE_GRAPH_NO_LIB) # ifdef _MSC_VER # pragma comment(lib,"gdiplus.lib") # ifdef _WIN64 // 64 bit libs # pragma comment(lib,"graphics64.lib") # else // 32 bit libs # pragma comment(lib,"graphics.lib") # endif # endif #endif
RGB 宏設置了 alpha 值爲 255
#define EGERGBA(r, g, b, a) ((::ege::color_t)( ((r)<<16) | ((g)<<8) | (b) | ((a)<<24) )) #define EGERGB(r, g, b) EGERGBA(r, g, b, 0xFF) #define EGEARGB(a, r, g, b) EGERGBA(r, g, b, a) #define EGEACOLOR(a, color) ((::ege::color_t)( ((color) & 0xFFFFFF) | ((a)<<24) )) #define EGECOLORA(color, a) EGEACOLOR(a, color) #define EGEGET_R(c) ( ((c)>>16) & 0xFF ) #define EGEGET_G(c) ( ((c)>> 8) & 0xFF ) #define EGEGET_B(c) ( ((c)) & 0xFF ) #define EGEGET_A(c) ( ((c)>>24) & 0xFF ) #define EGEGRAY(gray) EGERGB(gray, gray, gray) #define EGEGRAYA(gray, a) EGERGBA(gray, gray, gray, a) #define EGEAGRAY(a, gray) EGEGRAYA(gray, a)
給出 PI
const double PI = 3.1415926535897932384626;
給出更多預設顏色
// 颜色 enum COLORS { ALICEBLUE = EGERGB(0xF0, 0xF8, 0xFF), ANTIQUEWHITE = EGERGB(0xFA, 0xEB, 0xD7), AQUA = EGERGB(0x00, 0xFF, 0xFF), AQUAMARINE = EGERGB(0x7F, 0xFF, 0xD4), AZURE = EGERGB(0xF0, 0xFF, 0xFF), BEIGE = EGERGB(0xF5, 0xF5, 0xDC), BISQUE = EGERGB(0xFF, 0xE4, 0xC4), BLACK = EGERGB(0x00, 0x00, 0x00), BLANCHEDALMOND = EGERGB(0xFF, 0xEB, 0xCD), BLUE = EGERGB(0x00, 0x00, 0xFF), BLUEVIOLET = EGERGB(0x8A, 0x2B, 0xE2), BROWN = EGERGB(0xA5, 0x2A, 0x2A), BURLYWOOD = EGERGB(0xDE, 0xB8, 0x87), CADETBLUE = EGERGB(0x5F, 0x9E, 0xA0), CHARTREUSE = EGERGB(0x7F, 0xFF, 0x00), CHOCOLATE = EGERGB(0xD2, 0x69, 0x1E), CORAL = EGERGB(0xFF, 0x7F, 0x50), CORNFLOWERBLUE = EGERGB(0x64, 0x95, 0xED), CORNSILK = EGERGB(0xFF, 0xF8, 0xDC), CRIMSON = EGERGB(0xDC, 0x14, 0x3C), CYAN = EGERGB(0x00, 0xFF, 0xFF), DARKBLUE = EGERGB(0x00, 0x00, 0x8B), DARKCYAN = EGERGB(0x00, 0x8B, 0x8B), DARKGOLDENROD = EGERGB(0xB8, 0x86, 0x0B), DARKGRAY = EGERGB(0xA9, 0xA9, 0xA9), DARKGREEN = EGERGB(0x00, 0x64, 0x00), DARKKHAKI = EGERGB(0xBD, 0xB7, 0x6B), DARKMAGENTA = EGERGB(0x8B, 0x00, 0x8B), DARKOLIVEGREEN = EGERGB(0x55, 0x6B, 0x2F), DARKORANGE = EGERGB(0xFF, 0x8C, 0x00), DARKORCHID = EGERGB(0x99, 0x32, 0xCC), DARKRED = EGERGB(0x8B, 0x00, 0x00), DARKSALMON = EGERGB(0xE9, 0x96, 0x7A), DARKSEAGREEN = EGERGB(0x8F, 0xBC, 0x8F), DARKSLATEBLUE = EGERGB(0x48, 0x3D, 0x8B), DARKSLATEGRAY = EGERGB(0x2F, 0x4F, 0x4F), DARKTURQUOISE = EGERGB(0x00, 0xCE, 0xD1), DARKVIOLET = EGERGB(0x94, 0x00, 0xD3), DEEPPINK = EGERGB(0xFF, 0x14, 0x93), DEEPSKYBLUE = EGERGB(0x00, 0xBF, 0xFF), DIMGRAY = EGERGB(0x69, 0x69, 0x69), DODGERBLUE = EGERGB(0x1E, 0x90, 0xFF), FIREBRICK = EGERGB(0xB2, 0x22, 0x22), FLORALWHITE = EGERGB(0xFF, 0xFA, 0xF0), FORESTGREEN = EGERGB(0x22, 0x8B, 0x22), FUCHSIA = EGERGB(0xFF, 0x00, 0xFF), GAINSBORO = EGERGB(0xDC, 0xDC, 0xDC), GHOSTWHITE = EGERGB(0xF8, 0xF8, 0xFF), GOLD = EGERGB(0xFF, 0xD7, 0x00), GOLDENROD = EGERGB(0xDA, 0xA5, 0x20), GRAY = EGERGB(0x80, 0x80, 0x80), GREEN = EGERGB(0x00, 0x80, 0x00), GREENYELLOW = EGERGB(0xAD, 0xFF, 0x2F), HONEYDEW = EGERGB(0xF0, 0xFF, 0xF0), HOTPINK = EGERGB(0xFF, 0x69, 0xB4), INDIANRED = EGERGB(0xCD, 0x5C, 0x5C), INDIGO = EGERGB(0x4B, 0x00, 0x82), IVORY = EGERGB(0xFF, 0xFF, 0xF0), KHAKI = EGERGB(0xF0, 0xE6, 0x8C), LAVENDER = EGERGB(0xE6, 0xE6, 0xFA), LAVENDERBLUSH = EGERGB(0xFF, 0xF0, 0xF5), LAWNGREEN = EGERGB(0x7C, 0xFC, 0x00), LEMONCHIFFON = EGERGB(0xFF, 0xFA, 0xCD), LIGHTBLUE = EGERGB(0xAD, 0xD8, 0xE6), LIGHTCORAL = EGERGB(0xF0, 0x80, 0x80), LIGHTCYAN = EGERGB(0xE0, 0xFF, 0xFF), LIGHTGOLDENRODYELLOW = EGERGB(0xFA, 0xFA, 0xD2), LIGHTGRAY = EGERGB(0xD3, 0xD3, 0xD3), LIGHTGREEN = EGERGB(0x90, 0xEE, 0x90), LIGHTPINK = EGERGB(0xFF, 0xB6, 0xC1), LIGHTSALMON = EGERGB(0xFF, 0xA0, 0x7A), LIGHTSEAGREEN = EGERGB(0x20, 0xB2, 0xAA), LIGHTSKYBLUE = EGERGB(0x87, 0xCE, 0xFA), LIGHTSLATEGRAY = EGERGB(0x77, 0x88, 0x99), LIGHTSTEELBLUE = EGERGB(0xB0, 0xC4, 0xDE), LIGHTYELLOW = EGERGB(0xFF, 0xFF, 0xE0), LIGHTRED = EGERGB(0xFC, 0x54, 0x54), LIGHTMAGENTA = EGERGB(0xFC, 0x54, 0xFC), LIME = EGERGB(0x00, 0xFF, 0x00), LIMEGREEN = EGERGB(0x32, 0xCD, 0x32), LINEN = EGERGB(0xFA, 0xF0, 0xE6), MAGENTA = EGERGB(0xFF, 0x00, 0xFF), MAROON = EGERGB(0x80, 0x00, 0x00), MEDIUMAQUAMARINE = EGERGB(0x66, 0xCD, 0xAA), MEDIUMBLUE = EGERGB(0x00, 0x00, 0xCD), MEDIUMORCHID = EGERGB(0xBA, 0x55, 0xD3), MEDIUMPURPLE = EGERGB(0x93, 0x70, 0xDB), MEDIUMSEAGREEN = EGERGB(0x3C, 0xB3, 0x71), MEDIUMSLATEBLUE = EGERGB(0x7B, 0x68, 0xEE), MEDIUMSPRINGGREEN = EGERGB(0x00, 0xFA, 0x9A), MEDIUMTURQUOISE = EGERGB(0x48, 0xD1, 0xCC), MEDIUMVIOLETRED = EGERGB(0xC7, 0x15, 0x85), MIDNIGHTBLUE = EGERGB(0x19, 0x19, 0x70), MINTCREAM = EGERGB(0xF5, 0xFF, 0xFA), MISTYROSE = EGERGB(0xFF, 0xE4, 0xE1), MOCCASIN = EGERGB(0xFF, 0xE4, 0xB5), NAVAJOWHITE = EGERGB(0xFF, 0xDE, 0xAD), NAVY = EGERGB(0x00, 0x00, 0x80), OLDLACE = EGERGB(0xFD, 0xF5, 0xE6), OLIVE = EGERGB(0x80, 0x80, 0x00), OLIVEDRAB = EGERGB(0x6B, 0x8E, 0x23), ORANGE = EGERGB(0xFF, 0xA5, 0x00), ORANGERED = EGERGB(0xFF, 0x45, 0x00), ORCHID = EGERGB(0xDA, 0x70, 0xD6), PALEGOLDENROD = EGERGB(0xEE, 0xE8, 0xAA), PALEGREEN = EGERGB(0x98, 0xFB, 0x98), PALETURQUOISE = EGERGB(0xAF, 0xEE, 0xEE), PALEVIOLETRED = EGERGB(0xDB, 0x70, 0x93), PAPAYAWHIP = EGERGB(0xFF, 0xEF, 0xD5), PEACHPUFF = EGERGB(0xFF, 0xDA, 0xB9), PERU = EGERGB(0xCD, 0x85, 0x3F), PINK = EGERGB(0xFF, 0xC0, 0xCB), PLUM = EGERGB(0xDD, 0xA0, 0xDD), POWDERBLUE = EGERGB(0xB0, 0xE0, 0xE6), PURPLE = EGERGB(0x80, 0x00, 0x80), RED = EGERGB(0xFF, 0x00, 0x00), ROSYBROWN = EGERGB(0xBC, 0x8F, 0x8F), ROYALBLUE = EGERGB(0x41, 0x69, 0xE1), SADDLEBROWN = EGERGB(0x8B, 0x45, 0x13), SALMON = EGERGB(0xFA, 0x80, 0x72), SANDYBROWN = EGERGB(0xF4, 0xA4, 0x60), SEAGREEN = EGERGB(0x2E, 0x8B, 0x57), SEASHELL = EGERGB(0xFF, 0xF5, 0xEE), SIENNA = EGERGB(0xA0, 0x52, 0x2D), SILVER = EGERGB(0xC0, 0xC0, 0xC0), SKYBLUE = EGERGB(0x87, 0xCE, 0xEB), SLATEBLUE = EGERGB(0x6A, 0x5A, 0xCD), SLATEGRAY = EGERGB(0x70, 0x80, 0x90), SNOW = EGERGB(0xFF, 0xFA, 0xFA), SPRINGGREEN = EGERGB(0x00, 0xFF, 0x7F), STEELBLUE = EGERGB(0x46, 0x82, 0xB4), TAN = EGERGB(0xD2, 0xB4, 0x8C), TEAL = EGERGB(0x00, 0x80, 0x80), THISTLE = EGERGB(0xD8, 0xBF, 0xD8), TOMATO = EGERGB(0xFF, 0x63, 0x47), TURQUOISE = EGERGB(0x40, 0xE0, 0xD0), VIOLET = EGERGB(0xEE, 0x82, 0xEE), WHEAT = EGERGB(0xF5, 0xDE, 0xB3), WHITE = EGERGB(0xFF, 0xFF, 0xFF), WHITESMOKE = EGERGB(0xF5, 0xF5, 0xF5), YELLOW = EGERGB(0xFF, 0xFF, 0x00), YELLOWGREEN = EGERGB(0x9A, 0xCD, 0x32), };
提供一些填充模式,不知道這些是不是都是 GDI/GDI+ 本身就支持的?沒有確認在 EasyX 中支持哪些。
// 填充模式 enum fill_patterns {/* Fill patterns for get/setfillstyle */ EMPTY_FILL, /* fills area in background color */ SOLID_FILL, /* fills area in solid fill color */ LINE_FILL, /* --- fill */ LTSLASH_FILL, /* /// fill */ SLASH_FILL, /* /// fill with thick lines */ BKSLASH_FILL, /*fill with thick lines */ LTBKSLASH_FILL, /*fill */ HATCH_FILL, /* light hatch fill */ XHATCH_FILL, /* heavy cross hatch fill */ INTERLEAVE_FILL,/* interleaving line fill */ WIDE_DOT_FILL, /* Widely spaced dot fill */ CLOSE_DOT_FILL, /* Closely spaced dot fill */ USER_FILL /* user defined fill */ };
可供參考的一些選項
enum text_just { /* Horizontal and vertical justification for settextjustify */ LEFT_TEXT = 0, CENTER_TEXT = 1, RIGHT_TEXT = 2, BOTTOM_TEXT = 0, /* CENTER_TEXT = 1, already defined above */ TOP_TEXT = 2 }; enum line_styles { /* Line styles for get/setlinestyle */ SOLID_LINE = PS_SOLID, CENTER_LINE = PS_DASH, DOTTED_LINE = PS_DOT, DASHED_LINE = PS_DASHDOT, NULL_LINE = PS_NULL, USERBIT_LINE = PS_USERSTYLE, /* User defined line style */ };