首页 > 移动平台 > 详细

SDL2 简单实现图片缩放移动查看

时间:2016-03-19 21:20:43      阅读:1171      评论:0      收藏:0      [点我收藏+]
#include <SDL.h>
int main(int, char**)
{
    SDL_Window* win = SDL_CreateWindow("yoooomeng", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
    SDL_Renderer* renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
    SDL_Surface* surface = SDL_LoadBMP("yoooomeng.bmp");
    SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
    bool quit = false;
    SDL_Event ev;
    SDL_Rect rect = { 0,0,800,600 };
    int sx = 0, sy = 0;
    while (!quit)
    {
        while (SDL_PollEvent(&ev))
        {
            switch (ev.type)
            {
            case SDL_QUIT:
                quit = true;
                break;
            case SDL_MOUSEBUTTONDOWN:
                sx = ev.button.x+rect.x ;
                sy = ev.button.y+rect.y;
                break;
            case SDL_MOUSEMOTION:
                if (ev.motion.state)
                {
                    rect.x = ev.motion.x - sx ;
                    rect.y = ev.motion.y - sy;
                }
                break;
            case SDL_MOUSEWHEEL:
                if (ev.wheel.y > 0)
                {
                    rect.h *= 1.1;
                    rect.w *= 1.1;
                }
                if (ev.wheel.y < 0)
                {
                    rect.w /= 1.1;
                    rect.h /= 1.1;
                }
                break;
            }
        }
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, texture, NULL, &rect);
        SDL_RenderPresent(renderer);
        SDL_Delay(16);
    }
    return 0;
}

运行如下

技术分享

SDL2 简单实现图片缩放移动查看

原文:http://www.cnblogs.com/CodeMIRACLE/p/5296223.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!