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

📄 sdl_ph_events.c

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 C
📖 第 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"/* Handle the event stream, converting photon events into SDL events */#include <stdio.h>#include <setjmp.h>#include <sys/time.h>#include <Ph.h>#include <photon/PkKeyDef.h>#include "SDL.h"#include "SDL_syswm.h"#include "../SDL_sysvideo.h"#include "../../events/SDL_sysevents.h"#include "../../events/SDL_events_c.h"#include "SDL_ph_video.h"#include "SDL_ph_modes_c.h"#include "SDL_ph_image_c.h"#include "SDL_ph_events_c.h"#include "SDL_phyuv_c.h"/* The translation tables from a photon keysym to a SDL keysym */static SDLKey ODD_keymap[256];static SDLKey MISC_keymap[0xFF + 1];SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);/* Check to see if this is a repeated key.   (idea shamelessly lifted from GII -- thanks guys! :) */static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent){    PhRect_t *rect = PhGetRects( winEvent );    int centre_x, centre_y;    int dx, dy;    short abs_x, abs_y;    int posted;    centre_x = SDL_VideoSurface->w / 2;    centre_y = SDL_VideoSurface->h / 2;    dx = rect->ul.x - centre_x;    dy = rect->ul.y - centre_y;    posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );    /* Move mouse cursor to middle of the window */    PtGetAbsPosition( window, &abs_x, &abs_y );    PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);    return (posted);}/* Control which motion flags the window has set, a flags value of -1 sets * MOTION_BUTTON and MOTION_NOBUTTON */static void set_motion_sensitivity(_THIS, unsigned int flags){    int rid;    int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;    PhRegion_t region;    if( window )    {        rid = PtWidgetRid(window);        if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 )        {            region.events_sense=(region.events_sense & ~fields)|(flags & fields);            PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);        }    }}/* Convert the photon button state value to an SDL value */static Uint8 ph2sdl_mousebutton(unsigned short button_state){    Uint8 mouse_button = 0;    if (button_state & Ph_BUTTON_SELECT)        mouse_button |= SDL_BUTTON_LEFT;    if (button_state & Ph_BUTTON_MENU)        mouse_button |= SDL_BUTTON_RIGHT;    if (button_state & Ph_BUTTON_ADJUST)        mouse_button |= SDL_BUTTON_MIDDLE;    return (mouse_button);}static int ph_DispatchEvent(_THIS){    int posted;    PhRect_t* rect;    PhPointerEvent_t* pointerEvent;    PhKeyEvent_t* keyEvent;    PhWindowEvent_t* winEvent;    int i, buttons;    SDL_Rect sdlrects[PH_SDL_MAX_RECTS];	    posted = 0;	    switch (phevent->type)    {        case Ph_EV_BOUNDARY:        {            if (phevent->subtype == Ph_EV_PTR_ENTER)            {                posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);            }            else if (phevent->subtype ==Ph_EV_PTR_LEAVE)            {                posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	            }        }        break;        case Ph_EV_PTR_MOTION_BUTTON:        case Ph_EV_PTR_MOTION_NOBUTTON:        {            if (SDL_VideoSurface)            {                pointerEvent = PhGetData(phevent);                rect = PhGetRects(phevent);                if (mouse_relative)                {                    posted = ph_WarpedMotion(this, phevent);                }                else                {                    posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);                }            }        }        break;        case Ph_EV_BUT_PRESS:        {            pointerEvent = PhGetData(phevent);            buttons = ph2sdl_mousebutton(pointerEvent->buttons);            if (buttons != 0)            {                posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);            }        }        break;        case Ph_EV_BUT_RELEASE:        {            pointerEvent = PhGetData(phevent);            buttons = ph2sdl_mousebutton(pointerEvent->buttons);            if (phevent->subtype == Ph_EV_RELEASE_REAL && buttons != 0)            {                posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);            }            else if(phevent->subtype == Ph_EV_RELEASE_PHANTOM)            {                /* If the mouse is outside the window,                 * only a phantom release event is sent, so                 * check if the window doesn't have mouse focus.                 * Not perfect, maybe checking the mouse button                 * state for Ph_EV_BOUNDARY events would be                 * better. */                if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0)		{                    posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);                }            }        }        break;        case Ph_EV_WM:        {            winEvent = PhGetData(phevent);            /* losing focus */            if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))            {                set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);                posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	            }            /* gaining focus */            else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))            {                set_motion_sensitivity(this, -1);                posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);            }            /* request quit */            else if (winEvent->event_f==Ph_WM_CLOSE)            {                posted = SDL_PrivateQuit();            }            /* request hide/unhide */            else if (winEvent->event_f==Ph_WM_HIDE)            {                if (currently_hided)                {                   /* got unhide window event                                */                   /* TODO: restore application's palette if in palette mode */                   currently_hided=0;                }                else                {                   /* got hide window event                                  */                   /* TODO: restore original palette if in palette mode      */                   currently_hided=1;                }            }            /* request to resize */            else if (winEvent->event_f==Ph_WM_RESIZE)            {                currently_maximized=0;                #if (_NTO_VERSION < 630)                   SDL_PrivateResize(winEvent->size.w+1, winEvent->size.h+1);                #else                   /* QNX 6.3.0 have this bug fixed */                   SDL_PrivateResize(winEvent->size.w, winEvent->size.h);                #endif /* _NTO_VERSION */            }            /* request to move */            else if (winEvent->event_f==Ph_WM_MOVE)            {                if (current_overlay!=NULL)                {                   int lockedstate=current_overlay->hwdata->locked;                   int chromastate=current_overlay->hwdata->ischromakey;                   int error;                   SDL_Rect src, dst;                   current_overlay->hwdata->locked=1;                   src.x = 0;                   src.y = 0;                   src.w = current_overlay->w;                   src.y = current_overlay->h;                   dst.x=current_overlay->hwdata->CurrentViewPort.pos.x;                   dst.y=current_overlay->hwdata->CurrentViewPort.pos.y;                   dst.w=current_overlay->hwdata->CurrentViewPort.size.w;                   dst.h=current_overlay->hwdata->CurrentViewPort.size.h;                   current_overlay->hwdata->ischromakey=0;                   error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst);                   if (!error)                   {                       current_overlay->hwdata->ischromakey=chromastate;                       current_overlay->hwdata->locked=lockedstate;                   }                }            }            /* maximize request */            else if (winEvent->event_f==Ph_WM_MAX)            {                /* window already moved and resized here */                currently_maximized=1;            }            /* restore request */            else if (winEvent->event_f==Ph_WM_RESTORE)            {                /* window already moved and resized here */                currently_maximized=0;            }        }        break;        /* window has been resized, moved or removed */        case Ph_EV_EXPOSE:        {            if (phevent->num_rects!=0)            {                int numrects;                if (SDL_VideoSurface)                {                    rect = PhGetRects(phevent);                    if (phevent->num_rects>PH_SDL_MAX_RECTS)                    {                       /* sorry, buffers underrun, we'll update only first PH_SDL_MAX_RECTS rects */                       numrects=PH_SDL_MAX_RECTS;                    }                    for(i=0; i<phevent->num_rects; i++)                    {                        sdlrects[i].x = rect[i].ul.x;                        sdlrects[i].y = rect[i].ul.y;                        sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;                        sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;                    }                    this->UpdateRects(this, phevent->num_rects, sdlrects);                    if (current_overlay!=NULL)                    {                        int lockedstate=current_overlay->hwdata->locked;                        int error;                        SDL_Rect src, dst;

⌨️ 快捷键说明

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