AlphaFeld.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "AlphaFeld.h"
  2. #include "Punkt.h"
  3. #include "Bild.h"
  4. #include "Scroll.h"
  5. #include "ToolTip.h"
  6. #include "Text.h"
  7. using namespace Framework;
  8. // Inhalt der AlphaFeld Klasse aus AlphaFeld.h
  9. // Konstruktor
  10. AlphaFeld::AlphaFeld()
  11. : Zeichnung(),
  12. strength( 5 ),
  13. farbe( 0x9B000000 ),
  14. ref( 1 )
  15. {}
  16. AlphaFeld::~AlphaFeld()
  17. {}
  18. // nicht constant
  19. void AlphaFeld::setStrength( int st ) // setzt die Stärke
  20. {
  21. strength = st;
  22. rend = 1;
  23. }
  24. void AlphaFeld::setFarbe( int f ) // setzt die Farbe
  25. {
  26. farbe = f;
  27. rend = 1;
  28. }
  29. void AlphaFeld::render( Bild &zRObj ) // zeichnet nach zRObj
  30. {
  31. Zeichnung::render( zRObj );
  32. int br = gr.x - 1;
  33. int hi = gr.y - 1;
  34. int xp = pos.x, yp = pos.y;
  35. int a = ( farbe >> 24 ) & 0xFF;
  36. int index = ( br / 2 ) * ( br <= hi ) + ( hi / 2 ) * ( br > hi );
  37. int fc = farbe & 0x00FFFFFF;
  38. int fc2 = farbe;
  39. if( strength > 0 )
  40. index = index > ( a / strength ) ? a / strength : index;
  41. if( strength < 0 )
  42. index = index > ( ( 255 - a ) / -strength ) ? ( ( 255 - a ) / -strength ) : index;
  43. for( int i = 0; i < index; ++i )
  44. {
  45. a -= strength;
  46. fc2 = ( a << 24 ) | fc;
  47. int i2 = i << 1;
  48. zRObj.drawLinieHAlpha( xp + i + 1, yp + i, br - i2, fc2 ); // oben links --- oben rechts
  49. zRObj.drawLinieVAlpha( xp + br - i, yp + i + 1, hi - i2, fc2 ); // oben rechts -- unten rechts
  50. zRObj.drawLinieHAlpha( xp + i, yp + hi - i, br - i2, fc2 ); // unten rechts - unten links
  51. zRObj.drawLinieVAlpha( xp + i, yp + i, hi - i2, fc2 ); // unten links -- oben links
  52. }
  53. if( index == br / 2 )
  54. {
  55. for( int i = index; i <= index + ( br - index ) - index; ++i )
  56. zRObj.drawLinieVAlpha( xp + i, yp + index, hi - ( index << 1 ) + 1, fc2 ); // rest Fläche senkrecht
  57. }
  58. else
  59. {
  60. for( int i = index; i <= index + ( hi - index ) - index; ++i )
  61. zRObj.drawLinieHAlpha( xp + index, yp + i, br - ( index << 1 ) + 1, fc2 ); // rest Fläche waagerecht
  62. }
  63. }
  64. // constant
  65. int AlphaFeld::getStrength() const // gibt die Stärke zurück
  66. {
  67. return strength;
  68. }
  69. int AlphaFeld::getFarbe() const // gibt die Farbe zurück
  70. {
  71. return farbe;
  72. }
  73. Zeichnung *AlphaFeld::dublizieren() const // Kopiert das Zeichnung
  74. {
  75. AlphaFeld *obj = new AlphaFeld();
  76. obj->setPosition( pos );
  77. obj->setSize( gr );
  78. obj->setMausEreignisParameter( makParam );
  79. obj->setTastaturEreignisParameter( takParam );
  80. obj->setMausEreignis( Mak );
  81. obj->setTastaturEreignis( Tak );
  82. if( toolTip )
  83. obj->setToolTipText( toolTip->zText()->getText(), toolTip->zBildschirm() );
  84. obj->setStrength( strength );
  85. obj->setFarbe( farbe );
  86. return obj;
  87. }
  88. // Reference Counting
  89. AlphaFeld *AlphaFeld::getThis()
  90. {
  91. ++ref;
  92. return this;
  93. }
  94. AlphaFeld *AlphaFeld::release()
  95. {
  96. --ref;
  97. if( !ref )
  98. delete this;
  99. return 0;
  100. }