首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

perl-SDL处置键盘与鼠标

2013-01-19 
perl-SDL处理键盘与鼠标use SDLuse SDLx::Appuse SDL::Eventmy $appSDLx::App-new(w400,h400,d

perl-SDL处理键盘与鼠标

use SDL;use SDLx::App;use SDL::Event;my $app=SDLx::App->new(w=>400,h=>400,d=>32,t=>"my paint");my $color =[255,255,255,255];my $drawing=0;$app->add_event_handler(\&quit_handle);$app->add_event_handler(\&key_event);$app->add_event_handler(\&mouse_event);$app->run();sub quit_handle{    my $event=shift;my $controller=shift;$controller->stop() if $event->type==SDL_QUIT;}sub key_event{   my $keyevent=shift;   if ($keyevent->type==SDL_KEYDOWN)   {       my $key_name=SDL::Events::get_key_name($keyevent->key_sym);   if ($key_name=~/^c$/){      $app->draw_rect([0,0,400,400],0);   }   elsif  ($key_name=~/^q$/)   {      $app->stop();   }   else   {        my $col1=int(rand(255));my $col2=int(rand(255));my $col3=int(rand(255));         $color =[$col1,$col2,$col3,255];   }      }}sub  mouse_event{    my $event=shift;if ($event->type==SDL_MOUSEBUTTONDOWN||$drawing){    $drawing=1;my $x=$event->button_x;my $y=$event->button_y;$app->draw_rect([$x,$y,2,2],$color);$app->update();}    $drawing=0 if ($event->type==SDL_MOUSEBUTTONUP);}

?

?


perl-SDL处置键盘与鼠标
?

热点排行