diff options
author | Marcus Comstedt | 2004-03-14 22:16:22 +0000 |
---|---|---|
committer | Marcus Comstedt | 2004-03-14 22:16:22 +0000 |
commit | f1cac1545bd543fa52a75f2f6a4b6e0f0024380d (patch) | |
tree | 4f62cdf4f5b73a72d10a9d4625c09fa404bf922f /backends | |
parent | 0d3b89b88f7b969087549a68a79ffdfa769238e2 (diff) | |
download | scummvm-rg350-f1cac1545bd543fa52a75f2f6a4b6e0f0024380d.tar.gz scummvm-rg350-f1cac1545bd543fa52a75f2f6a4b6e0f0024380d.tar.bz2 scummvm-rg350-f1cac1545bd543fa52a75f2f6a4b6e0f0024380d.zip |
Virtual keyboard.
svn-id: r13279
Diffstat (limited to 'backends')
-rw-r--r-- | backends/dc/Makefile | 4 | ||||
-rw-r--r-- | backends/dc/dc.h | 16 | ||||
-rw-r--r-- | backends/dc/dcmain.cpp | 7 | ||||
-rw-r--r-- | backends/dc/display.cpp | 13 | ||||
-rw-r--r-- | backends/dc/input.cpp | 63 | ||||
-rw-r--r-- | backends/dc/softkbd.cpp | 157 | ||||
-rw-r--r-- | backends/dc/softkbd.h | 45 |
7 files changed, 280 insertions, 25 deletions
diff --git a/backends/dc/Makefile b/backends/dc/Makefile index 29e5bc45d7..1fe5fd1a03 100644 --- a/backends/dc/Makefile +++ b/backends/dc/Makefile @@ -10,7 +10,7 @@ CXXFLAGS= -O3 -Wno-multichar -funroll-loops -fschedule-insns2 -fomit-frame-point DEFINES = -D__DC__ -DNONSTANDARD_PORT LDFLAGS = -Wl,-Ttext,0x8c010000 -nostartfiles $(ronindir)/lib/crt0.o INCLUDES= -I./ -I$(srcdir) -I$(srcdir)/common -I$(ronindir)/include/ -LIBS = -L$(ronindir)/lib -lronin -lz -lm +LIBS = -L$(ronindir)/lib -lronin-netcd -lz -lm EXECUTABLE = scummvm.elf MKDIR = mkdir -p RM = rm -f @@ -20,7 +20,7 @@ RANLIB = sh-elf-ranlib HAVE_GCC3 = true OBJS := dcmain.o time.o display.o audio.o input.o selector.o icon.o \ - label.o vmsave.o + label.o vmsave.o softkbd.o MODULE_DIRS += . diff --git a/backends/dc/dc.h b/backends/dc/dc.h index cb2f778e2e..d18c722f32 100644 --- a/backends/dc/dc.h +++ b/backends/dc/dc.h @@ -26,6 +26,14 @@ #define NUM_BUFFERS 4 #define SOUND_BUFFER_SHIFT 3 +class Interactive +{ + public: + virtual int key(int k, byte &shiftFlags) = 0; +}; + +#include "softkbd.h" + class OSystem_Dreamcast : public OSystem { public: @@ -145,6 +153,8 @@ class OSystem_Dreamcast : public OSystem { private: + SoftKeyboard _softkbd; + int _ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_old_x, _ms_old_y; int _ms_hotspot_x, _ms_hotspot_y, _ms_visible, _devpoll; int _current_shake_pos, _screen_w, _screen_h; @@ -154,8 +164,9 @@ class OSystem_Dreamcast : public OSystem { void *_sound_proc_param; bool _overlay_visible, _overlay_dirty, _screen_dirty; int _screen_buffer, _overlay_buffer, _mouse_buffer; - bool _aspect_stretch; + bool _aspect_stretch, _softkbd_on; float _overlay_fade, _xscale, _yscale, _top_offset; + int _softkbd_motion; uint32 _timer_duration, _timer_next_expiry; bool _timer_active; @@ -179,9 +190,10 @@ class OSystem_Dreamcast : public OSystem { void setScaling(); }; + extern int handleInput(struct mapledev *pad, int &mouse_x, int &mouse_y, - byte &shiftFlags); + byte &shiftFlags, Interactive *inter = NULL); extern void initSound(); extern bool selectGame(char *&, char *&, class Icon &); diff --git a/backends/dc/dcmain.cpp b/backends/dc/dcmain.cpp index 61f3a7605d..3d35133a38 100644 --- a/backends/dc/dcmain.cpp +++ b/backends/dc/dcmain.cpp @@ -47,7 +47,7 @@ OSystem *OSystem_Dreamcast::create() { OSystem_Dreamcast::OSystem_Dreamcast() : screen(NULL), mouse(NULL), overlay(NULL), _ms_buf(NULL), _sound_proc(NULL), _timer_active(false), _current_shake_pos(0), - _aspect_stretch(false) + _aspect_stretch(false), _softkbd_on(false), _softkbd_motion(0) { memset(screen_tx, 0, sizeof(screen_tx)); memset(mouse_tx, 0, sizeof(mouse_tx)); @@ -165,7 +165,7 @@ void OSystem_Dreamcast::setFeatureState(Feature f, bool enable) setScaling(); break; case kFeatureVirtualKeyboard: - /* FIXME */ + _softkbd_on = enable; break; default: break; @@ -178,8 +178,7 @@ bool OSystem_Dreamcast::getFeatureState(Feature f) case kFeatureAspectRatioCorrection: return _aspect_stretch; case kFeatureVirtualKeyboard: - /* FIXME */ - return false; + return _softkbd_on; default: return false; } diff --git a/backends/dc/display.cpp b/backends/dc/display.cpp index 597cb03083..d32e3a718b 100644 --- a/backends/dc/display.cpp +++ b/backends/dc/display.cpp @@ -419,6 +419,19 @@ void OSystem_Dreamcast::updateScreen(void) ta_commit_list(&myvertex); } + if(_softkbd_on) + if(_softkbd_motion < 120) + _softkbd_motion += 10; + else + ; + else + if(_softkbd_motion > 0) + _softkbd_motion -= 10; + + if(_softkbd_motion) + _softkbd.draw(330.0*sin(0.013*_softkbd_motion) - 320.0, 200.0, + 120-_softkbd_motion); + // *((volatile unsigned int *)(void*)0xa05f8040) = 0xffff00; drawMouse(_ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_buf, _ms_visible); // *((volatile unsigned int *)(void*)0xa05f8040) = 0xff00ff; diff --git a/backends/dc/input.cpp b/backends/dc/input.cpp index cc04a2538f..ad0164991b 100644 --- a/backends/dc/input.cpp +++ b/backends/dc/input.cpp @@ -27,7 +27,7 @@ #include "dc.h" int handleInput(struct mapledev *pad, int &mouse_x, int &mouse_y, - byte &shiftFlags) + byte &shiftFlags, Interactive *inter) { static const char numpadmap[] = "0000039601740285"; int lmb=0, rmb=0, newkey=0; @@ -47,13 +47,17 @@ int handleInput(struct mapledev *pad, int &mouse_x, int &mouse_y, else if(!(buttons & 512)) newkey = ' '; else if(!(buttons & 1024)) newkey = numpadmap[(buttons>>4)&15]; - if(!(buttons & 128)) mouse_x++; - if(!(buttons & 64)) mouse_x--; - if(!(buttons & 32)) mouse_y++; - if(!(buttons & 16)) mouse_y--; + if(!(buttons & 128)) if(inter) newkey = 1001; else mouse_x++; + if(!(buttons & 64)) if(inter) newkey = 1002; else mouse_x--; + if(!(buttons & 32)) if(inter) newkey = 1003; else mouse_y++; + if(!(buttons & 16)) if(inter) newkey = 1004; else mouse_y--; mouse_x += ((int)pad->cond.controller.joyx-128)>>4; mouse_y += ((int)pad->cond.controller.joyy-128)>>4; + + if(pad->cond.controller.ltrigger > 200) newkey = 1005; + else if(pad->cond.controller.rtrigger > 200) newkey = 1006; + } else if(pad->func & MAPLE_FUNC_MOUSE) { int buttons = pad->cond.mouse.buttons; @@ -107,13 +111,13 @@ int handleInput(struct mapledev *pad, int &mouse_x, int &mouse_y, exit(0); break; case 0x4f: - mouse_x++; break; + if(inter) newkey = 1001; else mouse_x++; break; case 0x50: - mouse_x--; break; + if(inter) newkey = 1002; else mouse_x--; break; case 0x51: - mouse_y++; break; + if(inter) newkey = 1003; else mouse_y++; break; case 0x52: - mouse_y--; break; + if(inter) newkey = 1004; else mouse_y--; break; case 0x63: newkey = '.'; break; case 0x64: case 0x87: @@ -124,6 +128,11 @@ int handleInput(struct mapledev *pad, int &mouse_x, int &mouse_y, } } + if(lmb && inter) { + newkey = 1000; + lmb = 0; + } + if(lmb && !lastlmb) { lastlmb = 1; return -OSystem::EVENT_LBUTTONDOWN; @@ -139,13 +148,24 @@ int handleInput(struct mapledev *pad, int &mouse_x, int &mouse_y, return -OSystem::EVENT_RBUTTONUP; } + if(newkey && inter && newkey != lastkey) { + int transkey = inter->key(newkey, shiftFlags); + if(transkey) { + newkey = transkey; + inter = NULL; + } + } + if(!newkey || (lastkey && newkey != lastkey)) { int upkey = lastkey; lastkey = 0; if(upkey) return upkey | (1<<30); - } else if(!lastkey) - return lastkey = newkey; + } else if(!lastkey) { + lastkey = newkey; + if(newkey >= 1000 || !inter) + return newkey; + } return 0; } @@ -164,11 +184,12 @@ bool OSystem_Dreamcast::poll_event(Event *event) _devpoll += USEC_TO_TIMER(17000); if(((int)(t-_devpoll))>=0) _devpoll = t + USEC_TO_TIMER(17000); + int mask = getimask(); setimask(15); checkSound(); int e = handleInput(locked_get_pads(), _ms_cur_x, _ms_cur_y, - event->kbd.flags); + event->kbd.flags, (_softkbd_on? &_softkbd : NULL)); setimask(mask); if (_ms_cur_x<0) _ms_cur_x=0; if (_ms_cur_x>=_screen_w) _ms_cur_x=_screen_w-1; @@ -185,12 +206,20 @@ bool OSystem_Dreamcast::poll_event(Event *event) event->event_code = (EventCode)-e; return true; } else if(e>0) { - event->event_code = ((e&(1<<30))? EVENT_KEYUP : EVENT_KEYDOWN); + bool processed = false, down = !(e&(1<<30)); e &= ~(1<<30); - event->kbd.keycode = e; - event->kbd.ascii = (e>='a' && e<='z' && (event->kbd.flags & KBD_SHIFT)? - e &~ 0x20 : e); - return true; + if(e < 1000) { + event->event_code = (down? EVENT_KEYDOWN : EVENT_KEYUP); + event->kbd.keycode = e; + event->kbd.ascii = (e>='a' && e<='z' && (event->kbd.flags & KBD_SHIFT)? + e &~ 0x20 : e); + processed = true; + } else if(down) { + if(e == 1005) + setFeatureState(kFeatureVirtualKeyboard, + !getFeatureState(kFeatureVirtualKeyboard)); + } + return processed; } else if(_ms_cur_x != _ms_old_x || _ms_cur_y != _ms_old_y) { event->event_code = EVENT_MOUSEMOVE; _ms_old_x = _ms_cur_x; diff --git a/backends/dc/softkbd.cpp b/backends/dc/softkbd.cpp new file mode 100644 index 0000000000..d601d2ba54 --- /dev/null +++ b/backends/dc/softkbd.cpp @@ -0,0 +1,157 @@ +/* ScummVM - Scumm Interpreter + * Dreamcast port + * Copyright (C) 2002-2004 Marcus Comstedt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + * + */ + +#include <common/stdafx.h> +#include <common/scummsys.h> +#include "base/engine.h" + +#include <ronin/ronin.h> +#include <string.h> +#include <assert.h> + +#include "dc.h" + + +extern void draw_trans_quad(float x1, float y1, float x2, float y2, + int c0, int c1, int c2, int c3); + + +static const char key_names[] = + "Esc\0F1\0F2\0F3\0F4\0F5\0F6\0F7\0F8\0F9\0F10\0" + "1\0!\0""2\0\"\0""3\0#\0""4\0$\0""5\0%\0" + "6\0&\0""7\0'\0""8\0(\0""9\0)\0""0\0~\0-\0=\0" + "q\0Q\0w\0W\0e\0E\0r\0R\0t\0T\0y\0Y\0u\0U\0i\0I\0o\0O\0p\0P\0@\0`\0" + "a\0A\0s\0S\0d\0D\0f\0F\0g\0G\0h\0H\0j\0J\0k\0K\0l\0L\0;\0+\0:\0*\0" + "z\0Z\0x\0X\0c\0C\0v\0V\0b\0B\0n\0N\0m\0M\0,\0<\0.\0>\0/\0?\0\\\0_\0" + "Shf\0Ctl\0Alt\0Space\0BS\0Ret"; + +#define K(a,b) ((a)|((b)<<8)) + +static const short key_codes[] = + { + 27, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + K('1','!'), K('2','"'), K('3','#'), K('4','$'), K('5','%'), + K('6','&'), K('7','\''), K('8','('), K('9',')'), K('0','~'), K('-','='), + K('q','Q'), K('w','W'), K('e','E'), K('r','R'), K('t','T'), + K('y','Y'), K('u','U'), K('i','I'), K('o','O'), K('p','P'), K('@','`'), + K('a','A'), K('s','S'), K('d','D'), K('f','F'), K('g','G'), + K('h','H'), K('j','J'), K('k','K'), K('l','L'), K(';','+'), K(':','*'), + K('z','Z'), K('x','X'), K('c','C'), K('v','V'), K('b','B'), + K('n','N'), K('m','M'), K(',','<'), K('.','>'), K('/','?'), K('\\','_'), + ~OSystem::KBD_SHIFT, ~OSystem::KBD_CTRL, ~OSystem::KBD_ALT, ' ', 8, 13 + }; + +SoftKeyboard::SoftKeyboard() : shiftState(0), keySel(0) +{ + assert((sizeof(key_codes)/sizeof(key_codes[0])) == SK_NUM_KEYS); + + const char *np = key_names; + for(int i=0; i<SK_NUM_KEYS; i++) { + labels[0][i].create_texture(np); + np += strlen(np)+1; + if(key_codes[i]>8192) { + labels[1][i].create_texture(np); + np += strlen(np)+1; + } + } +} + +void SoftKeyboard::draw(float x, float y, int transp) +{ + float x0; + int c = 0; + unsigned int txt_alpha_mask = (255-2*transp)<<24; + unsigned int bg_alpha_mask = (128-transp)<<24; + + draw_trans_quad(x, y, x+312.0, y+172.0, + bg_alpha_mask|0x8080ff, bg_alpha_mask|0x8080ff, + bg_alpha_mask|0x8080ff, bg_alpha_mask|0x8080ff); + x0 = x += 4.0; + y += 4.0; + for(int i=0; i<SK_NUM_KEYS; i++) { + float w = (i == 58? 164.0 : 24.0); + unsigned int bg = (i == keySel? bg_alpha_mask|0xffff00 : + bg_alpha_mask|0xc0c0ff); + draw_trans_quad(x, y, x+w, y+24.0, bg, bg, bg, bg); + if(key_codes[i]<0 && (shiftState & ~key_codes[i])) + labels[0][i].draw(x+2, y+5, txt_alpha_mask|0xffffff, 0.5); + else if(key_codes[i]>8192 && (shiftState & OSystem::KBD_SHIFT)) + labels[1][i].draw(x+2, y+5, txt_alpha_mask|0x000000, 0.5); + else + labels[0][i].draw(x+2, y+5, txt_alpha_mask|0x000000, 0.5); + x += w+4.0; + if(++c == 11) { + c = 0; + x = x0; + y += 28.0; + } + } +} + +int SoftKeyboard::key(int k, byte &shiftFlags) +{ + switch(k) { + case 1001: + if(++keySel == SK_NUM_KEYS) + keySel = 0; + break; + case 1002: + if(--keySel < 0) + keySel = SK_NUM_KEYS - 1; + break; + case 1003: + if(keySel >= 55) { + if(keySel > 58) + keySel += 5; + keySel -= 55; + } else if(keySel > 47) { + if((keySel += 6) < 59) + keySel = 59; + } else + keySel += 11; + break; + case 1004: + if(keySel > 58) + keySel -= 6; + else if((keySel -= 11) < 0) + if((keySel += 66) > 58) + if((keySel -= 5) < 59) + keySel = 59; + break; + case 1000: + case 13: + case 32: + case 319: + if(key_codes[keySel]<0) + shiftState ^= ~key_codes[keySel]; + else { + shiftFlags = shiftState; + if(key_codes[keySel] > 8192) + return ((shiftState & OSystem::KBD_SHIFT)? (key_codes[keySel]>>8): + key_codes[keySel]) & 0xff; + else + return key_codes[keySel]; + } + break; + } + return 0; +} diff --git a/backends/dc/softkbd.h b/backends/dc/softkbd.h new file mode 100644 index 0000000000..33b481683d --- /dev/null +++ b/backends/dc/softkbd.h @@ -0,0 +1,45 @@ +/* ScummVM - Scumm Interpreter + * Dreamcast port + * Copyright (C) 2002-2004 Marcus Comstedt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + * + */ + +#ifndef DC_SOFTKBD_H +#define DC_SOFTKBD_H + +#include "label.h" + +#define SK_NUM_KEYS 61 + +class SoftKeyboard : public Interactive +{ + private: + + Label labels[2][SK_NUM_KEYS]; + byte shiftState; + int8 keySel; + + public: + SoftKeyboard(); + + void draw(float x, float y, int transp = 0); + int key(int k, byte &shiftFlags); +}; + +#endif /* DC_SOFTKBD_H */ |