Subversion Repositories tpanel

Rev

Rev 338 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 338 Rev 339
Line 631... Line 631...
631
    }
631
    }
632
 
632
 
633
    return "None";
633
    return "None";
634
}
634
}
635
 
635
 
-
 
636
/**
-
 
637
 * @brief erasePart - Erases the parts of a button who are not coverered by a border.
-
 
638
 * The method starts from left, right, top or bottom and erases avery pixel
-
 
639
 * who has an alpha value grater 0. It stops if it finds a visible pixel.
-
 
640
 * So every pixel outside of the border is removed (transparent).
-
 
641
 *
-
 
642
 * @param bm        A pointer to a bitmap containing the button image. This
-
 
643
 *                  must not be null or empty.
-
 
644
 * @param mask      A bitmap containg the border image. This must be of the
-
 
645
 *                  same size as \b bm.
-
 
646
 * @param ep        The side (left, right, top, bottom, outside) who should be
-
 
647
 *                  filtered. The option "outside" filters all four sides.
-
 
648
 */
636
void TIntBorder::erasePart(SkBitmap *bm, const SkBitmap& mask, ERASE_PART_t ep)
649
void TIntBorder::erasePart(SkBitmap *bm, const SkBitmap& mask, ERASE_PART_t ep)
637
{
650
{
638
    DECL_TRACER("TIntBorder::erasePart(SkBitmap *bm, const SkBitmap& mask, ERASE_PART_t ep)");
651
    DECL_TRACER("TIntBorder::erasePart(SkBitmap *bm, const SkBitmap& mask, ERASE_PART_t ep)");
639
 
652
 
640
    if (!bm || bm->empty() || ep == ERASE_NONE)
653
    if (!bm || bm->empty() || ep == ERASE_NONE)
Line 647... Line 660...
647
    switch(ep)
660
    switch(ep)
648
    {
661
    {
649
        case ERASE_LEFT_RIGHT:
662
        case ERASE_LEFT_RIGHT:
650
            for (y = 0; y < height; ++y)
663
            for (y = 0; y < height; ++y)
651
            {
664
            {
652
                bool barrier = false;
-
 
653
 
-
 
654
                for (x = 0; x < width; ++x)
665
                for (x = 0; x < width; ++x)
655
                {
666
                {
656
                    uint32_t *wpix = bm->getAddr32(x, y);
667
                    SkColor *wpix = bm->getAddr32(x, y);
657
                    uint32_t color = mask.getColor(x, y);
668
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
-
 
669
 
-
 
670
                    if (alpha == 0)
658
                    barrier = setPixel(wpix, color, barrier);
671
                        *wpix = SK_ColorTRANSPARENT;
-
 
672
                    else
-
 
673
                        break;
659
                }
674
                }
660
            }
675
            }
661
        break;
676
        break;
662
 
677
 
663
        case ERASE_RIGHT_LEFT:
678
        case ERASE_RIGHT_LEFT:
664
            for (y = 0; y < height; ++y)
679
            for (y = 0; y < height; ++y)
665
            {
680
            {
666
                bool barrier = false;
-
 
667
 
-
 
668
                for (x = width - 1; x > 0; --x)
681
                for (x = width - 1; x >= 0; --x)
669
                {
682
                {
670
                    uint32_t *wpix = bm->getAddr32(x, y);
683
                    SkColor *wpix = bm->getAddr32(x, y);;
671
                    uint32_t color = mask.getColor(x, y);
684
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
-
 
685
 
-
 
686
                    if (alpha == 0)
672
                    barrier = setPixel(wpix, color, barrier);
687
                        *wpix = SK_ColorTRANSPARENT;
-
 
688
                    else
-
 
689
                        break;
673
                }
690
                }
674
            }
691
            }
675
        break;
692
        break;
676
 
693
 
677
        case ERASE_TOP_DOWN:
694
        case ERASE_TOP_DOWN:
678
            for (x = 0; x < width; ++x)
695
            for (x = 0; x < width; ++x)
679
            {
696
            {
680
                bool barrier = false;
-
 
681
 
-
 
682
                for (y = 0; y < height; ++y)
697
                for (y = 0; y < height; ++y)
683
                {
698
                {
684
                    uint32_t *wpix = bm->getAddr32(x, y);
699
                    SkColor *wpix = bm->getAddr32(x, y);;
685
                    uint32_t color = mask.getColor(x, y);
700
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
-
 
701
 
-
 
702
                    if (alpha == 0)
686
                    barrier = setPixel(wpix, color, barrier);
703
                        *wpix = SK_ColorTRANSPARENT;
-
 
704
                    else
-
 
705
                        break;
687
                }
706
                }
688
            }
707
            }
689
        break;
708
        break;
690
 
709
 
691
        case ERASE_BOTTOM_UP:
710
        case ERASE_BOTTOM_UP:
692
            for (x = 0; x < width; ++x)
711
            for (x = 0; x < width; ++x)
693
            {
712
            {
694
                bool barrier = false;
-
 
695
 
-
 
696
                for (y = height - 1; y > 0; --y)
713
                for (y = height - 1; y >= 0; --y)
697
                {
714
                {
698
                    uint32_t *wpix = bm->getAddr32(x, y);
715
                    SkColor *wpix = bm->getAddr32(x, y);;
699
                    uint32_t color = mask.getColor(x, y);
716
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
-
 
717
 
-
 
718
                    if (alpha == 0)
700
                    barrier = setPixel(wpix, color, barrier);
719
                        *wpix = SK_ColorTRANSPARENT;
-
 
720
                    else
-
 
721
                        break;
701
                }
722
                }
702
            }
723
            }
703
        break;
724
        break;
704
 
725
 
705
        case ERASE_OUTSIDE:
726
        case ERASE_OUTSIDE:
706
            for (y = 0; y < height; ++y)
727
            for (y = 0; y < height; ++y)
707
            {
728
            {
708
                SkColor color = 0;
-
 
709
 
-
 
710
                for (x = 0; x < width; ++x)
729
                for (x = 0; x < width; ++x)         // from left
711
                {
730
                {
712
                    SkColor *wpix = bm->getAddr32(x, y);
731
                    SkColor *wpix = bm->getAddr32(x, y);
713
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
732
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
714
 
733
 
715
                    if (alpha == 0)
734
                    if (alpha == 0)
716
                        color = SK_ColorTRANSPARENT;
735
                        *wpix = SK_ColorTRANSPARENT;
717
                    else
736
                    else
718
                        break;
737
                        break;
-
 
738
                }
719
 
739
 
-
 
740
                for (x = width - 1; x >= 0; --x)    // from right
-
 
741
                {
-
 
742
                    SkColor *wpix = bm->getAddr32(x, y);;
-
 
743
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
-
 
744
 
-
 
745
                    if (alpha == 0)
-
 
746
                        *wpix = SK_ColorTRANSPARENT;
-
 
747
                    else
720
                    *wpix = color;
748
                        break;
721
                }
749
                }
722
 
750
 
723
                for (x = width - 1; x >= 0; --x)
751
                for (y = 0; y < height; ++y)        // from top
724
                {
752
                {
725
                    SkColor *wpix = bm->getAddr32(x, y);;
753
                    SkColor *wpix = bm->getAddr32(x, y);;
726
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
754
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
727
 
755
 
728
                    if (alpha == 0)
756
                    if (alpha == 0)
729
                        color = SK_ColorTRANSPARENT;
757
                        *wpix = SK_ColorTRANSPARENT;
730
                    else
758
                    else
731
                        break;
759
                        break;
-
 
760
                }
732
 
761
 
-
 
762
                for (y = height - 1; y >= 0; --y)   // from bottom
-
 
763
                {
-
 
764
                    SkColor *wpix = bm->getAddr32(x, y);;
-
 
765
                    SkColor alpha = SkColorGetA(mask.getColor(x, y));
-
 
766
 
-
 
767
                    if (alpha == 0)
-
 
768
                        *wpix = SK_ColorTRANSPARENT;
-
 
769
                    else
733
                    *wpix = color;
770
                        break;
734
                }
771
                }
735
            }
772
            }
736
        break;
773
        break;
737
 
774
 
738
        default:
775
        default:
739
            return;
776
            return;
740
    }
777
    }
741
}
778
}
742
 
779
 
743
bool TIntBorder::setPixel(uint32_t *wpix, uint32_t col, bool bar)
-
 
744
{
780
/**
745
//    DECL_TRACER("TIntBorder::setPixel(uint32_t *wpix, uint32_t col, bool bar)");
781
 * @brief colorizeFrame - changes the basic color of frame.
746
 
-
 
747
    uint32_t alpha = SkColorGetA(col);
782
 * This method replaces the color of every pixel of the \b frame with \b color.
748
    uint32_t color = col;
-
 
749
    bool barrier = bar;
-
 
750
 
-
 
751
    if (alpha == 0 && !barrier)
-
 
752
        color = SK_ColorTRANSPARENT;
-
 
753
    else if (alpha > 0 && !barrier)
783
 * Only real black pixels are not replaced. The alpha value remains as it is.
754
    {
784
 *
755
        barrier = true;
-
 
756
        int red = SkColorGetR(*wpix);
785
 * @param frame     A pointer to bitmap containing the frame. This must not NULL
757
        int green = SkColorGetG(*wpix);
786
 *                  and it must not be empty.
758
        int blue = SkColorGetB(*wpix);
-
 
759
        color = SkColorSetARGB(alpha, red, green, blue);
787
 * @param color     The color to replace the pixels with.
760
//        color = *wpix;
-
 
761
    }
788
 */
762
    else if (barrier)
-
 
763
        color = *wpix;
-
 
764
 
-
 
765
    *wpix = color;
-
 
766
    return barrier;
-
 
767
}
-
 
768
 
-
 
769
void TIntBorder::colorizeFrame(SkBitmap *frame, SkColor color)
789
void TIntBorder::colorizeFrame(SkBitmap *frame, SkColor color)
770
{
790
{
771
    DECL_TRACER("TIntBorder::colorizeFrame(SkBitmap *frame, SkColor color)");
791
    DECL_TRACER("TIntBorder::colorizeFrame(SkBitmap *frame, SkColor color)");
772
 
792
 
773
    if (!frame || frame->empty())
793
    if (!frame || frame->empty())
Line 800... Line 820...
800
                *wpix = SK_ColorTRANSPARENT;
820
                *wpix = SK_ColorTRANSPARENT;
801
        }
821
        }
802
    }
822
    }
803
}
823
}
804
 
824
 
-
 
825
/**
-
 
826
 * @brief backgroudFrame - Draws a solid underground for a border.
-
 
827
 * The method draw a pixel with color \b color at each point (pixel) where
-
 
828
 * the alpha value of the bitmap containing the border is not 0.
-
 
829
 *
-
 
830
 * @param bm        The bitmap containg the button image without the frame.
-
 
831
 * @param frame     The bitmap containg the frame.
-
 
832
 * @param color     The color to draw for each visible pixel in \b frame.
-
 
833
 */
-
 
834
void TIntBorder::backgroundFrame(SkBitmap* bm, SkBitmap& frame, SkColor color)
-
 
835
{
-
 
836
    DECL_TRACER("TIntBorder::backgroundFrame(SkBitmap* bm, SkBitmap& frame, SkColor color)");
-
 
837
 
-
 
838
    if (!bm || bm->empty() || frame.empty())
-
 
839
        return;
-
 
840
 
-
 
841
    int width = bm->info().width();
-
 
842
    int height = bm->info().height();
-
 
843
 
-
 
844
    if (width != frame.info().width() || height != frame.info().height())
-
 
845
    {
-
 
846
        MSG_WARNING("Size of bitmap and frame is different!");
-
 
847
        return;
-
 
848
    }
-
 
849
 
-
 
850
    for (int y = 0; y < height; ++y)
-
 
851
    {
-
 
852
        for (int x = 0; x < width; ++x)
-
 
853
        {
-
 
854
            SkColor *wpix = bm->getAddr32(x, y);
-
 
855
            SkColor fpix = frame.getColor(x, y);
-
 
856
 
-
 
857
            if (SkColorGetA(fpix) > 0)
-
 
858
                *wpix = color;
-
 
859
        }
-
 
860
    }
-
 
861
}
-
 
862
 
805
SkRect TIntBorder::calcRect(int width, int height, int pen)
863
SkRect TIntBorder::calcRect(int width, int height, int pen)
806
{
864
{
807
    DECL_TRACER("TIntBorder::calcRect(int width, int height, int pen)");
865
    DECL_TRACER("TIntBorder::calcRect(int width, int height, int pen)");
808
    SkRect rect;
866
    SkRect rect;
809
 
867