Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*!
  2.   \file SDL_draw.c
  3.   \author Mario Palomo Torrero <mpalomo@ihman.com>
  4.   \author Jose M. de la Huerga Fernández
  5.   \author Pepe González Mora
  6.   \date 05-2002
  7.  
  8.   Drawing primitives for SDL. Main implementation file.
  9.  
  10.   This library is free software; you can redistribute it and/or
  11.   modify it under the terms of the GNU Library General Public
  12.   License as published by the Free Software Foundation; either
  13.   version 2 of the License, or (at your option) any later version.
  14.  
  15.   This library is distributed in the hope that it will be useful,
  16.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.   Library General Public License for more details.
  19.  
  20.   You should have received a copy of the GNU Library General Public
  21.   License along with this library; if not, write to the Free Foundation,
  22.   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include "SDL_draw.h"
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <wchar.h>  /*wmemset*/
  29.  
  30.  
  31. /*==================== BEGIN of Draw_Pixel ======================*/
  32.  
  33. #define SDL_DRAW_BPP 1
  34. #define SDL_DRAWFUNCTION  Draw_Pixel_1
  35. #include "Draw_Pixel.c"
  36. #undef SDL_DRAWFUNCTION
  37. #undef SDL_DRAW_BPP
  38.  
  39. #define SDL_DRAW_BPP 2
  40. #define SDL_DRAWFUNCTION  Draw_Pixel_2
  41. #include "Draw_Pixel.c"
  42. #undef SDL_DRAWFUNCTION
  43. #undef SDL_DRAW_BPP
  44.  
  45. #define SDL_DRAW_BPP 3
  46. #define SDL_DRAWFUNCTION  Draw_Pixel_3
  47. #include "Draw_Pixel.c"
  48. #undef SDL_DRAWFUNCTION
  49. #undef SDL_DRAW_BPP
  50.  
  51. #define SDL_DRAW_BPP 4
  52. #define SDL_DRAWFUNCTION  Draw_Pixel_4
  53. #include "Draw_Pixel.c"
  54. #undef SDL_DRAWFUNCTION
  55. #undef SDL_DRAW_BPP
  56.  
  57. static
  58. void Draw_Pixel_error(SDL_Surface *super,
  59.                       Sint16 x, Sint16 y, Uint32 color)
  60. {
  61.   SDL_printf("SDL_draw: Draw_Pixel ERROR!!."
  62.                   " Have you call to SDL_Draw_Init()?\n");
  63.   exit(-1);
  64. }
  65.  
  66. void (*Draw_Pixel)(SDL_Surface *super,
  67.                    Sint16 x, Sint16 y, Uint32 color) = Draw_Pixel_error;
  68.  
  69. /*===================== END of Draw_Pixel =======================*/
  70.  
  71. /*==================== BEGIN of Draw_Line ======================*/
  72.  
  73. #define SDL_DRAW_BPP 1
  74. #define SDL_DRAWFUNCTION  Draw_Line_1
  75. #include "Draw_Line.c"
  76. #undef SDL_DRAWFUNCTION
  77. #undef SDL_DRAW_BPP
  78.  
  79. #define SDL_DRAW_BPP 2
  80. #define SDL_DRAWFUNCTION  Draw_Line_2
  81. #include "Draw_Line.c"
  82. #undef SDL_DRAWFUNCTION
  83. #undef SDL_DRAW_BPP
  84.  
  85. #define SDL_DRAW_BPP 3
  86. #define SDL_DRAWFUNCTION  Draw_Line_3
  87. #include "Draw_Line.c"
  88. #undef SDL_DRAWFUNCTION
  89. #undef SDL_DRAW_BPP
  90.  
  91. #define SDL_DRAW_BPP 4
  92. #define SDL_DRAWFUNCTION  Draw_Line_4
  93. #include "Draw_Line.c"
  94. #undef SDL_DRAWFUNCTION
  95. #undef SDL_DRAW_BPP
  96.  
  97. static
  98. void Draw_Line_error(SDL_Surface *super,
  99.                      Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
  100.                      Uint32 color)
  101. {
  102.   SDL_printf("SDL_draw: Draw_Line ERROR!!."
  103.                   " Have you call to SDL_Draw_Init()?\n");
  104.   exit(-1);
  105. }
  106.  
  107. void (*Draw_Line)(SDL_Surface *super,
  108.                   Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
  109.                   Uint32 color) = Draw_Line_error;
  110.  
  111. /*===================== END of Draw_Line =======================*/
  112.  
  113. /*=================== BEGIN of Draw_Circle =====================*/
  114.  
  115. #define SDL_DRAW_BPP 1
  116. #define SDL_DRAWFUNCTION  Draw_Circle_1
  117. #include "Draw_Circle.c"
  118. #undef SDL_DRAWFUNCTION
  119. #undef SDL_DRAW_BPP
  120.  
  121. #define SDL_DRAW_BPP 2
  122. #define SDL_DRAWFUNCTION  Draw_Circle_2
  123. #include "Draw_Circle.c"
  124. #undef SDL_DRAWFUNCTION
  125. #undef SDL_DRAW_BPP
  126.  
  127. #define SDL_DRAW_BPP 3
  128. #define SDL_DRAWFUNCTION  Draw_Circle_3
  129. #include "Draw_Circle.c"
  130. #undef SDL_DRAWFUNCTION
  131. #undef SDL_DRAW_BPP
  132.  
  133. #define SDL_DRAW_BPP 4
  134. #define SDL_DRAWFUNCTION  Draw_Circle_4
  135. #include "Draw_Circle.c"
  136. #undef SDL_DRAWFUNCTION
  137. #undef SDL_DRAW_BPP
  138.  
  139. static
  140. void Draw_Circle_error(SDL_Surface *super,
  141.                        Sint16 x0, Sint16 y0, Uint16 r,
  142.                        Uint32 color)
  143. {
  144.   SDL_printf("SDL_draw: Draw_Circle ERROR!!."
  145.                   " Have you call to SDL_Draw_Init()?\n");
  146.   exit(-1);
  147. }
  148.  
  149.  
  150. void (*Draw_Circle)(SDL_Surface *super,
  151.                     Sint16 x0, Sint16 y0, Uint16 r,
  152.                     Uint32 color) = Draw_Circle_error;
  153.  
  154. /*==================== END of Draw_Circle ======================*/
  155.  
  156. /*================= BEGIN of Draw_FillCircle ===================*/
  157.  
  158. #define SDL_DRAW_BPP 1
  159. #define SDL_DRAWFUNCTION  Draw_FillCircle_1
  160. #include "Draw_FillCircle.c"
  161. #undef SDL_DRAWFUNCTION
  162. #undef SDL_DRAW_BPP
  163.  
  164. #define SDL_DRAW_BPP 2
  165. #define SDL_DRAWFUNCTION  Draw_FillCircle_2
  166. #include "Draw_FillCircle.c"
  167. #undef SDL_DRAWFUNCTION
  168. #undef SDL_DRAW_BPP
  169.  
  170. #define SDL_DRAW_BPP 3
  171. #define SDL_DRAWFUNCTION  Draw_FillCircle_3
  172. #include "Draw_FillCircle.c"
  173. #undef SDL_DRAWFUNCTION
  174. #undef SDL_DRAW_BPP
  175.  
  176. #define SDL_DRAW_BPP 4
  177. #define SDL_DRAWFUNCTION  Draw_FillCircle_4
  178. #include "Draw_FillCircle.c"
  179. #undef SDL_DRAWFUNCTION
  180. #undef SDL_DRAW_BPP
  181.  
  182. static
  183. void Draw_FillCircle_error(SDL_Surface *super,
  184.                            Sint16 x0, Sint16 y0, Uint16 r,
  185.                            Uint32 color)
  186. {
  187.   SDL_printf("SDL_draw: Draw_FillCircle ERROR!!."
  188.                   " Have you call to SDL_Draw_Init()?\n");
  189.   exit(-1);
  190. }
  191.  
  192.  
  193. void (*Draw_FillCircle)(SDL_Surface *super,
  194.                         Sint16 x0, Sint16 y0, Uint16 r,
  195.                         Uint32 color) = Draw_FillCircle_error;
  196.  
  197. /*================== END of Draw_FillCircle ====================*/
  198.  
  199. /*=================== BEGIN of Draw_HLine =====================*/
  200.  
  201. #define SDL_DRAW_BPP 1
  202. #define SDL_DRAWFUNCTION  Draw_HLine_1
  203. #include "Draw_HLine.c"
  204. #undef SDL_DRAWFUNCTION
  205. #undef SDL_DRAW_BPP
  206.  
  207. #define SDL_DRAW_BPP 2
  208. #define SDL_DRAWFUNCTION  Draw_HLine_2
  209. #include "Draw_HLine.c"
  210. #undef SDL_DRAWFUNCTION
  211. #undef SDL_DRAW_BPP
  212.  
  213. #define SDL_DRAW_BPP 3
  214. #define SDL_DRAWFUNCTION  Draw_HLine_3
  215. #include "Draw_HLine.c"
  216. #undef SDL_DRAWFUNCTION
  217. #undef SDL_DRAW_BPP
  218.  
  219. #define SDL_DRAW_BPP 4
  220. #define SDL_DRAWFUNCTION  Draw_HLine_4
  221. #include "Draw_HLine.c"
  222. #undef SDL_DRAWFUNCTION
  223. #undef SDL_DRAW_BPP
  224.  
  225. static
  226. void Draw_HLine_error(SDL_Surface *super,
  227.                       Sint16 x0,Sint16 y0, Sint16 x1,
  228.                       Uint32 color)
  229. {
  230.   SDL_printf("SDL_draw: Draw_HLine ERROR!!."
  231.                   " Have you call to SDL_Draw_Init()?\n");
  232.   exit(-1);
  233. }
  234.  
  235. void (*Draw_HLine)(SDL_Surface *super,
  236.                    Sint16 x0,Sint16 y0, Sint16 x1,
  237.                    Uint32 color) = Draw_HLine_error;
  238.  
  239. /*==================== END of Draw_HLine ======================*/
  240.  
  241. /*=================== BEGIN of Draw_VLine =====================*/
  242. #define SDL_DRAW_BPP 1
  243. #define SDL_DRAWFUNCTION  Draw_VLine_1
  244. #include "Draw_VLine.c"
  245. #undef SDL_DRAWFUNCTION
  246. #undef SDL_DRAW_BPP
  247.  
  248. #define SDL_DRAW_BPP 2
  249. #define SDL_DRAWFUNCTION  Draw_VLine_2
  250. #include "Draw_VLine.c"
  251. #undef SDL_DRAWFUNCTION
  252. #undef SDL_DRAW_BPP
  253.  
  254. #define SDL_DRAW_BPP 3
  255. #define SDL_DRAWFUNCTION  Draw_VLine_3
  256. #include "Draw_VLine.c"
  257. #undef SDL_DRAWFUNCTION
  258. #undef SDL_DRAW_BPP
  259.  
  260. #define SDL_DRAW_BPP 4
  261. #define SDL_DRAWFUNCTION  Draw_VLine_4
  262. #include "Draw_VLine.c"
  263. #undef SDL_DRAWFUNCTION
  264. #undef SDL_DRAW_BPP
  265.  
  266. static
  267. void Draw_VLine_error(SDL_Surface *super,
  268.                       Sint16 x0,Sint16 y0, Sint16 y1,
  269.                       Uint32 color)
  270. {
  271.   SDL_printf("SDL_draw: Draw_VLine ERROR!!."
  272.                   " Have you call to SDL_Draw_Init()?\n");
  273.   exit(-1);
  274. }
  275.  
  276.  
  277. void (*Draw_VLine)(SDL_Surface *super,
  278.                    Sint16 x0,Sint16 y0, Sint16 y1,
  279.                    Uint32 color) = Draw_VLine_error;
  280.  
  281. /*==================== END of Draw_VLine ======================*/
  282.  
  283. /*==================== BEGIN of Draw_Rect ======================*/
  284.  
  285. #define SDL_DRAW_BPP 1
  286. #define SDL_DRAWFUNCTION  Draw_Rect_1
  287. #include "Draw_Rect.c"
  288. #undef SDL_DRAWFUNCTION
  289. #undef SDL_DRAW_BPP
  290.  
  291. #define SDL_DRAW_BPP 2
  292. #define SDL_DRAWFUNCTION  Draw_Rect_2
  293. #include "Draw_Rect.c"
  294. #undef SDL_DRAWFUNCTION
  295. #undef SDL_DRAW_BPP
  296.  
  297. #define SDL_DRAW_BPP 3
  298. #define SDL_DRAWFUNCTION  Draw_Rect_3
  299. #include "Draw_Rect.c"
  300. #undef SDL_DRAWFUNCTION
  301. #undef SDL_DRAW_BPP
  302.  
  303. #define SDL_DRAW_BPP 4
  304. #define SDL_DRAWFUNCTION  Draw_Rect_4
  305. #include "Draw_Rect.c"
  306. #undef SDL_DRAWFUNCTION
  307. #undef SDL_DRAW_BPP
  308.  
  309. static
  310. void Draw_Rect_error(SDL_Surface *super,
  311.                   Sint16 x,Sint16 y, Uint16 w,Uint16 h,
  312.                   Uint32 color)
  313. {
  314.   SDL_printf("SDL_draw: Draw_Rect ERROR!!."
  315.                   " Have you call to SDL_Draw_Init()?\n");
  316.   exit(-1);
  317. }
  318.  
  319. void (*Draw_Rect)(SDL_Surface *super,
  320.                   Sint16 x,Sint16 y, Uint16 w,Uint16 h,
  321.                   Uint32 color) = Draw_Rect_error;
  322.  
  323. /*===================== END of Draw_Rect =======================*/
  324.  
  325. /*=================== BEGIN of Draw_Ellipse ====================*/
  326.  
  327. #define SDL_DRAW_BPP 1
  328. #define SDL_DRAWFUNCTION  Draw_Ellipse_1
  329. #include "Draw_Ellipse.c"
  330. #undef SDL_DRAWFUNCTION
  331. #undef SDL_DRAW_BPP
  332.  
  333. #define SDL_DRAW_BPP 2
  334. #define SDL_DRAWFUNCTION  Draw_Ellipse_2
  335. #include "Draw_Ellipse.c"
  336. #undef SDL_DRAWFUNCTION
  337. #undef SDL_DRAW_BPP
  338.  
  339. #define SDL_DRAW_BPP 3
  340. #define SDL_DRAWFUNCTION  Draw_Ellipse_3
  341. #include "Draw_Ellipse.c"
  342. #undef SDL_DRAWFUNCTION
  343. #undef SDL_DRAW_BPP
  344.  
  345. #define SDL_DRAW_BPP 4
  346. #define SDL_DRAWFUNCTION  Draw_Ellipse_4
  347. #include "Draw_Ellipse.c"
  348. #undef SDL_DRAWFUNCTION
  349. #undef SDL_DRAW_BPP
  350.  
  351. static
  352. void Draw_Ellipse_error(SDL_Surface *super,
  353.                         Sint16 x0, Sint16 y0,
  354.                         Uint16 Xradius, Uint16 Yradius,
  355.                         Uint32 color)
  356. {
  357.   SDL_printf("SDL_draw: Draw_Ellipse ERROR!!."
  358.                   " Have you call to SDL_Draw_Init()?\n");
  359.   exit(-1);
  360. }
  361.  
  362.  
  363. void (*Draw_Ellipse)(SDL_Surface *super,
  364.                      Sint16 x0, Sint16 y0,
  365.                      Uint16 Xradius, Uint16 Yradius,
  366.                      Uint32 color) = Draw_Ellipse_error;
  367.  
  368. /*==================== END of Draw_Ellipse =====================*/
  369.  
  370. /*================= BEGIN of Draw_FillEllipse ==================*/
  371.  
  372. #define SDL_DRAW_BPP 1
  373. #define SDL_DRAWFUNCTION  Draw_FillEllipse_1
  374. #include "Draw_FillEllipse.c"
  375. #undef SDL_DRAWFUNCTION
  376. #undef SDL_DRAW_BPP
  377.  
  378. #define SDL_DRAW_BPP 2
  379. #define SDL_DRAWFUNCTION  Draw_FillEllipse_2
  380. #include "Draw_FillEllipse.c"
  381. #undef SDL_DRAWFUNCTION
  382. #undef SDL_DRAW_BPP
  383.  
  384. #define SDL_DRAW_BPP 3
  385. #define SDL_DRAWFUNCTION  Draw_FillEllipse_3
  386. #include "Draw_FillEllipse.c"
  387. #undef SDL_DRAWFUNCTION
  388. #undef SDL_DRAW_BPP
  389.  
  390. #define SDL_DRAW_BPP 4
  391. #define SDL_DRAWFUNCTION  Draw_FillEllipse_4
  392. #include "Draw_FillEllipse.c"
  393. #undef SDL_DRAWFUNCTION
  394. #undef SDL_DRAW_BPP
  395.  
  396. static
  397. void Draw_FillEllipse_error(SDL_Surface *super,
  398.                             Sint16 x0, Sint16 y0,
  399.                             Uint16 Xradius, Uint16 Yradius,
  400.                             Uint32 color)
  401. {
  402.   SDL_printf("SDL_draw: Draw_FillEllipse ERROR!!."
  403.                   " Have you call to SDL_Draw_Init()?\n");
  404.   exit(-1);
  405. }
  406.  
  407.  
  408. void (*Draw_FillEllipse)(SDL_Surface *super,
  409.                          Sint16 x0, Sint16 y0,
  410.                          Uint16 Xradius, Uint16 Yradius,
  411.                          Uint32 color) = Draw_FillEllipse_error;
  412.  
  413. /*================== END of Draw_FillEllipse ===================*/
  414.  
  415. /*==================== BEGIN of Draw_Round =====================*/
  416.  
  417. #define SDL_DRAW_BPP 1
  418. #define SDL_DRAWFUNCTION  Draw_Round_1
  419. #include "Draw_Round.c"
  420. #undef SDL_DRAWFUNCTION
  421. #undef SDL_DRAW_BPP
  422.  
  423. #define SDL_DRAW_BPP 2
  424. #define SDL_DRAWFUNCTION  Draw_Round_2
  425. #include "Draw_Round.c"
  426. #undef SDL_DRAWFUNCTION
  427. #undef SDL_DRAW_BPP
  428.  
  429. #define SDL_DRAW_BPP 3
  430. #define SDL_DRAWFUNCTION  Draw_Round_3
  431. #include "Draw_Round.c"
  432. #undef SDL_DRAWFUNCTION
  433. #undef SDL_DRAW_BPP
  434.  
  435. #define SDL_DRAW_BPP 4
  436. #define SDL_DRAWFUNCTION  Draw_Round_4
  437. #include "Draw_Round.c"
  438. #undef SDL_DRAWFUNCTION
  439. #undef SDL_DRAW_BPP
  440.  
  441. static
  442. void Draw_Round_error(SDL_Surface *super,
  443.                       Sint16 x0,Sint16 y0, Uint16 w,Uint16 h,
  444.                       Uint16 corner, Uint32 color)
  445. {
  446.   SDL_printf("SDL_draw: Draw_Round ERROR!!."
  447.                   " Have you call to SDL_Draw_Init()?\n");
  448.   exit(-1);
  449. }
  450.  
  451. void (*Draw_Round)(SDL_Surface *super,
  452.                    Sint16 x0,Sint16 y0, Uint16 w,Uint16 h,
  453.                    Uint16 corner, Uint32 color) = Draw_Round_error;
  454.  
  455. /*===================== END of Draw_Round ======================*/
  456.  
  457. /*================== BEGIN of Draw_FillRound ===================*/
  458.  
  459. #define SDL_DRAW_BPP 1
  460. #define SDL_DRAWFUNCTION  Draw_FillRound_1
  461. #include "Draw_FillRound.c"
  462. #undef SDL_DRAWFUNCTION
  463. #undef SDL_DRAW_BPP
  464.  
  465. #define SDL_DRAW_BPP 2
  466. #define SDL_DRAWFUNCTION  Draw_FillRound_2
  467. #include "Draw_FillRound.c"
  468. #undef SDL_DRAWFUNCTION
  469. #undef SDL_DRAW_BPP
  470.  
  471. #define SDL_DRAW_BPP 3
  472. #define SDL_DRAWFUNCTION  Draw_FillRound_3
  473. #include "Draw_FillRound.c"
  474. #undef SDL_DRAWFUNCTION
  475. #undef SDL_DRAW_BPP
  476.  
  477. #define SDL_DRAW_BPP 4
  478. #define SDL_DRAWFUNCTION  Draw_FillRound_4
  479. #include "Draw_FillRound.c"
  480. #undef SDL_DRAWFUNCTION
  481. #undef SDL_DRAW_BPP
  482.  
  483. static
  484. void Draw_FillRound_error(SDL_Surface *super,
  485.                           Sint16 x0,Sint16 y0, Uint16 w,Uint16 h,
  486.                           Uint16 corner, Uint32 color)
  487. {
  488.   SDL_printf("SDL_draw: Draw_FillRound ERROR!!."
  489.                   " Have you call to SDL_Draw_Init()?\n");
  490.   exit(-1);
  491. }
  492.  
  493. void (*Draw_FillRound)(SDL_Surface *super,
  494.                        Sint16 x0,Sint16 y0, Uint16 w,Uint16 h,
  495.                        Uint16 corner, Uint32 color) = Draw_FillRound_error;
  496.  
  497. /*=================== END of Draw_FillRound ====================*/
  498.  
  499.  
  500. /*Assignment of function pointers:*/
  501. #define SDL_DRAW_FUNCTIONS_BPP(x) \
  502.       Draw_Pixel       = Draw_Pixel_##x;       \
  503.       Draw_Line        = Draw_Line_##x;        \
  504.       Draw_Circle      = Draw_Circle_##x;      \
  505.       Draw_FillCircle  = Draw_FillCircle_##x;  \
  506.       Draw_HLine       = Draw_HLine_##x;       \
  507.       Draw_VLine       = Draw_VLine_##x;       \
  508.       Draw_Rect        = Draw_Rect_##x;        \
  509.       Draw_Ellipse     = Draw_Ellipse_##x;     \
  510.       Draw_FillEllipse = Draw_FillEllipse_##x; \
  511.       Draw_Round       = Draw_Round_##x;       \
  512.       Draw_FillRound   = Draw_FillRound_##x
  513.  
  514. /*IMPORTANT: Call this function AFTER the call to 'SDL_SetVideoMode'*/
  515. void Draw_Init(void)
  516. {
  517.   SDL_Surface *screen = SDL_GetVideoSurface();
  518.   if (!screen) {
  519.     SDL_printf("SDL_draw: SDL_Draw_Init ERROR!!."
  520.                   " Video Surface not found\n");
  521.     exit(-2);
  522.   }
  523.  
  524.  
  525.   switch(screen->format->BytesPerPixel) {
  526.     case 1:
  527.       SDL_DRAW_FUNCTIONS_BPP(1);
  528.     break;
  529.  
  530.     case 2:
  531.       SDL_DRAW_FUNCTIONS_BPP(2);
  532.     break;
  533.  
  534.     case 3:
  535.       SDL_DRAW_FUNCTIONS_BPP(3);
  536.     break;
  537.  
  538.     case 4:
  539.       SDL_DRAW_FUNCTIONS_BPP(4);
  540.     break;
  541.   }/*switch*/
  542.  
  543. }/*Draw_Init*/
  544.  
  545. #undef SDL_DRAW_FUNCTIONS_BPP
  546.  
  547.