示例#1
0
int CschedulerDlg::resize(int cx, int cy)
{
	CRect gtop;
	CRect gbot;
	CRect wndrect(0,0,cx,cy);

	setSpaces(5,5,5,5,0,0);
	//gtop=wndrect;
	//gtop.bottom=gtop.top + KR_SCALE(25);
	gtop=grid((CWnd*)&m_sGroupT,KR_LEFT,KR_TOP,0,KR_SCALE(22),wndrect);
	wndrect.top=gtop.bottom;

	gbot=grid((CWnd*)&m_sGroup2,KR_LEFT,KR_BOT,0,0,wndrect);

	setSpaces(5,5,KR_SCALE(7),KR_SCALE(3),2,2);
	grid((CWnd*)&m_nowChk,0,1,0,1,12,1,gtop);
	grid((CWnd*)&m_now,1,2,0,1,12,1,gtop);
	grid((CWnd*)&m_sRemain,3,1,0,1,12,1,gtop);
	grid((CWnd*)& m_hours,4,2,0,1,12,1,gtop);
	grid((CWnd*)& m_sSub,6,1,0,1,12,1,gtop);
	grid((CWnd*)& m_sub,7,2,0,1,12,1,gtop);
	grid((CWnd*)& m_sNote,9,1,0,1,12,1,gtop);
	grid((CWnd*)& m_note,10,2,0,1,12,1,gtop);
	//grid((CWnd*)&,,,,,,,gtop);
	CRect gbtn;
	setSpaces(0,2,0,2,2,2);
	gbtn.SetRect(0,0,KR_SCALE(120),KR_SCALE(15));
	gbtn=grid(0,KR_RIGHT,KR_BOT,gbtn,gbot);
	grid((CWnd*)&m_addBtn,0,1,0,1,3,1,gbtn);
	grid((CWnd*)&m_editBtn,1,1,0,1,3,1,gbtn);
	grid((CWnd*)&m_delBtn,2,1,0,1,3,1,gbtn);
	//
	setSpaces(5,5,12,5,0,0);
	gbot.DeflateRect(0,0,0,gbtn.Height());
	grid((CWnd*)&m_list,0,1,0,1,1,1,gbot);

	return 0;
}
void uie_albumart::paint(HDC hdc)
{
    RECT wndrect_temp;
    if(GetClientRect(m_hWnd,&wndrect_temp))
    {
        Graphics gfx(hdc);
        Rect wndrect(
            wndrect_temp.left,
            wndrect_temp.top,
            wndrect_temp.right-wndrect_temp.left,
            wndrect_temp.bottom-wndrect_temp.top
            );

        Color bg;
        bg.SetFromCOLORREF((m_config.bg_enabled)
                           ?m_config.bgcol
                           :GetSysColor(COLOR_3DFACE));

        bool noimage = m_bufnew.is_empty();
        bool image_changed = !m_image_file_exists || m_bmpnew.is_valid();
        bool size_changed = m_bufnew.is_valid()
            ? (m_bufnew->GetWidth() != wndrect.Width || m_bufnew->GetHeight() != wndrect.Height)
            : true;
        if (noimage || image_changed || size_changed || m_config_changed || m_dragging)
        {
            if (!m_dragging)
            {
                m_pan_dx = m_pan_dy = 0;
            }
            else
            {
                m_bmpnew = m_bmp;
            }

            if (size_changed || noimage)
            {
                // create bitmaps with new size
                m_animating = false;
                m_bufold.release();
                m_bufanim.release();

                m_bufold = new Bitmap(wndrect.Width,wndrect.Height,&gfx);
                m_bufnew = new Bitmap(wndrect.Width,wndrect.Height,&gfx);

                // make sure currently displayed image is redrawn
                // during the resize
                m_bmpnew = m_bmp;
            }
            if (m_config.animtime == 0)
                m_bufanim.release();
            else if (m_bufanim.is_empty())
                m_bufanim=new Bitmap(wndrect.Width,wndrect.Height,&gfx);

            m_config_changed = false;

            Bitmap *temp = m_bufold.detach();
            m_bufold.set(m_bufnew.detach());
            m_bufnew.set(temp);

            Graphics bufgfx(m_bufnew.get_ptr());
            bufgfx.Clear(bg);

            if (m_bmpnew.is_valid())
            {
                // adjust for padding
                if(m_config.padding > 0)
                {
                    wndrect.Height-=2*m_config.padding;
                    wndrect.Width-=2*m_config.padding;
                    wndrect.X+=m_config.padding;
                    wndrect.Y+=m_config.padding;
                }

                Size bmp_dim(m_bmpnew->GetWidth(), m_bmpnew->GetHeight());

                // rectangle that will be drawn on the screen
                RectF rect(wndrect.X, wndrect.Y, bmp_dim.Width, bmp_dim.Height);

                // shrink album art
                if (m_config.shrinkalbum)
                {
                    if (bmp_dim.Width > wndrect.Width)
                        rect.Width = wndrect.Width;

                    if (bmp_dim.Height > wndrect.Height)
                        rect.Height = wndrect.Height;
                }

                // expand album art
                if (m_config.expandalbum)
                {
                    if (bmp_dim.Width < wndrect.Width)
                        rect.Width = wndrect.Width;

                    if (bmp_dim.Height < wndrect.Height)
                        rect.Height = wndrect.Height;
                }

                // correct aspect ratio
                if (m_config.aspectratio)
                {
                    REAL new_width = bmp_dim.Width*(rect.Height/bmp_dim.Height);
                    REAL new_height = bmp_dim.Height*(rect.Width/bmp_dim.Width);

                    if (m_config.expandalbum && !m_config.shrinkalbum)
                    {
                        // try to fill the entire window, even if parts of the
                        // image are cut off (enlarge image)
                        if (new_height >= wndrect.Height)
                        {
                            rect.Height = new_height;
                        }
                        else
                        {
                            if (new_width >= wndrect.Width)
                            {
                                rect.Width = new_width;
                            }
                        }
                    }
                    else
                    {
                        // do not cut off any part of the image while
                        // maintaining aspect ratio (shrink image)
                        if (new_height <= wndrect.Height)
                        {
                            rect.Height = new_height;
                        }
                        else
                        {
                            if (new_width <= wndrect.Width)
                            {
                                rect.Width = new_width;
                            }
                        }
                    }
                }

                // Center album
                // uses integers for the offsets because if the offset
                // is a fraction of a pixel, there's lowered quality
                if (m_config.centeralbum)
                {
                    int center_dx = (wndrect.GetRight() - rect.GetRight()) / 2;
                    int center_dy = (wndrect.GetBottom() - rect.GetBottom()) / 2;
                    rect.Offset((REAL)center_dx,
                                (REAL)center_dy);
                }

                if (m_config.draw_pixel_border)
                {
                    Gdiplus::Color border;
                    border.SetFromCOLORREF(m_config.bordercol);

                    rect.Width--;
                    rect.Height--;
                    bufgfx.DrawRectangle(& Pen(border),rect);
                    rect.X++;
                    rect.Y++;
                    rect.Width--;
                    rect.Height--;
                }

                m_panning_enabled = ((rect.Width > wndrect.Width) ||
                                     (rect.Height > wndrect.Height));

                // panning
                REAL dx = m_pan_dx;
                REAL dy = m_pan_dy;
                if (m_dragging)
                {
                    // Make sure the image doesn't pan out of bounds
                    if (m_panning_enabled)
                    {
                        if (rect.Width > wndrect.Width)
                        {
                            if ((rect.GetLeft()+dx) > wndrect.GetLeft())
                                dx = wndrect.GetLeft() - rect.GetLeft();
                            if ((rect.GetRight()+dx) < wndrect.GetRight())
                                dx = wndrect.GetRight() - rect.GetRight();
                        }

                        if (rect.Height > wndrect.Height)
                        {
                            if ((rect.GetTop()+dy) > wndrect.GetTop())
                                dy = wndrect.GetTop() - rect.GetTop();
                            if ((rect.GetBottom()+dy) < wndrect.GetBottom())
                                dy = wndrect.GetBottom() - rect.GetBottom();
                        }
                    }
                    else
                    {
                        dx = 0;
                        dy = 0;
                    }

                    if (rect.Width <= wndrect.Width) dx = 0;
                    if (rect.Height <= wndrect.Height) dy = 0;

                    m_pan_dx = dx;
                    m_pan_dy = dy;
                }
                rect.Offset(dx,dy);

                bufgfx.SetInterpolationMode(m_config.interpolationmode == RESIZE_HIGH
                    ? InterpolationModeHighQuality
                    : m_config.interpolationmode == RESIZE_MEDIUM
                        ? InterpolationModeDefault
                        : m_config.interpolationmode == RESIZE_LOW
                            ? InterpolationModeLowQuality
                            // m_config.interpolationmode == RESIZE_HIGHEST
                            : InterpolationModeHighQualityBicubic);

                if (m_dragging) bufgfx.SetInterpolationMode(InterpolationModeLowQuality);

                REAL srcWidth = m_bmpnew->GetWidth();
                REAL srcHeight = m_bmpnew->GetHeight();
                REAL srcX = 0;
                REAL srcY = 0;

                /*if (m_config.padding < 0)
                {
                    if(abs(m_config.padding) < m_bmpnew->GetWidth() &&
                       abs(m_config.padding) < m_bmpnew->GetHeight())
                    {
                        srcWidth+=2*m_config.padding;
                        srcHeight+=2*m_config.padding;
                        srcX-=m_config.padding;
                        srcY-=m_config.padding;
                    }
                }*/

                bufgfx.SetClip(wndrect);    // ensures that padding is respected
                bufgfx.DrawImage(
                    &(*m_bmpnew),
                    rect,         // destination rectangle
                    srcX, srcY,   // upper-left corner of source rectangle
                    srcWidth,     // width of source rectangle
                    srcHeight,    // height of source rectangle
                    UnitPixel);
            }

            // m_bufnew updated. time to fade in the changes.
            DWORD now = GetTickCount();
            if (m_config.animtime != 0 && !size_changed && (m_animshouldstart+700) > now)
            {
                m_animating = true;
                m_animstarted=GetTickCount();
                set_anim_timer();
            }
        }



        Rect dest(wndrect_temp.left,
            wndrect_temp.top,
            wndrect_temp.right-wndrect_temp.left,
            wndrect_temp.bottom-wndrect_temp.top);
        if (m_bufnew.is_valid() && !m_animating)
        {
            gfx.DrawImage(m_bufnew.get_ptr(), 0, 0);
        }
        else if (m_animating && m_bufnew.is_valid() && m_bufanim.is_valid())
        {
            float opacityold=0.0f;
            float opacitynew=1.0f;
            int doneness=GetTickCount();
            if (doneness > (m_animstarted+m_config.animtime))
            // animation complete
            {
                m_animating=false;
                opacityold=0.0f;
                opacitynew=1.0f;
            }
            else if (doneness >= m_animstarted && m_config.animtime != 0)
            {
                opacitynew=(float)(doneness-m_animstarted)/(float)m_config.animtime;
                opacityold=1.0f-0.0f;
            }
            {
                Graphics animbuf(m_bufanim.get_ptr());
                animbuf.Clear(bg);
                ColorMatrix cm;
                ZeroMemory(&cm,sizeof(ColorMatrix));
                cm.m[0][0] = 1.0f;
                cm.m[1][1] = 1.0f;
                cm.m[2][2] = 1.0f;
                cm.m[3][3] = opacityold;

                ImageAttributes ia;
                ia.SetColorMatrix(&cm);
                animbuf.DrawImage(m_bufold.get_ptr(),dest,0,0,dest.Width,dest.Height,UnitPixel,&ia);
                cm.m[3][3] = opacitynew;
                ia.SetColorMatrix(&cm);
                animbuf.DrawImage(m_bufnew.get_ptr(),dest,0,0,dest.Width,dest.Height,UnitPixel,&ia);
            }
            gfx.DrawImage(m_bufanim.get_ptr(), 0, 0);
            if (m_animating)
                set_anim_timer();
            else
                m_bufanim.release();
        }
        else gfx.Clear(bg);

        m_bmpnew.release();
    }
}