模仿老式拨盘电话机拨号原理拨号

本文介绍了一种在MTK平台上实现复古电话盘动画的方法。通过使用特定的绘图函数和数学计算,实现了电话盘上数字及符号的位置布局,并通过定时器不断更新角度来模拟拨号过程。

总是有不少怀旧的人喜欢老电话,老相机,比如我,每次看到老上海的电话机,老香港的手提砖头块,总是会产生一种奇怪的感觉。
老话机每一个格就是一个脉冲,拨1就一个格,拨9就9个格,也就是能听到咔咔声9次。每个对应位置就接通一次脉冲,错过位置就断了,
下一个格又是一个脉冲,0就是10个脉冲。
这里只是在MTK做一些小尝试,非完整代码,请勿模仿。
#define DIAL_X  (UI_device_width/2)
#define DIAL_Y  ((UI_device_height/2)+30)
#define DIAL_R  ((((UI_device_height>UI_device_width)?(UI_device_width/2):(UI_device_height/2))))
#define DIAL_IN_R  (20)
#define DIAL_COLOR  (GDI_COLOR_BLACK)
void my_gdi_draw_line(S32 x1, S32 y1, S32 x2, S32 y2, gdi_color line_color, S32 w)
{
	mmi_pen_point_struct a[4];
	S32 sinx;
	S32 cosx;
	S32 r;
	S32 tmp;

	tmp = sqrt(((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
	sinx = (int)(((y2-y1)*1000/(int)tmp));
	cosx = (int)(((x2-x1)*1000/(int)tmp));
	if (w >2)
	{
		r  = w/2;
		a[0].x = x1 + (int)((r*sinx)/1000);
		a[0].y = y1 - (int)((r*cosx)/1000);
		
		a[1].x = x2 + (int)(((((r%2)!=0)?(r+1):r)*sinx)/1000);
		a[1].y = y2 - (int)(((((r%2)!=0)?(r+1):r)*cosx)/1000);

		a[2].x = x2 - (int)(((((r%2)!=0)?(r+1):r)*sinx)/1000);
		a[2].y = y2 + (int)(((((r%2)!=0)?(r+1):r)*cosx)/1000);

		a[3].x = x1 - (int)((r*sinx)/1000);
		a[3].y = y1 + (int)((r*cosx)/1000);

		gdi_draw_solid_polygon(a,4,DIAL_COLOR);
	}
	else
	{
		color c;
		
		c.r = (U8) ((0xFF000000 & line_color) >> 24);
		c.g = (U8) ((0x00FF0000 & line_color) >> 16);
		c.b = (U8) ((0x0000FF00 & line_color) >> 8);
		c.alpha = (U8) ((0x000000FF & line_color));

		gui_wline(x1, y1, x2, y2, c, w);
	}

}
extern void my_gdi_draw_line(S32 x1, S32 y1, S32 x2, S32 y2, gdi_color line_color, S32 w);
extern void my_gui_draw_anm_dial(void);

void exit_myapp_screen(void)
{
    if (buf_ptr != NULL)
    {
        med_free_ext_mem((void **)&buf_ptr);
    }
    if (my_layer2 != NULL)
    {
        gdi_layer_free(my_layer2);
    }
	InitDesktopScreen();
	gui_cancel_timer(my_gui_draw_anm_dial);
//GoBackHistory();
}
void my_gui_draw_dial(U16 angle)
{
	U8 i;
char *t[] = {L"0", L"1",L"2", L"3", L"4",L"5", L"6", L"7", L"8", L"9", L"*", L"#", L"←", L"A", L"B", L"C"};
		gdi_draw_circle(DIAL_X,DIAL_Y,DIAL_R,DIAL_COLOR);
		gdi_draw_circle(DIAL_X,DIAL_Y,(DIAL_R*618)/1000,DIAL_COLOR);
	
		gdi_draw_point(DIAL_X,DIAL_Y,DIAL_COLOR);
		gdi_draw_point(DIAL_X+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_cosine_table[angle],DIAL_Y+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_sine_table[angle],DIAL_COLOR);
	
		for (i = 0; i < 16; i++)
		{
			gdi_draw_circle(DIAL_X+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_cosine_table[((i*22)+angle)>=360?(((i*22)+angle)-360):((i*22)+angle)],DIAL_Y+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_sine_table[((i*22)+angle)>=360?(((i*22)+angle)-360):((i*22)+angle)],(DIAL_R*100)/1000,DIAL_COLOR);
			gui_move_text_cursor(DIAL_X+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_cosine_table[((i*22)+angle)>=360?(((i*22)+angle)-360):((i*22)+angle)]-5, DIAL_Y+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_sine_table[((i*22)+angle)>=360?(((i*22)+angle)-360):((i*22)+angle)]-5);
			gui_print_text((UI_string_type)t[i]);
		}

}

void my_gui_draw_anm_dial(void)
{

	static U16 a = 0;
	gdi_layer_get_base_handle(&my_base_layer);
	gdi_layer_set_active(my_base_layer);
	gdi_layer_clear(GDI_COLOR_TRANSPARENT);
	my_gui_draw_dial(a);
	//UI_start_timer(100, my_gui_draw_anm_dial);
	gdi_layer_set_blt_layer(my_base_layer, my_layer2, NULL, NULL);
	gdi_layer_blt_previous(0, 0, UI_device_width - 1, UI_device_height - 1);
	a = a + 5;
	if (a >= 360)
	{
		a = 0;
	}
	gui_start_timer(100, my_gui_draw_anm_dial);

}

void entry_myapp_screen(void)
{
	U8 *gui_buffer;
	BOOL isEnable;
	gdi_color base_color;
	mmi_pen_point_struct a[4];
	U16 angle = 0;
	U8 i;
	ExitDesktopScreen();

	//EntryNewScreen (MAIN_MENU_SCREENID,exit_myapp_screen,entry_myapp_screen, NULL);

//	gui_buffer = GetCurrGuiBuffer(MAIN_MENU_SCREENID);
	entry_full_screen();
	gdi_layer_clear(GDI_COLOR_TRANSPARENT);
	gdi_layer_multi_layer_enable();

	gdi_layer_create(0, 0, UI_device_width, UI_device_height, &my_layer2);
	gdi_layer_set_active(my_layer2);
	gdi_layer_clear_background(GDI_COLOR_TRANSPARENT);
	gdi_layer_set_source_key(TRUE, GDI_COLOR_TRANSPARENT);
	
	//draw handle
	a[0].x = DIAL_X;
	a[0].y = DIAL_Y;
	a[2].x = DIAL_X + (int)(((DIAL_R*618)/1000)*g_qj_gui_clock_acm_cosine_table[angle]);
	a[2].y = DIAL_Y + (int)(((DIAL_R*618)/1000)*g_qj_gui_clock_acm_sine_table[angle]);
	a[1].x = DIAL_X + (int)(DIAL_IN_R*g_qj_gui_clock_acm_cosine_table[((angle-42)>0?(angle-42):(angle-42+360))]);
	a[1].y = DIAL_Y + (int)(DIAL_IN_R*g_qj_gui_clock_acm_sine_table[((angle-42)>0?(angle-42):(angle-42+360))]);
	a[3].x = DIAL_X + (int)(DIAL_IN_R*g_qj_gui_clock_acm_cosine_table[((angle+42)<360?(angle+42):(angle+42-360))]);
	a[3].y = DIAL_Y + (int)(DIAL_IN_R*g_qj_gui_clock_acm_sine_table[((angle+42)<360?(angle+42):(angle+42-360))]);



	gdi_draw_polygon(a,4,DIAL_COLOR);

	gui_wline(a[0].x, a[0].y,a[2].x,a[2].y, UI_COLOR_GREEN,2);
	gui_wline(a[1].x, a[1].y,a[3].x,a[3].y, UI_COLOR_GREEN,2);

	//draw earphone
	//gdi_draw_circle(DIAL_X,DIAL_Y,UI_device_height/2+20,DIAL_COLOR);

	//my_gdi_draw_line(10, 20, 100, 50, DIAL_COLOR, 10);
	gdi_layer_get_base_handle(&my_base_layer);
	gdi_layer_set_active(my_base_layer);
	//draw dial
	#if 0
	gdi_draw_circle(DIAL_X,DIAL_Y,DIAL_R,DIAL_COLOR);
	gdi_draw_circle(DIAL_X,DIAL_Y,(DIAL_R*618)/1000,DIAL_COLOR);
	gdi_draw_circle(DIAL_X,DIAL_Y,20,DIAL_COLOR);

	gdi_draw_point(DIAL_X,DIAL_Y,DIAL_COLOR);

	gdi_draw_point(DIAL_X+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_cosine_table[angle],DIAL_Y+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_sine_table[angle],DIAL_COLOR);

	for (i = 0; i < 16; i++)
	{
		gdi_draw_circle(DIAL_X+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_cosine_table[(i*22)],DIAL_Y+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_sine_table[(i*22)],(DIAL_R*100)/1000,DIAL_COLOR);
		gui_move_text_cursor(DIAL_X+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_cosine_table[(i*22)]-5, DIAL_Y+(int)((DIAL_R*809)/1000)*g_qj_gui_clock_acm_sine_table[(i*22)]-5);
		gui_print_text((UI_string_type)t[i]);
	}
    #else
	//gui_start_timer(100, my_gui_draw_anm_dial);
	//my_gui_draw_dial(90);
	my_gui_draw_anm_dial();
    #endif
	gdi_layer_set_blt_layer(my_base_layer, my_layer2, NULL, NULL);
	gdi_layer_blt_previous(0, 0, UI_device_width - 1, UI_device_height - 1);

	SetKeyHandler(exit_myapp_screen, KEY_RSK, KEY_EVENT_UP);  
}
该文用到的三角形函数值数组请参阅拙作:

巧用数学函数生成函数表

http://blog.youkuaiyun.com/blogercn/archive/2011/03/28/6283278.aspx

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值