⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdlwidget.cpp

📁 qt和sdl库的结合 通过sdl库加载图片 并且在qt界面下显示控制
💻 CPP
字号:
/****************************************************************************** $Id:  qt/SDLWidget.cpp   3.0.5   edited Oct 12 2001 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include <stdlib.h>#include <stdio.h>#include "SDL.h"#include "SDLWidget.h"#if defined(Q_WS_X11)#include <X11/Xlib.h>//Added by qt3to4:#include <QPaintEvent>#include <QResizeEvent>#endifQSDLScreenWidget::QSDLScreenWidget( QWidget *parent) :    QWidget(parent), screen(NULL){    atexit(SDL_Quit);}void QSDLScreenWidget::resizeEvent( QResizeEvent * ){    char variable[64];    // We could get a resize event at any time, so clean previous mode    screen = NULL;    SDL_QuitSubSystem(SDL_INIT_VIDEO);    // Set the new video mode with the new window size    sprintf(variable, "SDL_WINDOWID=0x%lx", winId());    putenv(variable);    if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) {        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());        return;    }    screen = SDL_SetVideoMode(width(), height(), 0, 0);    if ( ! screen ) {        fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());        return;    }}void QSDLScreenWidget::paintEvent( QPaintEvent * ){#if defined(Q_WS_X11)    // Make sure we're not conflicting with drawing from the Qt library    XSync(QPaintDevice::x11Display(), FALSE);#endif    if ( screen ) {        SDL_FillRect(screen, NULL, 0);        SDL_Surface *image = SDL_LoadBMP("sample.bmp");        if ( image ) {            SDL_Rect dst;            dst.x = (screen->w - image->w)/2;            dst.y = (screen->h - image->h)/2;            dst.w = image->w;            dst.h = image->h;            SDL_BlitSurface(image, NULL, screen, &dst);        }        SDL_Flip(screen);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -