paletteentry palettecolors[256];
ppal->getpaletteentries(0, ntotalcolors, palettecolors);
bool bredzero=false;
bool bgreenzero=false;
bool bbluezero=false;
for (int i=0; i
{
if (palettecolors[i].pered + ndeta <
palettecolors0[i].pered)
{
palettecolors[i].pered += ndeta;
bredzero = false;
}
else if (palettecolors[i].pered + 1 <
palettecolors0[i].pered)
{
palettecolors[i].pered++;
bredzero = false;
}
else
bredzero = true;
if (palettecolors[i].pegreen + ndeta <
palettecolors0[i].pegreen)
{
palettecolors[i].pegreen += ndeta;
bgreenzero = false;
}
else if (palettecolors[i].pegreen + 1 <
palettecolors0[i].pegreen)
{
palettecolors[i].pegreen++;
bgreenzero = false;
}
else
bgreenzero = true;
if (palettecolors[i].peblue + ndeta <
palettecolors0[i].peblue)
{
palettecolors[i].peblue += ndeta;
bbluezero = false;
}
else if (palettecolors[i].peblue +1 <
palettecolors0[i].peblue)
{
palettecolors[i].peblue++;
bbluezero = false;
}
else
bbluezero = true;
}
// 直到恢復(fù)原始值結(jié)束
bdone = bredzero & bgreenzero && bbluezero;
// 使系統(tǒng)改變調(diào)色板
ppal->animatepalette(0, ntotalcolors, palettecolors);
}
::translatemessage(msg);
::dispatchmessage(msg);
}
}
::releasecapture();
pwnd->killtimer(0x100);
// 恢復(fù)原始調(diào)色板
ppal->setpaletteentries(0, ntotalcolors, palettecolors0);
ppal->animatepalette(0, ntotalcolors, palettecolors0);
}
四、漸隱
漸隱就是將顯示顏色由圖象各象素的顏色逐漸變化為黑色(rgb(0, 0, 0))的過程,即定時調(diào)用cpalette::animatepalette,每次將各邏輯表項的pered、pegreen、peblue值減小一個變化量,直到它們都為0?! ?
下面的函數(shù)fadeout通過對調(diào)色板顏色表項中的各顏色分量值進(jìn)行遞減,直到所有顏色值都變成0(即黑色)來實現(xiàn)漸隱。
// 圖象漸隱效果
// 參數(shù):
// pwnd – 顯示圖象的窗口
// ppal – 調(diào)色板指針
// ndeta – 各顏色分量的減小量
// utimeout – 時間的變化量
void fadeout(cwnd *pwnd, cpalette *ppal, int ndeta, uint utimeout)
{
// 保留原來的調(diào)色板顏色表項
int ntotalcolors = ppal->getentrycount();
paletteentry palettecolors0[256];
ppal->getpaletteentries(0, ntotalcolors, palettecolors0);
// 設(shè)置時間碼
pwnd->settimer(0x100, utimeout, null);
// 開始漸隱
pwnd->setcapture();
bool bdone = false;
msg msg;
while (! bdone)
{
if (::peekmessage(msg, null, 0, 0, pm_remove))
{
if (msg.message == wm_timer && msg.wparam == 0x100)
{
cclientdc dc(pwnd);
cpalette *poldpal = dc.selectpalette(ppal, false);
dc.realizepalette();
paletteentry palettecolors[256];
ppal->getpaletteentries(0, ntotalcolors, palettecolors);
bool bredzero=false;
bool bgreenzero=false;
bool bbluezero=false;
// 遞減顏色分量
for (int i=0; i
{
if (palettecolors[i].pered > ndeta)
{
palettecolors[i].pered -= ndeta;
bredzero = false;
}
else if (palettecolors[i].pered > 1)
{
palettecolors[i].pered--;
bredzero = false;
}
else
bredzero = true;
if (palettecolors[i].pegreen > ndeta)
{
palettecolors[i].pegreen -= ndeta;
bgreenzero = false;
}
else if (palettecolors[i].pegreen > 1)
{
palettecolors[i].pegreen--;
bgreenzero = false;
}
else
bgreenzero = true;
if (palettecolors[i].peblue > ndeta)
{
palettecolors[i].peblue -= ndeta;
bbluezero = false;
}
else if (palettecolors[i].peblue > 1)
{
palettecolors[i].peblue--;
bbluezero = false;
}
else
bbluezero = true;
}
// 如所有顏色分量都為0,則結(jié)束漸隱
bdone = bredzero & bgreenzero && bbluezero;
// 使系統(tǒng)改變調(diào)色板
ppal->animatepalette(0, ntotalcolors, palettecolors);
}
::translatemessage(msg);
::dispatchmessage(msg);
}
}
::releasecapture();
pwnd->killtimer(0x100);
// 恢復(fù)原始調(diào)色板
ppal->setpaletteentries(0, ntotalcolors, palettecolors0);
ppal->animatepalette(0, ntotalcolors, palettecolors0);
}