// 递增各颜色分量
paletteentry palettecolors[256];
ppal->getpaletteentries(0, ntotalcolors, palettecolors);
bool bredzero=false;
bool bgreenzero=false;
bool bbluezero=false;
for (int i=0; i<ntotalcolors; ++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;
}
// 直到恢复原始值结束
bdone = bredzero && bgreenzero && bbluezero;
// 使系统改变调色板
ppal->animatepalette(0, ntotalcolors, palettecolors);
}
::translatemessage(&msg);
::dispatchmessage(&msg);
}
}
::releasecapture();
pwnd->killtimer(0x100);
// 恢复原始调色板
ppal->setpaletteentries(0, ntotalcolors, palettecolors0);
ppal->animatepalette(0, ntotalcolors, palettecolors0);
}
四、渐隐
渐隐就是将显示颜色由图象各象素的颜色逐渐变化为黑色(rgb(0, 0, 0))的过程,即定时调用cpalette::animatepalette,每次将各逻辑表项的pered、pegreen、peblue值减小一个变化量,直到它们都为0。
下面的函数fadeout通过对调色板颜色表项中的各颜色分量值进行递减,直到所有颜色值都变成0(即黑色)来实现渐隐。
// 图象渐隐效果
// 参数:
// pwnd – 显示图象的窗口
// ppal – 调色板指针
// ndeta – 各颜色分量的减小量
// utimeout – 时间的变化量
void fadeout(cwnd *pwnd, cpalette *ppal, int ndeta, uint utimeout)
{
// 保留原来的调色板颜色表项
int ntotalcolors = ppal->getentrycount();
paletteentry palettecolors0[256];
ppal->getpaletteentries(0, ntotalcolors, palettecolors0);
// 设置时间码
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<ntotalcolors; ++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,则结束渐隐
bdone = bredzero && bgreenzero && bbluezero;
// 使系统改变调色板
ppal->animatepalette(0, ntotalcolors, palettecolors);
}
::translatemessage(&msg);
::dispatchmessage(&msg);
}
}
::releasecapture();
pwnd->killtimer(0x100);
// 恢复原始调色板
ppal->setpaletteentries(0, ntotalcolors, palettecolors0);
ppal->animatepalette(0, ntotalcolors, palettecolors0);
} 
说明:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
2/2 首页 上一页 1 2 |