1. /*
    2. This program is free software: you can redistribute it and/or modify
    3. it under the terms of the GNU General Public License as published by
    4. the Free Software Foundation, either version 3 of the License, or
    5. (at your option) any later version.
    6. This program is distributed in the hope that it will be useful,
    7. but WITHOUT ANY WARRANTY; without even the implied warranty of
    8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    9. GNU General Public License for more details.
    10. You should have received a copy of the GNU General Public License
    11. along with this program. If not, see <http://www.gnu.org/licenses/>.
    12. */
    13. ////////////////////////////////////////////////////////////////
    14. // ACLLib - Advanced C Lab Library
    15. // Ver 2014-07
    16. // For students' Lab at Zhejiang University
    17. // Created 2008 by Gao Yuan
    18. // Modified 2009 by Cui Liwei
    19. // 2010 by Lan Huidong
    20. // Revised 2012 by Li Rui
    21. // Modified 2014 by Weng Kai for MOOC
    22. ////////////////////////////////////////////////////////////////
    23. /*
    24. For Dev C++, these lib files need to be added into linker options.
    25. Be sure to change the leading folders as your installation.
    26. "C:/Program Files/Dev-Cpp/MinGW32/lib/libwinmm.a"
    27. "C:/Program Files/Dev-Cpp/MinGW32/lib/libmsimg32.a"
    28. "C:/Program Files/Dev-Cpp/MinGW32/lib/libkernel32.a"
    29. "C:/Program Files/Dev-Cpp/MinGW32/lib/libuser32.a"
    30. "C:/Program Files/Dev-Cpp/MinGW32/lib/libgdi32.a"
    31. "C:/Program Files/Dev-Cpp/MinGW32/lib/libole32.a"
    32. "C:/Program Files/Dev-Cpp/MinGW32/lib/liboleaut32.a"
    33. "C:/Program Files/Dev-Cpp/MinGW32/lib/libuuid.a"
    34. */
    35. #ifndef __ACLLIB_H__
    36. #define __ACLLIB_H__
    37. #ifdef _UNICODE
    38. #undef _UNICODE
    39. #endif
    40. #ifdef UNICODE
    41. #undef UNICODE
    42. #endif
    43. #include <Windows.h>
    44. #define BLACK RGB(0, 0, 0)
    45. #define RED RGB(255, 0, 0)
    46. #define GREEN RGB(0, 255, 0)
    47. #define BLUE RGB(0, 0, 255)
    48. #define CYAN RGB(0, 255, 255)
    49. #define MAGENTA RGB(255, 0, 255)
    50. #define YELLOW RGB(255, 255, 0)
    51. #define WHITE RGB(255, 255, 255)
    52. #define EMPTY 0xffffffff
    53. #define DEFAULT -1
    54. typedef enum
    55. {
    56. PEN_STYLE_SOLID,
    57. PEN_STYLE_DASH, /* ------- */
    58. PEN_STYLE_DOT, /* ....... */
    59. PEN_STYLE_DASHDOT, /* _._._._ */
    60. PEN_STYLE_DASHDOTDOT, /* _.._.._ */
    61. PEN_STYLE_NULL
    62. } ACL_Pen_Style;
    63. typedef enum
    64. {
    65. BRUSH_STYLE_SOLID = -1,
    66. BRUSH_STYLE_HORIZONTAL, /* ----- */
    67. BRUSH_STYLE_VERTICAL, /* ||||| */
    68. BRUSH_STYLE_FDIAGONAL, /* \\\\\ */
    69. BRUSH_STYLE_BDIAGONAL, /* ///// */
    70. BRUSH_STYLE_CROSS, /* +++++ */
    71. BRUSH_STYLE_DIAGCROSS, /* xxxxx */
    72. BRUSH_STYLE_NULL
    73. } ACL_Brush_Style;
    74. typedef enum
    75. {
    76. NO_BUTTON = 0,
    77. LEFT_BUTTON,
    78. MIDDLE_BUTTON,
    79. RIGHT_BUTTON
    80. } ACL_Mouse_Button;
    81. typedef enum
    82. {
    83. BUTTON_DOWN,
    84. BUTTON_DOUBLECLICK,
    85. BUTTON_UP,
    86. ROLL_UP,
    87. ROLL_DOWN,
    88. MOUSEMOVE
    89. } ACL_Mouse_Event;
    90. typedef enum
    91. {
    92. KEY_DOWN,
    93. KEY_UP
    94. } ACL_Keyboard_Event;
    95. typedef struct
    96. {
    97. HBITMAP hbitmap;
    98. int width;
    99. int height;
    100. } ACL_Image;
    101. //typedef enum
    102. //{
    103. // TM_NO = 0x00,
    104. // TM_COLOR = 0x01,
    105. // TM_ALPHA = 0x02
    106. //} ACL_TransparentMode;
    107. typedef COLORREF ACL_Color;
    108. typedef int ACL_Sound;
    109. typedef void(*KeyboardEventCallback) (int key, int event);
    110. typedef void(*CharEventCallback) (char c);
    111. typedef void(*MouseEventCallback) (int x, int y, int button, int event);
    112. typedef void(*TimerEventCallback) (int timerID);
    113. #ifdef __cplusplus
    114. extern "C" {
    115. #endif
    116. int Setup(void);
    117. //
    118. void initWindow(const char title[], int left, int top, int width, int height);
    119. void msgBox(const char title[], const char text[], int flag);
    120. void registerKeyboardEvent(KeyboardEventCallback callback);
    121. void registerCharEvent(CharEventCallback callback);
    122. void registerMouseEvent(MouseEventCallback callback);
    123. void registerTimerEvent(TimerEventCallback callback);
    124. void startTimer(int timerID, int timeinterval);
    125. void cancelTimer(int timerID);
    126. // Sound
    127. void loadSound(const char *fileName, ACL_Sound *pSound);
    128. void playSound(ACL_Sound soundID, int repeat);
    129. void stopSound(ACL_Sound soundID);
    130. // Paint
    131. void beginPaint();
    132. void endPaint();
    133. void clearDevice(void);
    134. int getWidth();
    135. int getHeight();
    136. // Pen
    137. void setPenColor(ACL_Color color);
    138. void setPenWidth(int width);
    139. void setPenStyle(ACL_Pen_Style style);
    140. // Brush
    141. void setBrushColor(ACL_Color color);
    142. void setBrushStyle(ACL_Brush_Style style);
    143. // Text
    144. void setTextColor(ACL_Color color);
    145. void setTextBkColor(ACL_Color color);
    146. void setTextSize(int size);
    147. void setTextFont(const char *pFontName);
    148. void paintText(int x, int y, const char *pStr);
    149. void setCaretSize(int w, int h);
    150. void setCaretPos(int x, int y);
    151. void showCaret();
    152. void hideCaret();
    153. // Pixel
    154. void putPixel(int x, int y, ACL_Color color);
    155. ACL_Color getPixel(int x, int y);
    156. // the Point
    157. int getX(void);
    158. int getY(void);
    159. void moveTo(int x, int y);
    160. void moveRel(int dx, int dy);
    161. // Lines and Curves
    162. void arc(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, \
    163. int nXStartArc, int nYStartArc, int nXEndArc, int nYEndArc);
    164. void line(int x0, int y0, int x1, int y1);
    165. void lineTo(int nXEnd, int nYEnd);
    166. void lineRel(int dx, int dy);
    167. void polyBezier(const POINT *lppt, int cPoints);
    168. void polyLine(const POINT *lppt, int cPoints);
    169. // Filled Shapes
    170. void chrod(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, \
    171. int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2);
    172. void ellipse(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
    173. void pie(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, \
    174. int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2);
    175. void polygon(const POINT *lpPoints, int nCount);
    176. void rectangle(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
    177. void roundrect(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, \
    178. int nWidth, int nHeight);
    179. // Image
    180. void loadImage(const char *pImageFileName, ACL_Image *pImage);
    181. void freeImage(ACL_Image *pImage);
    182. void putImage(ACL_Image *pImage, int x, int y);
    183. void putImageScale(ACL_Image *pImage, int x, int y, int width, int height);
    184. void putImageTransparent(ACL_Image *pImage, int x, int y, int width, int height, ACL_Color bkColor);
    185. //void putImageEx(ACL_Image *pImage,int dx,int dy,int dw,int dh,
    186. // int sx,int sy,int sw,int sh);
    187. //void setTransparentMode(ACL_TransparenetMode);
    188. //void setTransparentColor(ACL_Color);
    189. //void setTransparetnAlpha(int alpha);
    190. void initConsole(void);
    191. #ifdef __cplusplus
    192. }
    193. #endif
    194. #endif