[Scummvm-cvs-logs] CVS: scummvm/backends/dc softkbd.cpp,NONE,1.1 softkbd.h,NONE,1.1 Makefile,1.22,1.23 dc.h,1.25,1.26 dcmain.cpp,1.25,1.26 display.cpp,1.20,1.21 input.cpp,1.17,1.18

Marcus Comstedt marcus_c at users.sourceforge.net
Sun Mar 14 14:28:34 CET 2004


Update of /cvsroot/scummvm/scummvm/backends/dc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1207

Modified Files:
	Makefile dc.h dcmain.cpp display.cpp input.cpp 
Added Files:
	softkbd.cpp softkbd.h 
Log Message:
Virtual keyboard.

--- NEW FILE: softkbd.cpp ---
/* 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: /cvsroot/scummvm/scummvm/backends/dc/softkbd.cpp,v 1.1 2004/03/14 22:16:22 marcus_c Exp $
 *
 */

#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;
}

--- NEW FILE: softkbd.h ---
/* 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: /cvsroot/scummvm/scummvm/backends/dc/softkbd.h,v 1.1 2004/03/14 22:16:22 marcus_c Exp $
 *
 */

#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 */

Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/dc/Makefile,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- Makefile	13 Mar 2004 15:19:16 -0000	1.22
+++ Makefile	14 Mar 2004 22:16:22 -0000	1.23
@@ -10,7 +10,7 @@
 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 @@
 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 += .
 

Index: dc.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/dc/dc.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- dc.h	14 Mar 2004 13:14:03 -0000	1.25
+++ dc.h	14 Mar 2004 22:16:22 -0000	1.26
@@ -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 @@
 
  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 @@
   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 @@
   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 &);
 

Index: dcmain.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/dc/dcmain.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- dcmain.cpp	13 Mar 2004 17:32:28 -0000	1.25
+++ dcmain.cpp	14 Mar 2004 22:16:22 -0000	1.26
@@ -47,7 +47,7 @@
 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 @@
       setScaling();
     break;
   case kFeatureVirtualKeyboard:
-    /* FIXME */
+    _softkbd_on = enable;
     break;
   default:
     break;
@@ -178,8 +178,7 @@
   case kFeatureAspectRatioCorrection:
     return _aspect_stretch;
   case kFeatureVirtualKeyboard:
-    /* FIXME */
-    return false;
+    return _softkbd_on;
   default:
     return false;
   }

Index: display.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/dc/display.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- display.cpp	13 Mar 2004 17:32:28 -0000	1.20
+++ display.cpp	14 Mar 2004 22:16:22 -0000	1.21
@@ -419,6 +419,19 @@
     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;

Index: input.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/dc/input.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- input.cpp	13 Mar 2004 17:32:28 -0000	1.17
+++ input.cpp	14 Mar 2004 22:16:22 -0000	1.18
@@ -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 @@
       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 @@
 	    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 @@
       }
     }
 
+  if(lmb && inter) {
+    newkey = 1000;
+    lmb = 0;
+  }
+
   if(lmb && !lastlmb) {
     lastlmb = 1;
     return -OSystem::EVENT_LBUTTONDOWN;
@@ -139,13 +148,24 @@
     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 @@
   _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 @@
     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;





More information about the Scummvm-git-logs mailing list