void Liquid_StaticNoiseOverlay_Impl::update(int overlayIndex, float angle,
	GLImage & image, int offsetX, int offsetY)
{
	//prevent segfault
	if (overlayIndex < 0 || overlayIndex >= masks.size())
	{
		fprintf(stderr, "Liquid_StaticNoiseOverlay_Impl::update: overlayIndex %d out of range\n", overlayIndex);
		return;
	}

	//printf("overlayIndex=%d\tangle=%g\timage=%dx%d\toffsX=%d\toffsY=%d\n", overlayIndex, angle, image.width, image.height, offsetX, offsetY);
	//fflush(stdout);

	GLImage & mask = *masks.items()[overlayIndex];


	//Copy 'image' to a temporary buffer
	//given image holds the background-image and it is also what we will be updating.  This is
	// problematic for the water effect because we need to read the unmodified background image as we
	// are generating the final buffer.  In short, we need to buffers: the background and the output.
	Rect4i imgRect(offsetX, offsetY, offsetX + mask.width, offsetY + mask.height);
	tempBuf.copyRect(image, imgRect);
	//update dimensions to match 'imageRect'
	tempBuf.width = imgRect.width();
	tempBuf.height = imgRect.height();

	//rotate the noise according to angle
	renderer->updateRotationOffsets(angle);

	//Render the water effect from tempBuf into image
	renderer->renderMaskRect(mask, tempBuf, image, imgRect);
}
Ejemplo n.º 2
0
void ClosableImage::mousePressEvent(QMouseEvent *ev)
{
    if (m_loading || ev->button() != Qt::LeftButton || !m_pixmap.isNull())
        return;

    if ((!m_image.isNull() || !m_imagePath.isEmpty()) && closeRect().contains(ev->pos())) {
        if (!confirmDeleteImage())
            return;
        m_pixmap = QPixmap::grabWidget(this);
        Helper::instance()->setDevicePixelRatio(m_pixmap, Helper::instance()->devicePixelRatio(this));
        m_anim = new QPropertyAnimation(this);
        m_anim->setEasingCurve(QEasingCurve::InQuad);
        m_anim->setTargetObject(this);
        m_anim->setStartValue(0);
        m_anim->setEndValue(width()/2);
        m_anim->setPropertyName("mySize");
        m_anim->setDuration(400);
        m_anim->start(QPropertyAnimation::DeleteWhenStopped);
        connect(m_anim, SIGNAL(finished()), this, SIGNAL(sigClose()));
        connect(m_anim, SIGNAL(finished()), this, SLOT(closed()), Qt::QueuedConnection);
    } else if ((!m_image.isNull() || !m_imagePath.isEmpty()) && m_showZoomAndResolution && zoomRect().contains(ev->pos())) {
        if (!m_image.isNull()) {
            ImagePreviewDialog::instance()->setImage(QPixmap::fromImage(QImage::fromData(m_image)));
            ImagePreviewDialog::instance()->exec();
        } else if (!m_imagePath.isEmpty()) {
            ImagePreviewDialog::instance()->setImage(QPixmap::fromImage(QImage(m_imagePath)));
            ImagePreviewDialog::instance()->exec();
        }
    } else if (m_clickable && imgRect().contains(ev->pos())) {
        emit clicked();
    }
}
Ejemplo n.º 3
0
void ClosableImage::mouseMoveEvent(QMouseEvent *ev)
{
    if (!m_loading) {
        if ((!m_image.isNull() || !m_imagePath.isEmpty()) && closeRect().contains(ev->pos())) {
            setCursor(Qt::PointingHandCursor);
            setToolTip(tr("Delete Image"));
            return;
        }

        if ((!m_image.isNull() || !m_imagePath.isEmpty()) && m_showZoomAndResolution && zoomRect().contains(ev->pos())) {
            setCursor(Qt::PointingHandCursor);
            setToolTip(tr("Zoom Image"));
            return;
        }

        if (m_showCapture && captureRect().contains(ev->pos())) {
            setCursor(Qt::PointingHandCursor);
            setToolTip(tr("Capture random screenshot"));
            return;
        }

        if (m_clickable && imgRect().contains(ev->pos())) {
            setCursor(Qt::PointingHandCursor);
            setToolTip(tr("Select another image"));
            return;
        }
    }
    setCursor(Qt::ArrowCursor);
    setToolTip("");
}
Liquid_StaticNoiseOverlay_Impl::Liquid_StaticNoiseOverlay_Impl(GLImage & noise, GLImage & mask, float refactionIndex, float noiseIntensity)
{
	const int BORDER = 1;  //without this border the bluring below would ruin the seamless nature of the image

	HeightMap * noiseMap = imageToHeightMap_tilable(noise, BORDER);

	//images have only 255 steps - make the steps smoother
	noiseMap->blur(2);

	//reduce intensity of water effect
	noiseMap->scaleAll(noiseIntensity);

	renderer = new StaticNoiseLiquidRefactionRenderer(refactionIndex, *noiseMap, BORDER);

	//done with noiseMap
	delete noiseMap;

	//Split the mask into independent rectangles
	ImageMask im(mask);
	im.isolateMaskRegions(rects);

	Rect4i imgRect(0, 0, im.width(), im.height());

	int largestRectArea = 1;

	for (int i = 0; i < rects.size(); i++)
	{
		Rect4i & rect = *rects.items()[i];
		printf("Found rect ");
		rect.debugPrint();

        //UPDATE: this bugfix is now done in Java code
		//bug workaround: For some reason certain widths of rectangles
		//  causes strange gray looking textures after uploading with glTexSubImage2D().
		//  I can avoid the issue by making sure width is an even multiple of 8.  I picked
		//  8 out of the blue and it seems to work even though I don't fully understand the problem.
		//roundMaskRect(rect, imgRect, 8);

		//printf("Rounded to ");
		//rect.debugPrint();

		masks.add(im.copySubrect(rect));

		int area = rect.area();
		if (area > largestRectArea)
			largestRectArea = area;
	}

	fflush(stdout);

	//Allocate a temporary pixel buffer to use in the update() call.
	//It needs to be big enough to hold the largest MaskRect
	tempBuf.allocateBlank(1, largestRectArea, 0);
}
Ejemplo n.º 5
0
QPixmap QtResourceViewPrivate::makeThumbnail(const QPixmap &pix) const
{
    int w = qMax(48, pix.width());
    int h = qMax(48, pix.height());
    QRect imgRect(0, 0, w, h);
    QImage img(w, h, QImage::Format_ARGB32_Premultiplied);
    img.fill(0);
    if (!pix.isNull()) {
        QRect r(0, 0, pix.width(), pix.height());
        r.moveCenter(imgRect.center());
        QPainter p(&img);
        p.drawPixmap(r.topLeft(), pix);
    }
    return QPixmap::fromImage(img);
}
Ejemplo n.º 6
0
void TrackViewDelegate::paintDisk(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const Disk *disk) const
{
    QRect paintRect = option.rect;
    paintRect.setLeft(0);

    if (option.state & QStyle::State_Selected)
        QStyledItemDelegate::paint(painter, option, index);
    else
        painter->fillRect(option.rect, mTrackView->palette().base().color());


    //cache = self.cache(index)
    painter->save();
    painter->setClipRect(option.rect);
    QFont titleFont = this->titleFont(painter);
    QFont filesFont = this->filesFont(painter);


    int topPadding = index.row() ? TOP_PADDING : 0;

    painter->translate(option.rect.topLeft());

    QRect windowRect(MARGIN + MARGIN,
                     MARGIN + topPadding,
                     option.rect.right() - 2 * MARGIN,
                     option.rect.height() - 2 * MARGIN - topPadding - BOTTOM_PADDING);

    // Draw cover image ................................
    if (mNoCoverImg.height() != windowRect.height())
    {
        mNoCoverImg = QImage(":noCover").scaledToHeight(windowRect.height(), Qt::SmoothTransformation);
    }

    QRect imgRect(windowRect.topLeft(), mNoCoverImg.size());
    painter->fillRect(imgRect, mTrackView->palette().base().color());
    painter->fillRect(imgRect, Qt::white);
    painter->drawImage(imgRect, mNoCoverImg);


    // Rectangle for text drawing ......................
    QRect textRect(windowRect);
    textRect.setLeft(imgRect.right() + MARGIN);

    // Draw album & artist .............................
    painter->setFont(titleFont);
    QString album =  index.sibling(index.row(), TrackView::ColumnAlbum).data().toString();
    QString artist = index.sibling(index.row(), TrackView::ColumnArtist).data().toString();
    if (!album.isEmpty() || !artist.isEmpty())
        painter->drawText(textRect, Qt::AlignLeft, QString("%1 / %2").arg(artist, album));

    // Draw audio filename .............................
    painter->setFont(filesFont);
    int th = painter->fontMetrics().height();
    int tTop = windowRect.bottom() - 2 * th - 2;
    int aTop = windowRect.bottom() - th + 1;

    // Draw labels ........
    QRect tLabelRect(textRect.left(), tTop, windowRect.width(), th);
    QRect aLabelRect(textRect.left(), aTop, windowRect.width(), th);

    tLabelRect = drawLabel(tr("Tracks:"), tLabelRect, painter);
    aLabelRect = drawLabel(tr("Audio:"),  aLabelRect, painter);

    // Draw filenames .....
    int l = qMax(tLabelRect.right(), aLabelRect.right()) + 6;
    QRect tFileRect(l, tTop, windowRect.width(), th);
    QRect aFileRect(l, aTop, windowRect.width(), th);

    tFileRect = drawFile(disk->tagsTitle(), tFileRect, painter);
    QFileInfo fi(disk->audioFileName());
    aFileRect = drawFile(fi.fileName(), aFileRect, painter);


    // Draw buttons ......
    l = qMax(tLabelRect.right() + 80, qMax(tFileRect.right(), aFileRect.right()) + 8);

    QRect tBtnRect(0, 0, mTrackBtnPix.height(), mTrackBtnPix.width());
    tBtnRect.moveCenter(tLabelRect.center());
    tBtnRect.moveLeft(l);
    painter->drawPixmap(tBtnRect, mTrackBtnPix);

    QRect aBtnRect(0, 0, mAudioBtnPix.height(), mAudioBtnPix.width());
    aBtnRect.moveCenter(aLabelRect.center());
    aBtnRect.moveLeft(l);
    painter->drawPixmap(aBtnRect, mAudioBtnPix);

    TrackViewCacheItem *cache = mCache->item(index);
    QRect tClickRect = tBtnRect.united(tLabelRect).adjusted(0, -3, 4, 1);
    cache->trackBtn = tClickRect;
    //painter->drawRect(tClickRect);

    QRect aClickRect = aBtnRect.united(aLabelRect).adjusted(0, -3, 4, 1);
    cache->audioBtn = aClickRect;
    //painter->drawRect(aClickRect);

    // Draw bottom line ................................
    painter->setPen(mTrackView->palette().dark().color());
    int y = option.rect.height() - BOTTOM_PADDING - 2;
    painter->drawLine(MARGIN, y, windowRect.right(), y);

    // Draw warning mark ...............................
    QRect markRect(imgRect.right() - MARK_HEIGHT, imgRect.bottom() - MARK_HEIGHT, MARK_HEIGHT, MARK_HEIGHT);
    if (!disk->canConvert())
        painter->drawPixmap(markRect, mWarnPix);

    cache->isWaiting = disk->isDownloads();
    if (cache->isWaiting)
    {
        painter->drawPixmap(markRect, mDownloadMovie.currentPixmap());
    }

    cache->markBtn = markRect;

    painter->restore();    
}
Ejemplo n.º 7
0
//---------------------------------------------------------------------------
// Draw() draws the control into the parent window
// \param dirtyRect - portion of control (in window coordinates)
//        that requires redrawing.
//---------------------------------------------------------------------------
void CATKnob::Draw(CATImage* image, const CATRect& dirtyRect)
{
    if (this->IsVisible() == false)
    {
        return;
    }

    // sanity check parent image / dirty rectangle
    CATRect imgRect(0,0,image->Width(), image->Height());
    CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");

    // Find intersection between dirty rect and us
    CATRect drawRect;
    bool   drawn = false;

    CATInt32 knobNumber = (int)((47 * GetValPercent() ) + 0.5);
    fLastKnob = knobNumber;
    CATInt32 knobCol = knobNumber % 4;
    CATInt32 knobRow = knobNumber / 4;
    CATInt32 knobX = fRect.Width() * knobCol;
    CATInt32 knobY = fRect.Height() * knobRow;


    // Gracefully degrade depending on flags and whether the images are
    // available.
    if (this->fRect.Intersect(dirtyRect, &drawRect))
    {  
        CATRect ourRect;
        if ( (this->IsEnabled() == false) && (this->fImageDisabled))
        {
            if (drawRect.Intersect(CATRect(fRect.left, 
                fRect.top, 
                fRect.left + fImageDisabled->Width()/4,
                fRect.top  + fImageDisabled->Height()/12),
                &ourRect))
            {
                ourRect.Offset(-fRect.left, -fRect.top);

                image->Overlay(   this->fImageDisabled,
                    drawRect.left, 
                    drawRect.top, 
                    ourRect.left + knobX,
                    ourRect.top + knobY,
                    ourRect.Width(),
                    ourRect.Height());
                drawn = true;
            }        
        }
        else 
        {
            if (this->IsPressed() && (this->fImagePressed))
            {
                if (drawRect.Intersect(CATRect(fRect.left, 
                    fRect.top, 
                    fRect.left + fImagePressed->Width()/4,
                    fRect.top  + fImagePressed->Height()/12),
                    &ourRect))
                {
                    ourRect.Offset(-fRect.left, -fRect.top);

                    image->Overlay(   this->fImagePressed,
                        drawRect.left, 
                        drawRect.top, 
                        ourRect.left + knobX,
                        ourRect.top + knobY,
                        ourRect.Width(),
                        ourRect.Height());
                    drawn = true;
                }        
            }

            if ((!drawn) && (IsFocused() || IsPressed()) && (this->fImageFocus))
            {
                if (drawRect.Intersect(CATRect(fRect.left, 
                    fRect.top, 
                    fRect.left + fImageFocus->Width()/4,
                    fRect.top  + fImageFocus->Height()/12),
                    &ourRect))
                {
                    ourRect.Offset(-fRect.left, -fRect.top);

                    image->Overlay(   this->fImageFocus,
                        drawRect.left, 
                        drawRect.top, 
                        ourRect.left + knobX,
                        ourRect.top + knobY,
                        ourRect.Width(),
                        ourRect.Height());
                    drawn = true;
                }        
            }

            if ((!drawn) && (IsActive()) && (this->fImageActive))
            {
                if (drawRect.Intersect(CATRect(fRect.left, 
                    fRect.top, 
                    fRect.left + fImageActive->Width()/4,
                    fRect.top  + fImageActive->Height()/12),
                    &ourRect))
                {
                    ourRect.Offset(-fRect.left, -fRect.top);

                    image->Overlay(   this->fImageActive,
                        drawRect.left, 
                        drawRect.top, 
                        ourRect.left + knobX,
                        ourRect.top + knobY,
                        ourRect.Width(),
                        ourRect.Height());
                    drawn = true;
                }        
            }

        }

        if ((!drawn) && (this->fImage != 0))
        {
            if (drawRect.Intersect(CATRect(fRect.left, 
                fRect.top, 
                fRect.left + fImage->Width()/4,
                fRect.top  + fImage->Height()/12),
                &ourRect))
            {
                ourRect.Offset(-fRect.left, -fRect.top);

                image->Overlay(   this->fImage,
                    drawRect.left, 
                    drawRect.top, 
                    ourRect.left + knobX,
                    ourRect.top + knobY,
                    ourRect.Width(),
                    ourRect.Height());
                drawn = true;
            }        
        }

        if (!drawn)
        {

            // Right now, just make a big red rectangle where we should go.
            image->FillRect(drawRect, fBackgroundColor);
        }
    }
}
//---------------------------------------------------------------------------
// Draw() draws the control into the parent window
// \param dirtyRect - portion of control (in window coordinates)
//        that requires redrawing.
//---------------------------------------------------------------------------
void CATIconSwitch::Draw(CATImage* image, const CATRect& dirtyRect)
{
    if (this->IsVisible() == false)
    {
        return;
    }

    CATSwitch::Draw(image,dirtyRect);
    // sanity check parent image / dirty rectangle
    CATRect imgRect(0,0,image->Width(), image->Height());
    CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");

    // Find intersection between dirty rect and us
    CATRect drawRect;
    bool   drawn = false;

    CATImage* disabled = fIconDisabled;
    CATImage* normal   = fIconImage;

    if (fValue < 0.5)
    {
        if (fIconOffDisabled)
            disabled    = fIconOffDisabled;

        if (fIconOff)
            normal      = fIconOff;
    }

    CATRect innerRect;

    innerRect = fRect;
    if (fIconImage)
    {
        innerRect.left  = fRect.left + (fRect.Width() - fIconImage->Width())/2;
        innerRect.right = innerRect.left + fIconImage->Width();
        innerRect.top   = fRect.top  + (fRect.Height() - fIconImage->Height())/2;
        innerRect.bottom= innerRect.top  + fIconImage->Height();
    }

    if (this->IsPressed() || (this->fValue >= 0.5f))
    {
        CATPOINT iconOff;
        iconOff.x = this->fTextOffsetPressed.x - fTextOffset.x;
        iconOff.y = this->fTextOffsetPressed.y - fTextOffset.y;
        innerRect.Offset(iconOff);
    }

    if (innerRect.Intersect(dirtyRect, &drawRect))
    {  
        CATRect ourRect;
        if ( (this->IsEnabled() == false) && (disabled))
        {
            if (drawRect.Intersect(CATRect(innerRect.left, 
                innerRect.top, 
                innerRect.left + disabled->Width(),
                innerRect.top  + disabled->Height()),
                &ourRect))
            {
                ourRect.Offset(-innerRect.left, -innerRect.top);

                image->Overlay(   disabled,
                    drawRect.left, 
                    drawRect.top, 
                    ourRect.left,
                    ourRect.top,
                    ourRect.Width(),
                    ourRect.Height());
                drawn = true;
            }        
        }

        if ((!drawn) && (normal != 0))
        {
            if (drawRect.Intersect(CATRect(innerRect.left, 
                innerRect.top, 
                innerRect.left + normal->Width(),
                innerRect.top  + normal->Height()),
                &ourRect))
            {
                ourRect.Offset(-innerRect.left, -innerRect.top);

                image->Overlay(   normal,
                    drawRect.left,
                    drawRect.top,
                    ourRect.left,
                    ourRect.top,
                    ourRect.Width(),
                    ourRect.Height());
                drawn = true;
            }
        }
    }
}
Ejemplo n.º 9
0
GLMainContext::GLMainContext(wxGLCanvas *canvas)
    : wxGLContext(canvas)
{
    SetCurrent(*canvas);

    InitGL();
    CheckGLError();

    // Load the grass image and set the color key
    m_pGrassImg = CImage::CreateImage("res/GrassIso.bmp");
    m_pGrassImg->GetTexture()->SetColorKey(0, 128, 128);

    // Load the tree images
    for (int i=0; i<16; i++)
    {
        TRectanglei imgRect(i/4*128,(i/4+1)*128,(i%4)*128,(i%4+1)*128);
        m_pTreesImg[i] = CImage::CreateImage("res/Trees.bmp",imgRect);
    }
    CTextureManager::GetInstance()->GetTexture("res/Trees.bmp")
        ->SetColorKey(191, 123, 199);

    // Load all the 'walk' animations for the knight.
    m_pKnightSprite = new CAnimatedSprite;
    CAnimFileLoader fileLoader1("res/KnightWalk.bmp", 8, 96, 96);
    CTextureManager::GetInstance()->GetTexture("res/KnightWalk.bmp")
        ->SetColorKey(111, 79, 51);
    m_pKnightSprite->AddAnimation("WalkE",
                                  fileLoader1.GetAnimation(0,7));
    m_pKnightSprite->AddAnimation("WalkSE",
                                  fileLoader1.GetAnimation(8,15));
    m_pKnightSprite->AddAnimation("WalkS",
                                  fileLoader1.GetAnimation(16,23));
    m_pKnightSprite->AddAnimation("WalkSW",
                                  fileLoader1.GetAnimation(24,31));
    m_pKnightSprite->AddAnimation("WalkW",
                                  fileLoader1.GetAnimation(32,39));
    m_pKnightSprite->AddAnimation("WalkNW",
                                  fileLoader1.GetAnimation(40,47));
    m_pKnightSprite->AddAnimation("WalkN",
                                  fileLoader1.GetAnimation(48,55));
    m_pKnightSprite->AddAnimation("WalkNE",
                                  fileLoader1.GetAnimation(56,63));

    // Load all the 'pause' animations for the knight.
    CAnimFileLoader fileLoader2("res/KnightPause.bmp", 8, 96, 96);
    CTextureManager::GetInstance()->GetTexture("res/KnightPause.bmp")
        ->SetColorKey(111, 79, 51);
    m_pKnightSprite->AddAnimation("PauseE",
                                  fileLoader2.GetAnimation(0,7));
    m_pKnightSprite->AddAnimation("PauseSE",
                                  fileLoader2.GetAnimation(8,15));
    m_pKnightSprite->AddAnimation("PauseS",
                                  fileLoader2.GetAnimation(16,23));
    m_pKnightSprite->AddAnimation("PauseSW",
                                  fileLoader2.GetAnimation(24,31));
    m_pKnightSprite->AddAnimation("PauseW",
                                  fileLoader2.GetAnimation(32,39));
    m_pKnightSprite->AddAnimation("PauseNW",
                                  fileLoader2.GetAnimation(40,47));
    m_pKnightSprite->AddAnimation("PauseN",
                                  fileLoader2.GetAnimation(48,55));
    m_pKnightSprite->AddAnimation("PauseNE",
                                  fileLoader2.GetAnimation(56,63));
    m_pKnightSprite->PlayAnimation("PauseE");

    /* for (int i = 0; i < 256; ++i) {
        m_KeysDown[i] = false;
    } */
    m_KeysDown[WXK_LEFT] = false;
    m_KeysDown[WXK_RIGHT] = false;
    m_KeysDown[WXK_UP] = false;
    m_KeysDown[WXK_DOWN] = false;

    m_strLastDir = "E";
    m_pKnightSprite->SetPosition(350, 250);
}
Ejemplo n.º 10
0
//---------------------------------------------------------------------------
// Draw() draws the control into the parent window
// \param dirtyRect - portion of control (in window coordinates)
//        that requires redrawing.
//---------------------------------------------------------------------------
void CATSwitch::Draw(CATImage* image, const CATRect& dirtyRect)
{
    if (this->IsVisible() == false)
    {
        return;
    }

    // sanity check parent image / dirty rectangle
    CATRect imgRect(0,0,image->Width(), image->Height());
    CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");

    // Find intersection between dirty rect and us
    CATRect drawRect;
    bool   drawn = false;

    CATImage* disabled = fImageDisabled;
    CATImage* normal   = fImage;
    CATImage* pressed  = fImagePressed;
    CATImage* focus    = fImageFocus;
    CATImage* focusAct = fImageFocusAct;
    CATImage* active   = fImageActive;

    if (fValue > 0.5)
    {
        // All on...
        if (fImageDisabledOn)
            disabled    = fImageDisabledOn;

        if (fImageOn)
            normal      = fImageOn;

        if (fImagePressedOn)
            pressed     = fImagePressedOn;

        if (fImageFocusOn)
            focus       = fImageFocusOn;

        if (fImageFocusActOn)
            focusAct    = fImageFocusActOn;

        if (fImageActiveOn)
            active      = fImageActiveOn;
    }


    // Gracefully degrade depending on flags and whether the images are
    // available.
    if (this->fRect.Intersect(dirtyRect, &drawRect))
    {  
        CATRect ourRect;
        if ( (this->IsEnabled() == false) && (disabled))
        {
            if (drawRect.Intersect(CATRect(fRect.left, 
                fRect.top, 
                fRect.left + disabled->Width(),
                fRect.top  + disabled->Height()),
                &ourRect))
            {
                ourRect.Offset(-fRect.left, -fRect.top);

                image->Overlay(   disabled,
                    drawRect.left, 
                    drawRect.top, 
                    ourRect.left,
                    ourRect.top,
                    ourRect.Width(),
                    ourRect.Height());
                drawn = true;
            }        
        }
        else 
        {
            if (this->IsPressed() && (pressed))
            {
                if (drawRect.Intersect(CATRect(fRect.left, 
                                               fRect.top, 
                                               fRect.left + pressed->Width(),
                                               fRect.top  + pressed->Height()),
                                       &ourRect))
                {
                    ourRect.Offset(-fRect.left, -fRect.top);

                    image->Overlay( pressed,
                                    drawRect.left,
                                    drawRect.top,
                                    ourRect.left,
                                    ourRect.top,
                                    ourRect.Width(),
                                    ourRect.Height());
                    drawn = true;
                }
            }

            if ((!drawn) && ( (IsFocused() && IsActive()) || IsPressed()) && (focusAct))
            {
                if (drawRect.Intersect(CATRect( fRect.left, 
                                                fRect.top, 
                                                fRect.left + focusAct->Width(),
                                                fRect.top  + focusAct->Height()),
                                       &ourRect))
                {
                    ourRect.Offset(-fRect.left, -fRect.top);

                    image->Overlay( focusAct,
                                    drawRect.left,
                                    drawRect.top,
                                    ourRect.left,
                                    ourRect.top,
                                    ourRect.Width(),
                                    ourRect.Height());
                    drawn = true;
                }
            }

            if ((!drawn) && (IsFocused() || IsPressed()) && (focus))
            {
                if (drawRect.Intersect(CATRect( fRect.left, 
                                                fRect.top, 
                                                fRect.left + focus->Width(),
                                                fRect.top  + focus->Height()),
                                       &ourRect))
                {
                    ourRect.Offset(-fRect.left, -fRect.top);

                    image->Overlay( focus,
                                    drawRect.left,
                                    drawRect.top,
                                    ourRect.left,
                                    ourRect.top,
                                    ourRect.Width(),
                                    ourRect.Height());
                    drawn = true;
                }
            }

            if ((!drawn) && (IsActive()) && (active))
            {
                if (drawRect.Intersect(CATRect( fRect.left, 
                                                fRect.top, 
                                                fRect.left + active->Width(),
                                                fRect.top  + active->Height()),
                                       &ourRect))
                {
                    ourRect.Offset(-fRect.left, -fRect.top);

                    image->Overlay( active,
                                    drawRect.left,
                                    drawRect.top,
                                    ourRect.left,
                                    ourRect.top,
                                    ourRect.Width(),
                                    ourRect.Height());
                    drawn = true;
                }
            }
        }

        if ((!drawn) && (normal != 0))
        {
            if (drawRect.Intersect(CATRect(fRect.left, 
                fRect.top, 
                fRect.left + normal->Width(),
                fRect.top  + normal->Height()),
                &ourRect))
            {
                ourRect.Offset(-fRect.left, -fRect.top);

                image->Overlay(   normal,
                    drawRect.left,
                    drawRect.top,
                    ourRect.left,
                    ourRect.top,
                    ourRect.Width(),
                    ourRect.Height());
                drawn = true;
            }
        }

        if (!drawn)
        {

            // Right now, just make a big red rectangle where we should go.
            image->FillRect(drawRect, fBackgroundColor);
        }
    }
}
Ejemplo n.º 11
0
void CCardLabel::paintEvent(QPaintEvent *ev)
{
    QRectF titleRect(translatePoint(5, 2), translatePoint(155, 25));
    QRectF imgRect(translatePoint(5, 24), translatePoint(155, 144));
    QRectF blackRect(translatePoint(6, 24 + 40), translatePoint(156, 24 + 80));
    QRectF setRect(translatePoint(155 - 2 - 32, 144 + 8), translatePoint(155 - 2, 144 + 8 + 32));
    QRectF delayRect(translatePoint(155 - 40, 24), translatePoint(155,  24 + 40));
    QRectF attackRect(translatePoint(5 + 2, 215 - 20), translatePoint(5 + 2 + 20, 215));
    QRectF healthRect(translatePoint(155 - 2 - 20, 215 - 20), translatePoint(155 - 2, 215));
    QRectF ownedRect(translatePoint(155 - 60 - 2, 144 - 28), translatePoint(155 - 2, 144));
    QPointF upgradePos(translatePoint(50, 193));
    QPointF uniquePos(translatePoint(5 + 2, 144 - 28 - 2));
    QPointF skillPos(translatePoint(5 + 2, 144 + 8));

    // Update lock button geo before parent paint
    if (mLockButton)
    {
        mLockButton->setGeometry(QRect(imgRect.x() + 2, imgRect.y() + 2, 24, 24));
    }

    // Regular label painting (background image)
    QLabel::paintEvent(ev);

    if (mCard.isValid())
    {
        const CGlobalConfig &cfg = CGlobalConfig::getCfg();
        QPainter painter(this);

        // Paint upgrade symbol
        QString cardName = mCard.getName();
        if (mCard.getUpgradeLevel() != EUpgradeNotAvailable)
        {
            if (cardName.endsWith(QChar('*')))
            {
                cardName.replace("*", "");
            }
            switch(mCard.getUpgradeLevel())
            {
            case EUpgradeLevel1:
                painter.drawPixmap(upgradePos, QPixmap(cfg.getResourcePicturePath() + "UpgradeIcon1.png"));
                break;
            case EUpgradeLevel2:
                painter.drawPixmap(upgradePos, QPixmap(cfg.getResourcePicturePath() + "UpgradeIcon2.png"));
                break;
            default:
                break;
            }
        }

        // Paint title
        QPen inPen(Qt::white);
        painter.setPen(inPen);
        painter.drawText(titleRect.adjusted(titleRect.height() + 2, -1, 0, -1), Qt::AlignLeft | Qt::AlignVCenter, cardName);
        painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
        if (!mTitleIcon.isNull())
        {
            painter.drawPixmap(titleRect.topLeft(), mTitleIcon.scaled(titleRect.height() + 1, titleRect.height() + 1, Qt::KeepAspectRatio, Qt::SmoothTransformation));
        }

        // Paint unique symbol
        if (mCard.isUnique())
        {
            painter.drawPixmap(uniquePos, QPixmap(":/img/unique.png"));
            //painter.drawText(dx + 2, dySkill - 15, 100, 12, Qt::AlignLeft | Qt::AlignVCenter, "Unique");
        }

        // Paint skill symbols
        const TSkillList &skills = mCard.getSkills();
        int curIdx = 0;
        for (TSkillList::const_iterator i = skills.begin(); i != skills.end(); ++i, ++curIdx)
        {
            const CSkill& curSkill = mCards.getSkillForId(i->getId());
            if (curSkill.isValid())
            {
                QPixmap skillPixmap;
                if (!skillPixmap.load(cfg.getResourcePicturePath() + curSkill.getPicture() + ".png"))
                {
                    skillPixmap.load(cfg.getCustomPicturePath() + curSkill.getPicture() + ".png");
                }
                painter.drawPixmap(skillPos, skillPixmap);
                skillPos += QPointF(16 + 2, 0);
                //painter.drawText(dx, 80 + i*10, 100, 10, Qt::AlignLeft | Qt::AlignVCenter, curSkill.makeSignature(skills.at(i)));
            }
        }

        // Paint set symbol
        if (mCard.getSet() != EUnknownSet)
        {
            QPixmap setPixmap;
            if (!setPixmap.load(cfg.getResourcePicturePath() + mCards.getPictureForCardSet(mCard.getSet())))
            {
                setPixmap.load(cfg.getCustomPicturePath() + mCards.getPictureForCardSet(mCard.getSet()));
            }
            painter.drawPixmap(setRect, setPixmap, QRectF(0, 0, 24, 24));
        }


        // Paint delay symbol
        if (mCard.getDelay() > -1)
        {
            painter.drawPixmap(delayRect, QPixmap(cfg.getResourcePicturePath() + "ClockIcon.png"), QRectF(0, 0, 32, 32));
            painter.drawText(delayRect, Qt::AlignCenter, QString("%1").arg(mCard.getDelay()));
        }

        // Paint attack symbol
        if (mCard.hasAttack())
        {
            painter.drawPixmap(attackRect, QPixmap(cfg.getResourcePicturePath() + "AttackIcon.png"), QRectF(0, 0, 20, 20));
            painter.drawText(attackRect.translated(attackRect.width() + 1, 0), Qt::AlignLeft | Qt::AlignVCenter, QString("%1").arg(mCard.getAttack()));
        }

        // Paint health symbol
        if (mCard.hasHealth())
        {
            painter.drawPixmap(healthRect, QPixmap(cfg.getResourcePicturePath() + "HealthIcon.png"), QRectF(0, 0, 20, 20));

            painter.drawText(healthRect.adjusted(-2 * healthRect.width() - 1, 0, -healthRect.width() - 1, 0), Qt::AlignRight | Qt::AlignVCenter, QString("%1").arg(mCard.getHealth()));
        }

        if (!mIsVirtual)
        {
            // Display owned status
            SCardStatus status = mCards.getCardStatus(mCard);
            {
                painter.setPen(Qt::green);
                QString ownageStr("x0");
                if (status.numOwned > 0)
                {
                    ownageStr = QString("x%1").arg(status.numOwned);
                }
                painter.drawText(ownedRect, Qt::AlignRight | Qt::AlignVCenter, ownageStr);
            }
            if (cfg.isCardShadingEnabled() && status.numOwned <= 0)
            {
                painter.setPen(Qt::NoPen);
                painter.setBrush(Qt::black);
                painter.setOpacity(0.6);
                painter.drawRoundedRect(rect(), 2.0, 2.0);
            }
            if (cfg.isBlackLabellingEnabled() && status.isBlack)
            {
                // Display black list status
                painter.setPen(Qt::white);
                painter.setOpacity(0.6);
                painter.fillRect(blackRect, QBrush(Qt::black));
                painter.setOpacity(1.0);
                painter.drawText(blackRect, Qt::AlignCenter, "Blacklisted");
            }
            else if (cfg.isWhiteLabellingEnabled() && status.isWhite)
            {
                // Display white list status
                painter.setPen(Qt::black);
                painter.setOpacity(0.6);
                painter.fillRect(blackRect, QBrush(Qt::white));
                painter.setOpacity(1.0);
                painter.drawText(blackRect, Qt::AlignCenter, "Whitelisted");
            }
        }
    }
}
Ejemplo n.º 12
0
//@mFunc draws the listbox items in their proper state
void CQSLItemList::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

	QSLItemData itemData;
	GetItemData( lpDrawItemStruct->itemID, itemData );
	
#ifdef USECACHE
	RImage* pImage = GetCachedBitmap( lpDrawItemStruct->itemID ) ;
#else
	RImage* pImage = itemData.GetImage();

	if (!itemData.m_pImage)
	{
		itemData.m_pImage = pImage;
		SetItemData( lpDrawItemStruct->itemID, itemData );
	}

//	HBITMAP hBitmap = itemData.m_hBitmap ;
//	HPALETTE hPalette = itemData.m_hPalette ;
	
//	if (!itemData.m_pImage)
//	{
//		hBitmap = itemData.m_hBitmap = 
//			LoadBitmapPreview( lpDrawItemStruct->itemID, &itemData.m_hPalette ) ;
//		hPalette = itemData.m_hPalette;
//
//		// Save the new data into the control
//		SetItemData( lpDrawItemStruct->itemID, itemData );
//	}
//
//	// If we have a palette with the bitmap, realize it into the DC prior to painting.
//	if (hPalette != NULL)
//	{
//		CPalette palBitmap;
//		palBitmap.Attach( hPalette );
//		CPalette *pOldPal = pDC->SelectPalette( &palBitmap, TRUE );
//		pDC->RealizePalette();
//		pDC->SelectPalette( pOldPal, TRUE );
//		palBitmap.Detach();
//	}
#endif

	BITMAP  bm= { 0, 0, 0, 0, 0, 0, NULL };
	HBITMAP hBitmap = NULL;
	
	if (pImage)
	{
		hBitmap = (HBITMAP) pImage->GetSystemHandle();
		::GetObject( hBitmap, sizeof( bm ), &bm );
	}

	// Determine colors to use for drawing text and selection
	//
	COLORREF crFillColor = GetSysColor( COLOR_WINDOW ) ;
	COLORREF crTextColor = GetSysColor( COLOR_WINDOWTEXT ) ;

	if (lpDrawItemStruct->itemState & ODS_SELECTED)
	{
		crFillColor = GetSysColor( COLOR_HIGHLIGHT ) ;
		crTextColor = GetSysColor( COLOR_HIGHLIGHTTEXT ) ;
	}

	// Handle drawing according to action
	//

	// Setup DC
	COLORREF oldTextColor = pDC->SetTextColor( crTextColor );
	COLORREF oldBkColor   = pDC->SetBkColor( crFillColor );
	CFont* pOldFont = pDC->SelectObject( GetParent()->GetFont() );

	// Determine location to draw bitmap.  This information 
	// is needed for all drawing modes, so might as well
	// just determine it once, and in one place.
	CSize	  szExtent = pDC->GetTextExtent( itemData.m_strDesc );

	RIntRect  cellRect( lpDrawItemStruct->rcItem );
	cellRect.Inset( RIntSize( 4, 4 ) );
	cellRect.m_Bottom -= szExtent.cy + 2; // + 2 is for spacing between graphic & text

	RIntRect  imgRect( 0, 0, bm.bmWidth - 1, bm.bmHeight - 1 );
	imgRect.ShrinkToFit( cellRect );
	imgRect.CenterRectInRect( cellRect );

	CSize  szImage( imgRect.Width(), imgRect.Height() );
//	CPoint centerPt( cellRect.CenterPoint() );
//	CPoint ptTopLeft( centerPt.x - szImage.cx / 2, centerPt.y - szImage.cy / 2 - 2 );

	switch (lpDrawItemStruct->itemAction)
	{
	case ODA_DRAWENTIRE:
		{
		CDC memDC;
		memDC.CreateCompatibleDC( pDC );

		// Get the bitmap
		CBitmap* pBmp    = CBitmap::FromHandle( hBitmap );
		CBitmap* pOldBmp = memDC.SelectObject( pBmp );

		pDC->StretchBlt( imgRect.m_Left, imgRect.m_Top, imgRect.Width(), imgRect.Height(), 
			&memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY );

		memDC.SelectObject( pOldBmp );

		if (!(lpDrawItemStruct->itemState & ODS_SELECTED))
		{
			break ;
		}

		// Fall through
		}

	case ODA_SELECT:
		{
		// Draw/Clear the highlight rect
//		CRect bmpRect( ptTopLeft.x, ptTopLeft.y, ptTopLeft.x + bm.bmWidth, ptTopLeft.y + bm.bmHeight);
		
		CRect bmpRect( imgRect );
		bmpRect.InflateRect( 2, 2 );

		CPen pen( PS_SOLID, 2, crFillColor );
		CPen* pOldPen = pDC->SelectObject( &pen );

		pDC->MoveTo( bmpRect.left, bmpRect.top );
		pDC->LineTo( bmpRect.right, bmpRect.top );
		pDC->LineTo( bmpRect.right, bmpRect.bottom );
		pDC->LineTo( bmpRect.left, bmpRect.bottom );
		pDC->LineTo( bmpRect.left, bmpRect.top );
		pDC->SelectObject( pOldPen );
		}

	} // switch

	// Draw the text
	CPoint ptText( cellRect.m_Left + (cellRect.Width() - szExtent.cx) / 2, cellRect.m_Bottom + 4 );
	pDC->TextOut( ptText.x, ptText.y, itemData.m_strDesc );

//	pDC->DrawText( itemData.m_strDesc, &textRect, DT_CALCRECT | DT_SINGLELINE  );
//	textRect.OffsetRect( -textRect.Width() / 2, 2 );
//	pDC->DrawText( itemData.m_strDesc, &textRect, DT_CENTER | DT_VCENTER );

	// restore DC
	pDC->SelectObject( pOldFont );
	pDC->SetTextColor( oldTextColor );
	pDC->SetBkColor( oldBkColor );
}