forked from yvt/xtbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XTBDialogSheet.cpp
134 lines (100 loc) · 2.53 KB
/
XTBDialogSheet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// XTBDialogSheet.cpp
// XTBook
//
// Created by 河田 智明 on 8/2/11.
// Copyright 2011 Nexhawks. All rights reserved.
//
#include "XTBDialogSheet.h"
#include <tcw/twApp.h>
#include <tcw/twTimerWithInvocation.h>
#include <tcw/twEvent.h>
XTBDialogSheet::XTBDialogSheet(){
m_needsDimming=true;
m_appearAnimationTimer=NULL;
twWndStyle style=getStyle();
style.border=twBS_panel;
setStyle(style);
// height*0.2
}
XTBDialogSheet::~XTBDialogSheet(){
stopAppearAnimation();
}
twRect XTBDialogSheet::finalRect() const{
twSize screenSize=tw_app->getScrSize();
twSize siz=startupSize();
twRect rt;
rt.w=siz.w;
rt.h=siz.h;
rt.x=(screenSize.w-rt.w)/2;
rt.y=screenSize.h-rt.h+1;
rt.h+=m_paddingHeight;
return rt;
}
twPoint XTBDialogSheet::getStartupPos(const twSize&,
const twRect& scrRect){
twRect fr=finalRect();
fr.y=m_startY;
return fr.loc();
}
void XTBDialogSheet::clientPaint(const twPaintStruct& p){
twDC *dc=p.dc;
twRect cli=p.boundRect;
twRect rt=cli;
rt.y=cli.h-m_paddingHeight;
rt.h=m_paddingHeight;
dc->fillRect(paddingColor(), rt);
}
#pragma mark - Appear Animations
void XTBDialogSheet::startAppearAnimation(){
twInvocation *invocation=
new twNoArgumentMemberFunctionInvocation<XTBDialogSheet>(this, &XTBDialogSheet::updateAppearAnimation);
m_appearAnimationTimer=new twTimerWithInvocation(invocation);
m_appearAnimationTimer->setInterval(10);
m_appearStartTime=twGetTicks();
m_appearDuration=startupSize().h*600/tw_app->getScrSize().h;
m_appearAnimationTimer->addToEvent(tw_event);
}
void XTBDialogSheet::stopAppearAnimation(){
if(m_appearAnimationTimer){
delete m_appearAnimationTimer;
m_appearAnimationTimer=NULL;
}
}
static float transferFunction(float time){
float v=time*time*(3.f-2.f*time);
v=.5f+(1.f-time)*(v-.5f);
return v*2.;
}
void XTBDialogSheet::updateAppearAnimation(){
twTicks tm=twGetTicks()-m_appearStartTime;
twRect rt=getRect();
float per=(float)tm/(float)m_appearDuration;
if(per>1.f){
// animation ended.
rt.y=m_endY;
setRect(rt);
stopAppearAnimation();
return;
}
per=transferFunction(per);
float currentY;
currentY=(float)m_startY*(1.f-per)
+(float)m_endY*per;
rt.y=(int)currentY;
setRect(rt);
}
void XTBDialogSheet::willAppear(){
m_paddingHeight=startupSize().h/5;
m_startY=tw_app->getScrSize().h;
m_endY=finalRect().y;
twRect rt=finalRect();
rt.y=m_startY;
setRect(rt);
this->m_dimmer->setHidingWindow(this);
startAppearAnimation();
twDialog::willAppear();
}
void XTBDialogSheet::didDisappear(){
stopAppearAnimation();
}