Browse Source

Linien mit rahmen drum können nun gezeichnet werden

kolja 5 years ago
parent
commit
b72e9883df
2 changed files with 252 additions and 16 deletions
  1. 240 11
      Bild.cpp
  2. 12 5
      Bild.h

+ 240 - 11
Bild.cpp

@@ -7,7 +7,6 @@
 
 #endif
 #include "Bild.h"
-#ifdef WIN32
 #include "DateiSystem.h"
 #include "Scroll.h"
 #include "Rahmen.h"
@@ -16,7 +15,7 @@
 #include "ToolTip.h"
 #include "Text.h"
 #include "AlphaFeld.h"
-#else
+#ifndef WIN32
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
@@ -670,6 +669,237 @@ void Bild::drawLinieVAlpha( int x, int y, int len, int f ) // zeichnet eine vert
     rend = 1;
 }
 
+void Bild::drawLinieBordered( Punkt a, Punkt b, int bc, int fc )
+{
+    if( alpha[ alphaAnzahl ] == 0xFF )
+        return;
+    if( alpha[ alphaAnzahl ] )
+    {
+        drawLinieBorderedAlpha( a, b, bc, fc );
+        return;
+    }
+    a += drawOff[ doa ];
+    b += drawOff[ doa ];
+    char outCode1 = getOutCode( a );
+    char outCode2 = getOutCode( b );
+    bool ok = 0;
+    while( 1 )
+    {
+        int xMax = dSizeA[ doa ].x - 1;
+        int yMax = dSizeA[ doa ].y - 1;
+        if( !( outCode1 | outCode2 ) )
+        {
+            ok = 1;
+            break;
+        }
+        else if( outCode1 & outCode2 )
+            break;
+        else
+        {
+            int x = 0, y = 0;
+            char outCodeOut = outCode1 ? outCode1 : outCode2;
+            if( outCodeOut & 8 )
+            {
+                x = (int)( a.x + ( b.x - a.x ) * ( yMax - a.y ) / ( b.y - a.y ) + 0.5 );
+                y = yMax;
+            }
+            else if( outCodeOut & 4 )
+            {
+                x = (int)( a.x + ( b.x - a.x ) * ( dPosA[ doa ].y - a.y ) / ( b.y - a.y ) + 0.5 );
+                y = dPosA[ doa ].y;
+            }
+            else if( outCodeOut & 2 )
+            {
+                y = (int)( a.y + ( b.y - a.y ) * ( xMax - a.x ) / ( b.x - a.x ) + 0.5 );
+                x = xMax;
+            }
+            else if( outCodeOut & 1 )
+            {
+                y = (int)( a.y + ( b.y - a.y ) * ( dPosA[ doa ].x - a.x ) / ( b.x - a.x ) + 0.5 );
+                x = dPosA[ doa ].x;
+            }
+            if( outCodeOut == outCode1 )
+            {
+                a.x = x;
+                a.y = y;
+                outCode1 = getOutCode( a );
+            }
+            else
+            {
+                b.x = x;
+                b.y = y;
+                outCode2 = getOutCode( b );
+            }
+        }
+    }
+    if( ok )
+    {
+        int xlen = b.x - a.x, axlen = abs( xlen );
+        int ylen = b.y - a.y, aylen = abs( ylen );
+        double xf = (double)xlen / ( aylen ? aylen : 1 );
+        double yf = (double)ylen / ( axlen ? axlen : 1 );
+        if( axlen > aylen )
+            xf = xf < 0 ? -1 : 1;
+        else
+            yf = yf < 0 ? -1 : 1;
+        double x = (double)a.x, y = (double)a.y;
+        int maxP = (int)( sqrt( xlen * xlen + ylen * ylen ) + 0.5 );
+        int count = 0;
+        int maxPixel = size.x * size.y;
+        while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
+        {
+            ++count;
+            this->fc[ (int)( (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ) ] = fc;
+            if( (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel &&
+                this->fc[ (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) ] != fc )
+                this->fc[ (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) ] = bc;
+            if( (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel &&
+                this->fc[ (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) ] != fc )
+                this->fc[ (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) ] = bc;
+            if( (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) < maxPixel &&
+                this->fc[ (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) ] != fc )
+                this->fc[ (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) ] = bc;
+            if( (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) < maxPixel &&
+                this->fc[ (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) ] != fc )
+                this->fc[ (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) ] = bc;
+            x += xf, y += yf;
+        }
+        rend = 1;
+    }
+}
+
+void Bild::drawLinieBorderedAlpha( Punkt a, Punkt b, int bc, int fc )
+{
+    if( alpha[ alphaAnzahl ] == 0xFF )
+        return;
+    a += drawOff[ doa ];
+    b += drawOff[ doa ];
+    char outCode1 = getOutCode( a );
+    char outCode2 = getOutCode( b );
+    bool ok = 0;
+    while( 1 )
+    {
+        int xMax = dSizeA[ doa ].x - 1;
+        int yMax = dSizeA[ doa ].y - 1;
+        if( !( outCode1 | outCode2 ) )
+        {
+            ok = 1;
+            break;
+        }
+        else if( outCode1 & outCode2 )
+            break;
+        else
+        {
+            int x = 0, y = 0;
+            char outCodeOut = outCode1 ? outCode1 : outCode2;
+            if( outCodeOut & 8 )
+            {
+                x = (int)( a.x + ( b.x - a.x ) * ( yMax - a.y ) / ( b.y - a.y ) + 0.5 );
+                y = yMax;
+            }
+            else if( outCodeOut & 4 )
+            {
+                x = (int)( a.x + ( b.x - a.x ) * ( dPosA[ doa ].y - a.y ) / ( b.y - a.y ) + 0.5 );
+                y = dPosA[ doa ].y;
+            }
+            else if( outCodeOut & 2 )
+            {
+                y = (int)( a.y + ( b.y - a.y ) * ( xMax - a.x ) / ( b.x - a.x ) + 0.5 );
+                x = xMax;
+            }
+            else if( outCodeOut & 1 )
+            {
+                y = (int)( a.y + ( b.y - a.y ) * ( dPosA[ doa ].x - a.x ) / ( b.x - a.x ) + 0.5 );
+                x = dPosA[ doa ].x;
+            }
+            if( outCodeOut == outCode1 )
+            {
+                a.x = x;
+                a.y = y;
+                outCode1 = getOutCode( a );
+            }
+            else
+            {
+                b.x = x;
+                b.y = y;
+                outCode2 = getOutCode( b );
+            }
+        }
+    }
+    if( ok )
+    {
+        int xlen = b.x - a.x, axlen = abs( xlen );
+        int ylen = b.y - a.y, aylen = abs( ylen );
+        double xf = (double)xlen / ( aylen ? aylen : 1 );
+        double yf = (double)ylen / ( axlen ? axlen : 1 );
+        if( axlen > aylen )
+            xf = xf < 0 ? -1 : 1;
+        else
+            yf = yf < 0 ? -1 : 1;
+        double x = (double)a.x, y = (double)a.y;
+        if( alpha[ alphaAnzahl ] )
+        {
+            unsigned char *cf = (unsigned char*)&fc;
+            cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
+        }
+        int maxP = (int)( sqrt( xlen * xlen + ylen * ylen ) + 0.5 );
+        int alpha = ( ( fc >> 24 ) & 0xFF );
+        int alpha2 = ( ( bc >> 24 ) & 0xFF );
+        int na = ( 0x100 - alpha );
+        int na2 = ( 0x100 - alpha2 );
+        int i1 = ( alpha * ( fc & 0xFF00FF ) ) >> 8;
+        int i2 = ( alpha * ( fc & 0x00FF00 ) ) >> 8;
+        int j1 = ( alpha2 * ( bc & 0xFF00FF ) ) >> 8;
+        int j2 = ( alpha2 * ( bc & 0x00FF00 ) ) >> 8;
+        int count = 0;
+        int maxPixel = size.x * size.y;
+        while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
+        {
+            ++count;
+            if( (int)( (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel )
+            {
+                int &pixel = this->fc[ (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ];
+                pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
+                    ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+            }
+            if( (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel )
+            {
+                int &pixel = this->fc[ (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ];
+                pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
+                    ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+            }
+            if( (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) < maxPixel )
+            {
+                int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ];
+                pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
+                    ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+            }
+            if( (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) < maxPixel )
+            {
+                int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ];
+                pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
+                    ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+            }
+            x += xf, y += yf;
+        }
+        count = 0;
+        while( !( (int)( x + 0.5 ) == b.x && (int)( y + 0.5 ) == b.y ) && count < maxP )
+        {
+            ++count;
+            int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ];
+            pixel = ( ( ( ( ( na * ( pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
+                ( ( ( ( na * ( pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
+                      ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * fc;
+            x += xf, y += yf;
+        }
+        rend = 1;
+    }
+}
+
 void Bild::drawLinie( Punkt a, Punkt b, int fc ) // zeichnet eine Linie von Punkt( x1, y1 ) nach Punke( x2, y2 )
 {
     if( alpha[ alphaAnzahl ] == 0xFF )
@@ -1838,7 +2068,7 @@ void Bild::replaceColorWithAlpha( int color )
         int ygr = y * size.x;
         for( int x = dx + xx; x < bb; x++ )
         {
-            unsigned char *cf = (unsigned char*)&(fc[ x + ygr ]);
+            unsigned char *cf = ( unsigned char* )&( fc[ x + ygr ] );
             int abstand = (int)sqrt( ( r - cf[ 2 ] ) * ( r - cf[ 2 ] ) + ( g - cf[ 1 ] ) * ( g - cf[ 1 ] ) + ( b - cf[ 0 ] ) * ( b - cf[ 0 ] ) );
             if( abstand > 255 )
                 abstand = 255;
@@ -2001,7 +2231,6 @@ Bild *Bild::release()
 }
 
 
-#ifdef WIN32
 // Inhalt der BildZ Klasse aus Bild.h
 // Konstruktor 
 BildZ::BildZ()
@@ -2056,7 +2285,7 @@ void BildZ::setBild( Bild *b )
 
 bool BildZ::tick( double tickVal ) // tick
 {
-    return __super::tick( tickVal );
+    return ZeichnungHintergrund::tick( tickVal );
 }
 
 void BildZ::doMausEreignis( MausEreignis &me ) // ruft Mak auf
@@ -2125,7 +2354,7 @@ void BildZ::render( Bild &zRObj ) // zeichnet nach zRObj
 {
     if( hatStyle( Style::Sichtbar ) )
     {
-        __super::render( zRObj );
+        ZeichnungHintergrund::render( zRObj );
         lockZeichnung();
         if( !zRObj.setDrawOptions( innenPosition, innenSize ) )
         {
@@ -2137,17 +2366,17 @@ void BildZ::render( Bild &zRObj ) // zeichnet nach zRObj
             int x = 0;
             int y = 0;
             int br = innenSize.x;
-            int hö = innenSize.y;
+            int hi = innenSize.y;
             if( !( vertikalScrollBar && hatStyle( Style::VScroll ) ) && !( horizontalScrollBar && hatStyle( Style::HScroll ) ) )
             {
                 if( hatStyle( Style::Alpha ) )
-                    zRObj.alphaBild( x, y, br, hö, *bild );
+                    zRObj.alphaBild( x, y, br, hi, *bild );
                 else
-                    zRObj.drawBild( x, y, br, hö, *bild );
+                    zRObj.drawBild( x, y, br, hi, *bild );
             }
             else
             {
-                if( !zRObj.setDrawOptions( x, y, br, hö ) )
+                if( !zRObj.setDrawOptions( x, y, br, hi ) )
                 {
                     zRObj.releaseDrawOptions();
                     unlockZeichnung();
@@ -2218,7 +2447,7 @@ BildZ *BildZ::release()
     return 0;
 }
 
-
+#ifdef WIN32
 Bild *Framework::ladeBild( char *pfad, Text *zError )
 {
     Text p = pfad;

+ 12 - 5
Bild.h

@@ -2,11 +2,8 @@
 #define Bild_H
 
 #include "Array.h"
-#ifdef WIN32
 #include "Zeichnung.h"
-#else
 #include "Punkt.h"
-#endif
 
 namespace Framework
 {
@@ -154,6 +151,16 @@ namespace Framework
         //  a: Der Startpunkt der Linie
         //  b: der Endpunkt der Linie
         //  fc: Die Farbe im A8R8G8B8 Format
+        __declspec( dllexport ) void drawLinieBordered( Punkt a, Punkt b, int bc, int fc );
+        // Zeichnet eine Linie
+        //  a: Der Startpunkt der Linie
+        //  b: der Endpunkt der Linie
+        //  fc: Die Farbe im A8R8G8B8 Format
+        __declspec( dllexport ) void drawLinieBorderedAlpha( Punkt a, Punkt b, int bc, int fc );
+        // Zeichnet eine Linie
+        //  a: Der Startpunkt der Linie
+        //  b: der Endpunkt der Linie
+        //  fc: Die Farbe im A8R8G8B8 Format
         __declspec( dllexport ) void drawLinie( Punkt a, Punkt b, int fc );
         // Zeichnet eine Linie mit Alpha Blending
         //  a: Der Startpunkt der Linie
@@ -346,7 +353,6 @@ namespace Framework
         //  return: 0.
         __declspec( dllexport ) Bild *release();
     };
-#ifdef WIN32
 
     // Eine Zeichnung des 2d GUI Frameworks, die ein Bild anzeigt.
     class BildZ : public ZeichnungHintergrund
@@ -367,7 +373,7 @@ namespace Framework
         // Konstruktor 
         __declspec( dllexport ) BildZ();
         // Destruktor 
-        __declspec( dllexport ) ~BildZ();
+        __declspec( dllexport ) virtual ~BildZ();
         // Setzt einen Zeiger auf das Bild, was angezeigt werden soll
         //  b: Das Bild
         __declspec( dllexport ) void setBildZ( Bild *b );
@@ -398,6 +404,7 @@ namespace Framework
         __declspec( dllexport ) BildZ *release();
     };
 
+#ifdef WIN32
     // Lädt ein Bild aus einer .bmp, .jpg, .gif oder .png Datei
     //  pfad: Der Pfad zur Bilddatei
     //  zError: Ein Zeiger auf ein Text Objekt, in dem ein möglicher Fehler zurückgegeben wird