/lib/pods/SDL/GFX/Primitives.pod

http://github.com/PerlGameDev/SDL · Unknown · 222 lines · 128 code · 94 blank · 0 comment · 0 complexity · 944048531983b635169d9a73ff1239c6 MD5 · raw file

  1. =head1 NAME
  2. SDL::GFX::Primitives - basic drawing functions
  3. =head1 CATEGORY
  4. GFX
  5. =head1 DESCRIPTION
  6. All functions take an SDL::Surface object as first parameter. This can be a new surface that will be blitted afterwards, can be an surface
  7. obtained by L<SDL::Video::set_video_mode|SDL::Video/"set_video_mode"> or can be an L<SDLx::App>.
  8. The C<color> values for the C<_color> functions are C<0xRRGGBBAA> (32bit), even if the surface uses e. g. 8bit colors.
  9. =head1 METHODS
  10. =head2 pixel
  11. int SDL::GFX::Primitives::pixel_color( $surface, $x, $y, $color );
  12. int SDL::GFX::Primitives::pixel_RGBA( $surface, $x, $y, $r, $g, $b, $a );
  13. Draws a pixel at point C<x>/C<$y>. You can pass the color by C<0xRRGGBBAA> or by passing 4 values. One for red, green, blue and alpha.
  14. use SDL;
  15. use SDL::Video;
  16. use SDL::Surface;
  17. use SDL::GFX::Primitives;
  18. my $surface = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);
  19. SDL::GFX::Primitives::pixel_color($surface, 2, 2, 0xFF0000FF); # red pixel
  20. SDL::GFX::Primitives::pixel_RGBA( $surface, 4, 4, 0x00, 0xFF, 0x00, 0xFF); # green pixel
  21. =head2 hline
  22. int SDL::GFX::Primitives::hline_color( $surface, $x1, $x2, $y, $color );
  23. int SDL::GFX::Primitives::hline_RGBA( $surface, $x1, $x2, $y, $r, $g, $b, $a );
  24. Draws a line horizontally from C<$x1>/C<$y> to C<$x2>/C<$y>.
  25. =head2 vline
  26. int SDL::GFX::Primitives::vline_color( $surface, $x, $y1, $y2, $color );
  27. int SDL::GFX::Primitives::vline_RGBA( $surface, $x, $y1, $y2, $r, $g, $b, $a );
  28. Draws a line vertically from C<$x>/C<$y1> to C<$x>/C<$y2>.
  29. =head2 rectangle
  30. int SDL::GFX::Primitives::rectangle_color( $surface, $x1, $y1, $x2, $y2, $color );
  31. int SDL::GFX::Primitives::rectangle_RGBA( $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );
  32. Draws a rectangle. Upper left edge will be at C<$x1>/C<$y1> and lower right at C<$x2>/C<$y>. The colored border has a width of 1 pixel.
  33. =head2 box
  34. int SDL::GFX::Primitives::box_color( $surface, $x1, $y1, $x2, $y2, $color );
  35. int SDL::GFX::Primitives::box_RGBA( $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );
  36. Draws a filled rectangle.
  37. =head2 line
  38. int SDL::GFX::Primitives::line_color( $surface, $x1, $y1, $x2, $y2, $color );
  39. int SDL::GFX::Primitives::line_RGBA( $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );
  40. Draws a free line from C<$x1>/C<$y1> to C<$x2>/C<$y>.
  41. =head2 aaline
  42. int SDL::GFX::Primitives::aaline_color( $surface, $x1, $y1, $x2, $y2, $color );
  43. int SDL::GFX::Primitives::aaline_RGBA( $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );
  44. Draws a free line from C<$x1>/C<$y1> to C<$x2>/C<$y>. This line is anti aliased.
  45. =head2 circle
  46. int SDL::GFX::Primitives::circle_color( $surface, $x, $y, $r, $color );
  47. int SDL::GFX::Primitives::circle_RGBA( $surface, $x, $y, $rad, $r, $g, $b, $a );
  48. =head2 arc
  49. int SDL::GFX::Primitives::arc_color( $surface, $x, $y, $r, $start, $end, $color );
  50. int SDL::GFX::Primitives::arc_RGBA( $surface, $x, $y, $rad, $start, $end, $r, $g, $b, $a );
  51. B<Note>: You need lib SDL_gfx 2.0.17 or greater for this function.
  52. =head2 aacircle
  53. int SDL::GFX::Primitives::aacircle_color( $surface, $x, $y, $r, $color );
  54. int SDL::GFX::Primitives::aacircle_RGBA( $surface, $x, $y, $rad, $r, $g, $b, $a );
  55. B<Note>: You need lib SDL_gfx 2.0.17 or greater for this function.
  56. =head2 filled_circle
  57. int SDL::GFX::Primitives::filled_circle_color( $surface, $x, $y, $r, $color );
  58. int SDL::GFX::Primitives::filled_circle_RGBA( $surface, $x, $y, $rad, $r, $g, $b, $a );
  59. =head2 ellipse
  60. int SDL::GFX::Primitives::ellipse_color( $surface, $x, $y, $rx, $ry, $color );
  61. int SDL::GFX::Primitives::ellipse_RGBA( $surface, $x, $y, $rx, $ry, $r, $g, $b, $a );
  62. =head2 aaellipse
  63. int SDL::GFX::Primitives::aaellipse_color( $surface, $xc, $yc, $rx, $ry, $color );
  64. int SDL::GFX::Primitives::aaellipse_RGBA( $surface, $x, $y, $rx, $ry, $r, $g, $b, $a );
  65. =head2 filled_ellipse
  66. int SDL::GFX::Primitives::filled_ellipse_color( $surface, $x, $y, $rx, $ry, $color );
  67. int SDL::GFX::Primitives::filled_ellipse_RGBA( $surface, $x, $y, $rx, $ry, $r, $g, $b, $a );
  68. =head2 pie
  69. int SDL::GFX::Primitives::pie_color( $surface, $x, $y, $rad, $start, $end, $color );
  70. int SDL::GFX::Primitives::pie_RGBA( $surface, $x, $y, $rad, $start, $end, $r, $g, $b, $a );
  71. This draws an opened pie. C<$start> and C<$end> are degree values. C<0> is at right, C<90> at bottom, C<180> at left and C<270> degrees at top.
  72. =head2 filled_pie
  73. int SDL::GFX::Primitives::filled_pie_color( $surface, $x, $y, $rad, $start, $end, $color );
  74. int SDL::GFX::Primitives::filled_pie_RGBA( $surface, $x, $y, $rad, $start, $end, $r, $g, $b, $a );
  75. =head2 trigon
  76. int SDL::GFX::Primitives::trigon_color( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $color );
  77. int SDL::GFX::Primitives::trigon_RGBA( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $r, $g, $b, $a );
  78. =head2 aatrigon
  79. int SDL::GFX::Primitives::aatrigon_color( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $color );
  80. int SDL::GFX::Primitives::aatrigon_RGBA( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $r, $g, $b, $a );
  81. =head2 filled_trigon
  82. int SDL::GFX::Primitives::filled_trigon_color( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $color );
  83. int SDL::GFX::Primitives::filled_trigon_RGBA( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $r, $g, $b, $a );
  84. =head2 polygon
  85. int SDL::GFX::Primitives::polygon_color( $surface, $vx, $vy, $n, $color );
  86. int SDL::GFX::Primitives::polygon_RGBA( $surface, $vx, $vy, $n, $r, $g, $b, $a );
  87. Example:
  88. SDL::GFX::Primitives::polygon_color($display, [262, 266, 264, 266, 262], [243, 243, 245, 247, 247], 5, 0xFF0000FF);
  89. =head2 aapolygon
  90. int SDL::GFX::Primitives::aapolygon_color( $surface, $vx, $vy, $n, $color );
  91. int SDL::GFX::Primitives::aapolygon_RGBA( $surface, $vx, $vy, $n, $r, $g, $b, $a );
  92. =head2 filled_polygon
  93. int SDL::GFX::Primitives::filled_polygon_color( $surface, $vx, $vy, $n, $color );
  94. int SDL::GFX::Primitives::filled_polygon_RGBA( $surface, $vx, $vy, $n, $r, $g, $b, $a );
  95. =head2 textured_polygon
  96. int SDL::GFX::Primitives::textured_polygon( $surface, $vx, $vy, $n, $texture, $texture_dx, $texture_dy );
  97. =head2 filled_polygon_MT
  98. int SDL::GFX::Primitives::filled_polygon_color_MT( $surface, $vx, $vy, $n, $color, $polyInts, $polyAllocated );
  99. int SDL::GFX::Primitives::filled_polygon_RGBA_MT( $surface, $vx, $vy, $n, $r, $g, $b, $a, $polyInts, $polyAllocated );
  100. B<Note>: You need lib SDL_gfx 2.0.17 or greater for this function.
  101. =head2 textured_polygon_MT
  102. int SDL::GFX::Primitives::textured_polygon_MT( $surface, $vx, $vy, $n, $texture, $texture_dx, $texture_dy, $polyInts, $polyAllocated );
  103. B<Note>: You need lib SDL_gfx 2.0.17 or greater for this function.
  104. =head2 bezier
  105. int SDL::GFX::Primitives::bezier_color( $surface, $vx, $vy, $n, $s, $color );
  106. int SDL::GFX::Primitives::bezier_RGBA( $surface, $vx, $vy, $n, $s, $r, $g, $b, $a );
  107. C<$n> is the number of elements in C<$vx> and C<$vy>, and C<$s> is the number of steps. So the bigger C<$s> is, the smother it becomes.
  108. Example:
  109. SDL::GFX::Primitives::bezier_color($display, [390, 392, 394, 396], [243, 255, 235, 247], 4, 20, 0xFF00FFFF);
  110. =head2 character
  111. int SDL::GFX::Primitives::character_color( $surface, $x, $y, $c, $color );
  112. int SDL::GFX::Primitives::character_RGBA( $surface, $x, $y, $c, $r, $g, $b, $a );
  113. C<$c> is the character that will be drawn at C<$x>,C<$y>.
  114. =head2 string
  115. int SDL::GFX::Primitives::string_color( $surface, $x, $y, $c, $color );
  116. int SDL::GFX::Primitives::string_RGBA( $surface, $x, $y, $c, $r, $g, $b, $a );
  117. =head2 set_font
  118. void SDL::GFX::Primitives::set_font(fontdata, $cw, $ch );
  119. The fontsets are included in the SDL_gfx distribution. Check L<http://www.ferzkopp.net/joomla/content/view/19/14/> for more.
  120. Example:
  121. my $font = '';
  122. open(FH, '<', 'data/5x7.fnt');
  123. binmode(FH);
  124. read(FH, $font, 4096);
  125. close(FH);
  126. SDL::GFX::Primitives::set_font($font, 5, 7);
  127. =head1 AUTHORS
  128. See L<SDL/AUTHORS>.