关闭

借助SDL图库画个按钮

标签: buttonnull
1764人阅读 评论(2) 收藏 举报
分类:

  其实我们点击的按钮都是用坐标画上去的,当我们点击按钮就是触发里一个事件,好我们将按钮的上部分图片的坐标往一个方向移动一点距离,当我们松开鼠标时就让图片回到原来的位置,这样就是一个具有立体感的按钮!

 

主函数:

#include "Button.h"

Button::Button( SDL_Surface *src){
  screen=src;
 }
 
void Button::drawn()
{
 SDL_Event event;
 while(1){
  SDL_WaitEvent(&event);
  switch(event.type)
  {
   case SDL_MOUSEBUTTONDOWN:
    if(event.button.x<=100 && event.button.x>=40)
    if(event.button.y>=40 && event.button.y<= 100){
     
     boxRGBA(screen,44,44,104,104,100,100,63,0xff);
     filledTrigonRGBA(screen,55,55,85,70,55,85,70,77,235,0xff);
     boxRGBA(screen,85,55,90,85 ,70,77,235,0xff);
     display();
    }
    break;
   case SDL_MOUSEBUTTONUP:
     boxRGBA(screen,43,43,103,103,233,231,231,0xff);
     boxRGBA(screen,40,40,100,100,133,124,122,0xff);
     filledTrigonRGBA(screen,55,55,85,70,55,85 ,69,55,67,0xff);
     boxRGBA(screen,85,55,90,85 ,69,55,67,0xff);
     filledTrigonRGBA(screen, 100,40,104,44,100,44,233,231,231,0xff);
     display();
     SDL_FillRect(screen,NULL,0x00);
     break;
   case SDL_QUIT:
    exit(1);
  }
 }
}

void Button::drawn1()
{
 boxRGBA(screen,43,43,103,103,233,231,231,0xff);
 boxRGBA(screen,40,40,100,100,133,124,122,0xff);
 filledTrigonRGBA(screen,55,55,85,70,55,85 ,69,55,67,0xff);
 boxRGBA(screen,85,55,90,85 ,69,55,67,0xff);
 filledTrigonRGBA(screen, 100,40,103,43,100,43,233,231,231,0xff);
 display();
 SDL_FillRect(screen,NULL,0x00);

}
void Button::display()
{
 
 SDL_UpdateRect(screen,0,0,0,0);

}

 

头文件

#ifndef BUTTON_H
#define BUTTON_H

#include<iostream>
using namespace std;
#include<SDL/SDL.h>
#include<SDL/SDL_gfxPrimitives.h>
class Button
{
 public:
 Button( SDL_Surface *src);
 void drawn();
 void drawn1();
 void display();
 private:
 SDL_Surface *screen;

};
#endif

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:17848次
    • 积分:279
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:0篇
    • 译文:0篇
    • 评论:7条
    文章分类
    最新评论