duilib之计算器+设计模式
学习对duilib有一段时间了,之前做过类似华为网盘的软件,还算山寨成功了,临近学期末,老师布置了一个设计模式的项目作业,就花了4天时间用duilib来做了。感觉一般,有很多地方可以改进,但是没时间了,下一步要潜心学习cocos2d-x,以后有时间在改吧,先写个总结。
注:5-16 版本已经更新了,增加了界面换肤更能,天气即时查询功能,暂时就不放出来了,有想法的人自己去实现吧。
界面展示:
计算器界面如下,仿照ios7界面画的

功能介绍:
- 主界面点击左上角信号图标可以关闭窗口
- 主界面点击设置按钮可以更改当前背景图片
- 主界面点击计算器进入计算器界面,之后可以进行计算操作,点击左上角信号图标可以发回主界面
- 计算器可以接受键盘输入,可以连续计算
界面布局源码:
- <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <Window size="359,580" caption="0,0,0,32">
- <Font name="华文细黑" size="35" bold="true" italic="false" />
- <Font name="华文细黑" size="70" bold="false" italic="false" />
- <Font name=".Lock Clock" size="73" bold="false" italic="false" />
- <Font name="新宋体" size="20" bold="true" italic="false" />
- <Font name=".Lock Clock" size="24" bold="false" italic="false" />
- <Font name="新宋体" size="17" bold="true" italic="false" />
- <VerticalLayout name="bk" width="360" height="580" bkimage="file='i4..png' dest='0,0,359,580'" bkcolor="#FF020202">
- <HorizontalLayout bordersize="3" width="360" height="130">
- <Text name="ans" float="true" pos="0,43,0,0" width="359" height="75" textpadding="2,0,2,0" textcolor="#00FFFBF0" disabledtextcolor="#FFA7A6AA" font="2" align="rightwrap" />
- <HorizontalLayout width="359" height="40">
- <Label float="true" pos="318,2,0,0" width="40" height="32" bkimage="WhiteOnBlackShadow_BatteryCharged@2x.png" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
- <Label text="99%" float="true" pos="282,6,0,0" width="39" height="22" textcolor="#00FFFFFF" disabledtextcolor="#FFA7A6AA" font="3" />
- <Text name="time" text="11:20" float="true" pos="147,6,0,0" width="60" height="24" textpadding="2,0,2,0" textcolor="#00FFFFFF" disabledtextcolor="#FFA7A6AA" font="3" align="wrap" />
- <Label text="BTF" float="true" pos="46,7,0,0" width="33" height="21" textcolor="#00FFFFFF" disabledtextcolor="#FFA7A6AA" font="3" />
- <Button name="reback" float="true" pos="2,4,0,0" width="40" height="28" bkimage="WhiteOnBlackEtch_4_Bars@2x.png" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" />
- </HorizontalLayout>
- </HorizontalLayout>
- <HorizontalLayout name="cal" width="359" height="450" bkcolor="#FF7793A2"visible="false">
- <Button name="clear" float="true" pos="0,0,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='clear_normal.png' mask='0xfffffbf0'" hotimage="file='clera_hotimge.png' mask='0xfffffbf0'" pushedimage="file='clear_hot.png' mask='0xfffffbf0'" />
- <Button name="plusminos" float="true" pos="90,0,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='plusmoins_normal.png' mask='0xfffffbf0'" hotimage="file='plusmoins_hotimage.png' mask='0xfffffbf0'" pushedimage="file='plusmoins_hot.png' mask='0xfffffbf0'" />
- <Button name="peurcent" float="true" pos="180,0,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='peurcent_nomal.png' mask='0xfffffbf0'" hotimage="file='peurcent_hotimage.png' mask='0xfffffbf0'" pushedimage="file='peurcent_hoti.png' mask='0xfffffbf0'" />
- <Button name="division" float="true" pos="270,0,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='division_normla.png' mask='0xfffffbf0'" hotimage="file='division_hotimge.png' mask='0xfffffbf0'" pushedimage="file='division_hot.png' mask='0xfffffbf0'" />
- <Button name="seven" float="true" pos="0,90,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='seven_normal.png' mask='0xfffffbf0'" hotimage="file='seven_hotimage.png' mask='0xfffffbf0'" pushedimage="file='seven_hot.png' mask='0xfffffbf0'" />
- <Button name="eight" float="true" pos="90,90,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='eight_normal.png' mask='0xfffffbf0'" hotimage="file='eight_hotimage.png' mask='0xfffffbf0'" pushedimage="file='eight_hot.png' mask='0xfffffbf0'" />
- <Button name="nine" float="true" pos="180,90,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='nine_normal.png' mask='0xfffffbf0'" hotimage="file='nine_hotimage.png' mask='0xfffffbf0'" pushedimage="file='nine_hot.png' mask='0xfffffbf0'" />
- <Button name="multiplication" float="true" pos="270,90,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='multiplication_normal.png' mask='0xfffffbf0'" hotimage="file='multiplication_hot.png' mask='0xfffffbf0'" pushedimage="file='multiplication_hoti.png' mask='0xfffffbf0'" />
- <Button name="four" float="true" pos="0,180,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='four_normal.png' mask='0xfffffbf0'" hotimage="file='fout_hotimage.png' mask='0xfffffbf0'" pushedimage="file='four_hot.png' mask='0xfffffbf0'" />
- <Button name="five" float="true" pos="90,180,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='five_normal.png' mask='0xfffffbf0'" hotimage="file='five_hotimage.png' mask='0xfffffbf0'" pushedimage="file='five_hot.png' mask='0xfffffbf0'" />
- <Button name="six" float="true" pos="180,180,0,0" width="89" height="89" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='six_normal.png' mask='0xfffffbf0'" hotimage="file='six_hotimage.png' mask='0xfffffbf0'" pushedimage