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

📄 sdl_qwin.cc

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 CC
📖 第 1 页 / 共 2 页
字号:
/*    SDL - Simple DirectMedia Layer    Copyright (C) 1997-2006 Sam Lantinga    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA    Sam Lantinga    slouken@libsdl.org*/#include "SDL_config.h"#include "SDL_QWin.h"#include <qapplication.h>#include <qdirectpainter_qws.h>screenRotationT screenRotation = SDL_QT_NO_ROTATION;SDL_QWin::SDL_QWin(const QSize& size)  : QWidget(0, "SDL_main"), my_painter(0), my_image(0),    my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0),    my_has_fullscreen(false), my_locked(0){  setBackgroundMode(NoBackground);}SDL_QWin::~SDL_QWin() {  // Nothing to do yet.  if(my_image) {    delete my_image;  }}void SDL_QWin::setImage(QImage *image) {  if ( my_image ) {    delete my_image;  }  my_image = image;  //  setFixedSize(image->size());}void SDL_QWin::resizeEvent(QResizeEvent *e) {  if(size() != qApp->desktop()->size()) {    // Widget is not the correct size, so do the fullscreen magic    my_has_fullscreen = false;    enableFullscreen();  }  if(my_inhibit_resize) {    my_inhibit_resize = false;  } else {    SDL_PrivateResize(e->size().width(), e->size().height());  }}void SDL_QWin::focusInEvent(QFocusEvent *) {  // Always do it here, no matter the size.  enableFullscreen();  SDL_PrivateAppActive(true, SDL_APPINPUTFOCUS);}void SDL_QWin::focusOutEvent(QFocusEvent *) {  my_has_fullscreen = false;  SDL_PrivateAppActive(false, SDL_APPINPUTFOCUS);}void SDL_QWin::closeEvent(QCloseEvent *e) {  SDL_PrivateQuit();  e->ignore();}void SDL_QWin::setMousePos(const QPoint &pos) {  if(my_image->width() == height()) {    if (screenRotation == SDL_QT_ROTATION_90)      my_mouse_pos = QPoint(height()-pos.y(), pos.x());    else if (screenRotation == SDL_QT_ROTATION_270)      my_mouse_pos = QPoint(pos.y(), width()-pos.x());  } else {    my_mouse_pos = pos;  }}void SDL_QWin::mouseMoveEvent(QMouseEvent *e) {  Qt::ButtonState button = e->button();  int sdlstate = 0;  if( (button & Qt::LeftButton)) {    sdlstate |= SDL_BUTTON_LMASK;  }  if( (button & Qt::RightButton)) {    sdlstate |= SDL_BUTTON_RMASK;  }  if( (button & Qt::MidButton)) {    sdlstate |= SDL_BUTTON_MMASK;  }  setMousePos(e->pos());  SDL_PrivateMouseMotion(sdlstate, 0, my_mouse_pos.x(), my_mouse_pos.y());}void SDL_QWin::mousePressEvent(QMouseEvent *e) {  mouseMoveEvent(e);  Qt::ButtonState button = e->button();  SDL_PrivateMouseButton(SDL_PRESSED,			 (button & Qt::LeftButton) ? 1 :			 ((button & Qt::RightButton) ? 2 : 3),			 my_mouse_pos.x(), my_mouse_pos.y());}void SDL_QWin::mouseReleaseEvent(QMouseEvent *e) {  setMousePos(e->pos());  Qt::ButtonState button = e->button();  SDL_PrivateMouseButton(SDL_RELEASED,			 (button & Qt::LeftButton) ? 1 :			 ((button & Qt::RightButton) ? 2 : 3),			 my_mouse_pos.x(), my_mouse_pos.y());  my_mouse_pos = QPoint(-1, -1);}static inline voidgs_fastRotateBlit_3 ( unsigned short *fb,		      unsigned short *bits,		      const QRect& rect ){  // FIXME: this only works correctly for 240x320 displays  int startx, starty;  int width, height;    startx = rect.left() >> 1;  starty = rect.top() >> 1;  width  = ((rect.right() - rect.left()) >> 1) + 2;  height = ((rect.bottom() - rect.top()) >> 1) + 2;  if((startx+width) > 120) {    width = 120 - startx; // avoid horizontal overflow  }  if((starty+height) > 160) {     height = 160 - starty; // avoid vertical overflow  }  ulong *sp1, *sp2, *dp1, *dp2;  ulong stop, sbot, dtop, dbot;        sp1 = (ulong*)bits + startx + starty*240;  sp2 = sp1 + 120;  dp1 = (ulong *)fb + (159 - starty) + startx*320;  dp2 = dp1 + 160;  int rowadd = (-320*width) - 1;  int rowadd2 = 240 - width;  // transfer in cells of 2x2 pixels in words  for (int y=0; y<height; y++) {    for (int x=0; x<width; x++) {      // read source pixels      stop = *sp1;      sbot = *sp2;      // rotate pixels      dtop = (sbot & 0xffff) + ((stop & 0xffff)<<16);      dbot = ((sbot & 0xffff0000)>>16) + (stop & 0xffff0000);      // write to framebuffer      *dp1 = dtop;      *dp2 = dbot;      // update source ptrs      sp1++; sp2++;      // update dest ptrs - 2 pix at a time      dp1 += 320;      dp2 += 320;    }    // adjust src ptrs - skip a row as we work in pairs    sp1 += rowadd2;    sp2 += rowadd2;    // adjust dest ptrs for rotation    dp1 += rowadd;    dp2 += rowadd;  }}static inline voidgs_fastRotateBlit_1 ( unsigned short *fb,		      unsigned short *bits,		      const QRect& rect ) {  // FIXME: this only works correctly for 240x320 displays  int startx, starty;  int width, height;  startx = rect.left() >> 1;  starty = rect.top() >> 1;  width  = ((rect.right() - rect.left()) >> 1) + 2;  height = ((rect.bottom() - rect.top()) >> 1) + 2;  if((startx+width) > 120) {    width = 120 - startx; // avoid horizontal overflow  }  if((starty+height) > 160) {     height = 160 - starty; // avoid vertical overflow  }  ulong *sp1, *sp2, *dp1, *dp2;  ulong stop, sbot, dtop, dbot;      fb += 320*239; // Move "fb" to top left corner  sp1 = (ulong*)bits + startx + starty*240;  sp2 = sp1 + 120;  dp1 = (ulong*)fb - startx * 320 - starty;  dp2 = dp1 - 160;  int rowadd = (320*width) + 1;  int rowadd2 = 240 - width;  // transfer in cells of 2x2 pixels in words  for (int y=0; y<height; y++) {    for (int x=0; x<width; x++) {      // read      stop = *sp1;      sbot = *sp2;      // rotate      dtop = (stop & 0xffff) + ((sbot & 0xffff)<<16);      dbot = ((stop & 0xffff0000)>>16) + (sbot & 0xffff0000);      // write      *dp1 = dtop;      *dp2 = dbot;      // update source ptrs      sp1++; sp2++;      // update dest ptrs - 2 pix at a time      dp1 -= 320;      dp2 -= 320;    }    // adjust src ptrs - skip a row as we work in pairs    sp1 += rowadd2;    sp2 += rowadd2;    // adjust dest ptrs for rotation    dp1 += rowadd;    dp2 += rowadd;  }}// desktop, SL-A300 etcbool SDL_QWin::repaintRotation0(const QRect& rect) {  if(my_image->width() == width()) {    uchar *fb = (uchar*)my_painter->frameBuffer();    uchar *buf = (uchar*)my_image->bits();    if(rect == my_image->rect()) {      SDL_memcpy(fb, buf, width()*height()*2);    } else {      int h = rect.height();      int wd = rect.width()<<1;      int fblineadd = my_painter->lineStep();      int buflineadd = my_image->bytesPerLine();      fb  += (rect.left()<<1) + rect.top() * my_painter->lineStep();      buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();      while(h--) {	SDL_memcpy(fb, buf, wd);	fb += fblineadd;	buf += buflineadd;      }    }  } else {    return false; // FIXME: Landscape  }#ifdef __i386__

⌨️ 快捷键说明

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