00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLConic.h"
00028
00029 #include "OSDLFromGfx.h"
00030 #include "OSDLSurface.h"
00031 #include "OSDLPoint2D.h"
00032 #include "OSDLVideo.h"
00033
00034 #include "Ceylan.h"
00035
00036
00037
00038 #ifdef OSDL_USES_CONFIG_H
00039 #include <OSDLConfig.h>
00040 #endif // OSDL_USES_CONFIG_H
00041
00042
00043 #if OSDL_ARCH_NINTENDO_DS
00044 #include "OSDLConfigForNintendoDS.h"
00045 #endif // OSDL_ARCH_NINTENDO_DS
00046
00047
00048 using namespace OSDL::Video ;
00049 using namespace OSDL::Video::Pixels ;
00050
00051 using namespace Ceylan::Log ;
00052
00053
00054
00055
00056 #if OSDL_USES_SDL_GFX
00057
00058 #include "SDL_gfxPrimitives.h"
00059
00060 #endif // OSDL_USES_SDL_GFX
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 bool TwoDimensional::drawCircle( Surface & targetSurface,
00071 Coordinate xCenter, Coordinate yCenter, Length radius,
00072 Pixels::ColorElement red, Pixels::ColorElement green,
00073 Pixels::ColorElement blue, Pixels::ColorElement alpha,
00074 bool filled, bool blended )
00075 {
00076
00077 #if OSDL_USES_SDL_GFX
00078
00079
00080
00081
00082
00083
00084
00085
00086 #if OSDL_DEBUG_CONICS
00087
00088 LogPlug::trace( "TwoDimensional::drawCircle (RGBA): center = ["
00089 + Ceylan::toString( xCenter ) + ";" + Ceylan::toString( yCenter )
00090 + "], radius = " + Ceylan::toString( radius )
00091 + ", color: " + Pixels::toString(
00092 Pixels::convertRGBAToColorDefinition( red, green, blue, alpha ) )
00093 + ", filled = " + Ceylan::toString( filled )
00094 + ", blended = " + Ceylan::toString( blended ) ) ;
00095
00096 #endif // OSDL_DEBUG_CONICS
00097
00098 if ( blended )
00099 {
00100
00101 if ( filled )
00102 {
00103
00104
00105 return ( ::filledCircleRGBA( & targetSurface.getSDLSurface(),
00106 xCenter, yCenter, radius, red, green, blue, alpha ) == 0 ) ;
00107 }
00108 else
00109 {
00110
00111
00112
00113 if ( VideoModule::GetAntiAliasingState() )
00114 {
00115 return ( ::aacircleRGBA( & targetSurface.getSDLSurface(),
00116 xCenter, yCenter, radius, red, green, blue, alpha ) == 0 ) ;
00117
00118 }
00119 else
00120 {
00121 return ( ::circleRGBA( & targetSurface.getSDLSurface(),
00122 xCenter, yCenter, radius, red, green, blue, alpha ) == 0 ) ;
00123
00124 }
00125
00126 }
00127
00128 }
00129 else
00130 {
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 if ( filled )
00141 {
00142
00143
00144 return ( ::filledCircleRGBANotBlended(
00145 & targetSurface.getSDLSurface(),
00146 xCenter, yCenter, radius, red, green, blue, alpha ) == 0 ) ;
00147 }
00148 else
00149 {
00150
00151
00152
00153
00154 if ( VideoModule::GetAntiAliasingState() )
00155 {
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 return ( ::aacircleRGBA( & targetSurface.getSDLSurface(),
00166 xCenter, yCenter, radius, red, green, blue, alpha ) == 0 ) ;
00167 }
00168 else
00169 {
00170
00171
00172
00173
00174
00175
00176
00177
00178 return ( ::circleRGBA( & targetSurface.getSDLSurface(),
00179 xCenter, yCenter, radius, red, green, blue, alpha ) == 0 ) ;
00180 }
00181
00182 }
00183
00184 }
00185
00186 #else // OSDL_USES_SDL_GFX
00187
00188 throw VideoException( "TwoDimensional::drawCircle: "
00189 "no SDL_gfx support available" ) ;
00190
00191 #endif // OSDL_USES_SDL_GFX
00192
00193 }
00194
00195
00196
00197 bool TwoDimensional::drawCircle( Surface & targetSurface,
00198 Coordinate xCenter, Coordinate yCenter,
00199 Length radius, Pixels::ColorDefinition colorDef, bool filled, bool blended )
00200 {
00201
00202 #if OSDL_USES_SDL_GFX
00203
00204 #if OSDL_DEBUG_CONICS
00205
00206 LogPlug::trace( "TwoDimensional::drawCircle (color definition): center = ["
00207 + Ceylan::toString( xCenter ) + ";" + Ceylan::toString( yCenter )
00208 + "], radius = " + Ceylan::toString( radius )
00209 + ", color: " + Pixels::toString( colorDef )
00210 + ", filled = " + Ceylan::toString( filled )
00211 + ", blended = " + Ceylan::toString( blended ) ) ;
00212
00213 #endif // OSDL_DEBUG_CONICS
00214
00215
00216 if ( blended )
00217 {
00218
00219 if ( filled )
00220 {
00221
00222
00223 return ( ::filledCircleColor( & targetSurface.getSDLSurface(),
00224 xCenter, yCenter, radius,
00225 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00226 == 0 ) ;
00227 }
00228 else
00229 {
00230
00231
00232
00233 if ( VideoModule::GetAntiAliasingState() )
00234 {
00235
00236 return ( ::aacircleColor( & targetSurface.getSDLSurface(),
00237 xCenter, yCenter, radius,
00238 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00239 == 0 ) ;
00240
00241 }
00242 else
00243 {
00244
00245 return ( ::circleColor( & targetSurface.getSDLSurface(),
00246 xCenter, yCenter, radius,
00247 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00248 == 0 ) ;
00249
00250 }
00251
00252 }
00253
00254 }
00255 else
00256 {
00257
00258
00259
00260
00261
00262
00263
00264 if ( filled )
00265 {
00266
00267
00268
00269 #if OSDL_DEBUG_CONICS
00270 LogPlug::trace( "TwoDimensional::drawCircle: "
00271 "before filledCircleColorNotBlended, "
00272 + targetSurface.describePixelAt( xCenter, yCenter ) ) ;
00273
00274 bool result = ( ::filledCircleRGBANotBlended(
00275 & targetSurface.getSDLSurface(), xCenter, yCenter, radius,
00276 colorDef.r, colorDef.g, colorDef.b, colorDef.unused ) == 0 ) ;
00277
00278 LogPlug::trace( "TwoDimensional::drawCircle: "
00279 "after filledCircleColorNotBlended, "
00280 + targetSurface.describePixelAt( xCenter, yCenter ) ) ;
00281
00282 return result ;
00283
00284 #endif // OSDL_DEBUG_CONICS
00285
00286 return ( ::filledCircleRGBANotBlended(
00287 & targetSurface.getSDLSurface(), xCenter, yCenter, radius,
00288 colorDef.r, colorDef.g, colorDef.b, colorDef.unused ) == 0 ) ;
00289
00290 }
00291 else
00292 {
00293
00294
00295
00296
00297 if ( VideoModule::GetAntiAliasingState() )
00298 {
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 return ( ::aacircleRGBA( & targetSurface.getSDLSurface(),
00311 xCenter, yCenter, radius,
00312 colorDef.r, colorDef.g, colorDef.b, colorDef.unused )
00313 == 0 ) ;
00314 }
00315 else
00316 {
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 return ( ::circleRGBA( & targetSurface.getSDLSurface(),
00328 xCenter, yCenter, radius,
00329 colorDef.r, colorDef.g, colorDef.b, colorDef.unused )
00330 == 0 ) ;
00331
00332 }
00333
00334 }
00335
00336 }
00337
00338 #else // OSDL_USES_SDL_GFX
00339
00340 throw VideoException( "TwoDimensional::drawCircle: "
00341 "no SDL_gfx support available" ) ;
00342
00343 #endif // OSDL_USES_SDL_GFX
00344
00345 }
00346
00347
00348
00349 bool TwoDimensional::drawDiscWithEdge( Surface & targetSurface,
00350 Coordinate xCenter, Coordinate yCenter,
00351 Length outerRadius, Length innerRadius,
00352 Pixels::ColorDefinition ringColorDef,
00353 Pixels::ColorDefinition discColorDef, bool blended )
00354 {
00355
00356 #if OSDL_USES_SDL_GFX
00357
00358 if ( innerRadius >= outerRadius )
00359 return false ;
00360
00361
00362
00363
00364
00365
00366
00367 if ( discColorDef.unused != AlphaOpaque && blended )
00368 {
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 #ifdef OSDL_MUST_RECTIFY_DISC_ALPHA
00403
00404
00405
00406
00407 Surface * fullEdgedDiscSurface = new Surface(
00408 Surface::Software | Surface::AlphaBlendingBlit,
00409 2 * outerRadius, 2 * outerRadius ) ;
00410
00411
00412
00413
00414 ColorElement ringAlpha = ringColorDef.unused ;
00415 ringColorDef.unused = Pixels::AlphaOpaque ;
00416
00417
00418 if ( ! fullEdgedDiscSurface->drawCircle( outerRadius,
00419 outerRadius, outerRadius, ringColorDef, true ) )
00420 {
00421 delete fullEdgedDiscSurface ;
00422 return false ;
00423 }
00424
00425
00426
00427 ColorElement discAlpha = discColorDef.unused ;
00428 discColorDef.unused = Pixels::AlphaOpaque ;
00429
00430 fullEdgedDiscSurface->drawCircle( outerRadius,
00431 outerRadius, innerRadius, discColorDef, true ) ;
00432
00433
00434
00435
00436
00437
00438 fullEdgedDiscSurface->setAlphaForColor( ringColorDef, ringAlpha ) ;
00439
00440
00441
00442
00443
00444
00445
00446 fullEdgedDiscSurface->setAlphaForColor( discColorDef, discAlpha ) ;
00447
00448 LogPlug::debug( "fullEdgedDiscSurface: "
00449 + fullEdgedDiscSurface->describePixelAt(
00450 outerRadius, outerRadius ) ) ;
00451
00452 fullEdgedDiscSurface->blitTo( targetSurface,
00453 xCenter - outerRadius, yCenter - outerRadius ) ;
00454
00455 delete fullEdgedDiscSurface ;
00456
00457
00458 #else // OSDL_MUST_RECTIFY_DISC_ALPHA
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 Surface * fullEdgedDiscSurface = new Surface(
00469 Surface::Software | Surface::AlphaBlendingBlit,
00470 2 * outerRadius, 2 * outerRadius ) ;
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 if ( ! fullEdgedDiscSurface->drawCircle(
00490 outerRadius, outerRadius, outerRadius,
00491 ringColorDef, true, false ) )
00492 {
00493 delete fullEdgedDiscSurface ;
00494 return false ;
00495 }
00496
00497
00498
00499 if ( ! fullEdgedDiscSurface->drawCircle(
00500 outerRadius, outerRadius, innerRadius,
00501 discColorDef, true, false ) )
00502 {
00503 delete fullEdgedDiscSurface ;
00504 return false ;
00505 }
00506
00507 fullEdgedDiscSurface->blitTo( targetSurface,
00508 xCenter - outerRadius, yCenter - outerRadius ) ;
00509
00510 delete fullEdgedDiscSurface ;
00511
00512
00513 #endif // OSDL_MUST_RECTIFY_DISC_ALPHA
00514
00515
00516 return true ;
00517
00518
00519 }
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529 if ( ! drawCircle( targetSurface, xCenter, yCenter,
00530 outerRadius, ringColorDef, true, blended ) )
00531 {
00532 return false ;
00533 }
00534
00535
00536
00537 if ( ! drawCircle( targetSurface, xCenter, yCenter,
00538 innerRadius, discColorDef, true, blended ) )
00539 {
00540 return false ;
00541 }
00542
00543 return true ;
00544
00545 #else // OSDL_USES_SDL_GFX
00546
00547 throw VideoException( "TwoDimensional::drawDiscWithEdge: "
00548 "no SDL_gfx support available" ) ;
00549
00550 #endif // OSDL_USES_SDL_GFX
00551
00552 }
00553
00554
00555
00556 bool TwoDimensional::drawEllipse( Surface & targetSurface,
00557 Coordinate xCenter, Coordinate yCenter,
00558 Length horizontalRadius, Length verticalRadius,
00559 Pixels::ColorElement red, Pixels::ColorElement green,
00560 Pixels::ColorElement blue, Pixels::ColorElement alpha, bool filled )
00561 {
00562
00563 #if OSDL_USES_SDL_GFX
00564
00565 if ( filled )
00566 {
00567
00568 return ( ::filledEllipseRGBA( & targetSurface.getSDLSurface(),
00569 xCenter, yCenter, horizontalRadius, verticalRadius,
00570 red, green, blue, alpha ) == 0 ) ;
00571 }
00572 else
00573 {
00574
00575 if ( VideoModule::GetAntiAliasingState() )
00576 {
00577
00578 return ( ::aaellipseRGBA( & targetSurface.getSDLSurface(),
00579 xCenter, yCenter, horizontalRadius, verticalRadius,
00580 red, green, blue, alpha ) == 0 ) ;
00581
00582
00583 }
00584 else
00585 {
00586
00587 return ( ::ellipseRGBA( & targetSurface.getSDLSurface(),
00588 xCenter, yCenter, horizontalRadius, verticalRadius,
00589 red, green, blue, alpha ) == 0 ) ;
00590
00591 }
00592
00593 }
00594
00595 #else // OSDL_USES_SDL_GFX
00596
00597 throw VideoException( "TwoDimensional::drawEllipse: "
00598 "no SDL_gfx support available" ) ;
00599
00600 #endif // OSDL_USES_SDL_GFX
00601
00602 }
00603
00604
00605
00606 bool TwoDimensional::drawEllipse( Surface & targetSurface,
00607 Coordinate xCenter, Coordinate yCenter,
00608 Length horizontalRadius, Length verticalRadius,
00609 Pixels::ColorDefinition colorDef, bool filled )
00610 {
00611
00612 #if OSDL_USES_SDL_GFX
00613
00614 if ( filled )
00615 {
00616
00617 return ( ::filledEllipseColor( & targetSurface.getSDLSurface(),
00618 xCenter, yCenter, horizontalRadius, verticalRadius,
00619 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) ) == 0 ) ;
00620
00621 }
00622 else
00623 {
00624
00625 if ( VideoModule::GetAntiAliasingState() )
00626 {
00627
00628 return ( ::aaellipseColor( & targetSurface.getSDLSurface(),
00629 xCenter, yCenter, horizontalRadius, verticalRadius,
00630 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00631 == 0 ) ;
00632
00633 }
00634 else
00635 {
00636
00637 return ( ::ellipseColor( & targetSurface.getSDLSurface(),
00638 xCenter, yCenter, horizontalRadius, verticalRadius,
00639 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00640 == 0 ) ;
00641
00642 }
00643
00644 }
00645
00646 #else // OSDL_USES_SDL_GFX
00647
00648 throw VideoException( "TwoDimensional::drawEllipse: "
00649 "no SDL_gfx support available" ) ;
00650
00651 #endif // OSDL_USES_SDL_GFX
00652
00653 }