r530 - in trunk/src/target/OM-2007/applications/openmoko-keyboard: layouts src

caowai_song at gta01.hmw-consulting.de caowai_song at gta01.hmw-consulting.de
Wed Jan 10 09:55:35 CET 2007


Author: caowai_song
Date: 2007-01-10 09:55:16 +0100 (Wed, 10 Jan 2007)
New Revision: 530

Added:
   trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/testkey.png
Modified:
   trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/keyboard.xml
   trunk/src/target/OM-2007/applications/openmoko-keyboard/src/config-parser.c
   trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-key.c
   trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-ui-xft-backend.c
   trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard.h
Log:
Add background image to the key.



Modified: trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/Makefile.am	2007-01-10 08:54:13 UTC (rev 529)
+++ trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/Makefile.am	2007-01-10 08:55:16 UTC (rev 530)
@@ -1,6 +1,6 @@
 keyboardsdir = $(datadir)/matchbox-keyboard
 keyboards_DATA = keyboard.xml keyboard-extended.xml keyboard-dvorak.xml \
 		 keyboard-us.xml keyboard-ru.xml keyboard-fi.xml        \
-                 keyboard-numpad.xml
+                 keyboard-numpad.xml testkey.png
 
-EXTRA_DIST = $(keyboards_DATA)
\ No newline at end of file
+EXTRA_DIST = $(keyboards_DATA)

Modified: trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/keyboard.xml
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/keyboard.xml	2007-01-10 08:54:13 UTC (rev 529)
+++ trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/keyboard.xml	2007-01-10 08:55:16 UTC (rev 530)
@@ -31,6 +31,7 @@
 
     <key fill="true">
 	  <default display="Esc" action="escape" />
+	  <background image="testkey.png"/>
     </key>
 <!--
     <key>
@@ -39,56 +40,69 @@
 -->
     <key>
 	  <default display="`" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="1" />                
 	  <shifted display="!" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="2" />                
 	  <shifted display='"' />
           <mod1    display="½" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="3" />
 	  <shifted display="£" />
           <mod1    display="¾" />               
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="4" />
 	  <shifted display="$" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="5" />
 	  <shifted display="%" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="6" />
 	  <shifted display="^" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="7" />
 	  <shifted display="&amp;" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="8" />
 	  <shifted display="*" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="9" />
 	  <shifted display="(" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="0" />
 	  <shifted display=")" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="-" />
 	  <shifted display="_" />                
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="=" />
 	  <shifted display="+" />                
+	  <background image="testkey.png"/>
     </key>
 
     <key fill="true">
@@ -119,55 +133,68 @@
     <key obey-caps='true'>
 	  <default display="q" />                
 	  <shifted display="Q" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="w" />                
 	  <shifted display="W" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <mod1 display="ë" />
 	  <default    display="e" />                
 	  <shifted display="E" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="r" />                
 	  <shifted display="R" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="t" />                
 	  <shifted display="T" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="y" />                
 	  <shifted display="Y" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="u" />                
 	  <shifted display="U" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="i" />                
 	  <shifted display="I" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="o" />                
 	  <shifted display="O" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="p" />                
 	  <shifted display="P" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="{" />                
 	  <shifted display="[" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="}" />                
 	  <shifted display="]" />
+	  <background image="testkey.png"/>
     </key>
     <key fill="true">
 	  <default display="\" />                
 	  <shifted display="|" />
+	  <background image="testkey.png"/>
     </key>
 
     <space width="500" extended="true"/>
@@ -192,46 +219,57 @@
     <key obey-caps='true'>
 	  <default display="a" />                
 	  <shifted display="A" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="s" />                
 	  <shifted display="S" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="d" />                
 	  <shifted display="D" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="f" />                
 	  <shifted display="F" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="g" />                
 	  <shifted display="G" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="h" />                
 	  <shifted display="H" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="j" />                
 	  <shifted display="J" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="k" />                
 	  <shifted display="K" />
+	  <background image="testkey.png"/>
     </key>
     <key obey-caps='true'>
 	  <default display="l" />                
 	  <shifted display="L" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display=";" />                
 	  <shifted display=":" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="#" />                
 	  <shifted display="~" />
+	  <background image="testkey.png"/>
     </key>
     <key fill="true">
 	  <default display="Ret" action="return"/>
@@ -258,49 +296,59 @@
     <key obey-caps='true'>
 	  <default display="z" />                
 	  <shifted display="Z" />
+	  <background image="testkey.png"/>
     </key>
 
     <key obey-caps='true'>
 	  <default display="x" />                
 	  <shifted display="X" />
+	  <background image="testkey.png"/>
     </key>
 
     <key obey-caps='true'>
 	  <default display="c" />                
 	  <shifted display="C" />
+	  <background image="testkey.png"/>
     </key>
 
     <key obey-caps='true'>
 	  <default display="v" />                
 	  <shifted display="V" />
+	  <background image="testkey.png"/>
     </key>
 
     <key obey-caps='true'>
 	  <default display="b" />                
 	  <shifted display="B" />
+	  <background image="testkey.png"/>
     </key>
 
     <key obey-caps='true'>
 	  <default display="n" />                
 	  <shifted display="N" />
+	  <background image="testkey.png"/>
     </key>
 
     <key obey-caps='true'>
 	  <default display="m" />                
 	  <shifted display="M" />
+	  <background image="testkey.png"/>
     </key>
 
     <key>
 	  <default display="," />                
 	  <shifted display="&lt;" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="." />                
 	  <shifted display="&gt;" />
+	  <background image="testkey.png"/>
     </key>
     <key>
 	  <default display="/" />                
 	  <shifted display="?" />
+	  <background image="testkey.png"/>
     </key>
 
 

Added: trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/testkey.png
===================================================================
(Binary files differ)


Property changes on: trunk/src/target/OM-2007/applications/openmoko-keyboard/layouts/testkey.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/src/target/OM-2007/applications/openmoko-keyboard/src/config-parser.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-keyboard/src/config-parser.c	2007-01-10 08:54:13 UTC (rev 529)
+++ trunk/src/target/OM-2007/applications/openmoko-keyboard/src/config-parser.c	2007-01-10 08:55:16 UTC (rev 530)
@@ -307,7 +307,41 @@
   return NULL;
 }
 
+static void
+config_handle_key_background_tag(MBKeyboardConfigState *state,
+                                 const char            *tag,
+                                 const char           **attr)
+{
+  MBKeyboardImage *img;
+  const char *val;
+  char  buf[512];
 
+  if ((val = attr_get_val("image", attr)) == NULL)
+    {
+      fprintf(stderr, "image=%s\n", val);
+      set_error(state, "Attribute 'image' is required");
+      return;
+    }
+
+  if (val[0] != '/')
+    {
+      snprintf(buf, 512, "%s/%s", PKGDATADIR, val);
+
+      if (!util_file_readable(buf))
+        snprintf(buf, 512, "%s/.matchbox/%s", getenv("HOME"), val);
+
+      img = mb_kbd_image_new (state->keyboard, buf);
+    }
+  else
+    {
+      img = mb_kbd_image_new (state->keyboard, val);
+    }
+  if (img == NULL)
+    fprintf(stderr, "load img fail\n");
+
+  mb_kbd_key_set_back_image(state->current_key, img);
+}
+
 static void
 config_handle_key_subtag(MBKeyboardConfigState *state,
 			 const char            *tag,
@@ -493,6 +527,7 @@
 config_handle_key_tag(MBKeyboardConfigState *state, const char **attr)
 {
   const char *val;
+  //MBKeyboardImage *img;
   DBG("got key");
 
   state->current_key = mb_kbd_key_new(state->keyboard);
@@ -521,6 +556,12 @@
 	mb_kbd_key_set_fill(state->current_key, True);
     }
 
+  /*FIXME: It is only temporary code */
+  //img = mb_kbd_image_new(state->keyboard, "/root/.matchbox/match.png");
+  //if(!img)
+    //fprintf(stderr, "can not find /root/.matchbox/match.png\n");
+  //mb_kbd_key_set_back_image(state->current_key, img);
+
   mb_kbd_row_append_key(state->current_row, state->current_key);
 }
 
@@ -546,6 +587,10 @@
       config_handle_key_tag(state, attr);
       mb_kbd_key_set_blank(state->current_key, True);
     }
+  else  if (streq(tag, "background"))
+    {
+      config_handle_key_background_tag(state, tag, attr);
+    }
   else if (streq(tag, "normal") 
 	   || streq(tag, "default")
 	   || streq(tag, "shifted")

Modified: trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-key.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-key.c	2007-01-10 08:54:13 UTC (rev 529)
+++ trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-key.c	2007-01-10 08:55:16 UTC (rev 530)
@@ -72,6 +72,8 @@
   boolean                is_blank;   /* 'blank' keys are spacers */
   boolean                extended;   /* only show in landscape */
 
+  MBKeyboardImage        *back_image;   /* The background image */
+
   MBKeyboardStateType    sets_kbdstate; /* needed */
 };
 
@@ -98,6 +100,18 @@
 }
 
 void
+mb_kbd_key_set_back_image(MBKeyboardKey *key, MBKeyboardImage *image)
+{
+  key->back_image = image;
+}
+
+MBKeyboardImage *
+mb_kbd_key_get_back_image(MBKeyboardKey *key)
+{
+  return key->back_image;
+}
+
+void
 mb_kbd_key_set_obey_caps(MBKeyboardKey  *key, boolean obey)
 {
   key->obeys_caps = obey;

Modified: trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-ui-xft-backend.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-ui-xft-backend.c	2007-01-10 08:54:13 UTC (rev 529)
+++ trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard-ui-xft-backend.c	2007-01-10 08:55:16 UTC (rev 530)
@@ -120,6 +120,8 @@
   Pixmap                 backbuffer;
   MBKeyboard            *kbd;
 
+  MBKeyboardImage       *image;
+
   if (mb_kbd_key_is_blank(key)) /* spacer */
     return;
 
@@ -149,65 +151,82 @@
 
   XFillRectangles(xdpy, backbuffer, xft_backend->xgc, &rect, 1);
 
-  /* draw 'main border' */
+  image = mb_kbd_key_get_back_image(key);
+  if(image)
+    {
+      int w, h;
+      w = mb_kbd_image_width (image);
+      h = mb_kbd_image_height (image);
 
-  XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_c5c5c5.pixel);
+      XRenderComposite(xdpy,
+                       PictOpOver,
+                       mb_kbd_image_render_picture (image),
+                       None, 
+                       XftDrawPicture (xft_backend->xft_backbuffer),
+                       0, 0, 0, 0, rect.x, rect.y, w, h);
+    }
+  else                   
+    {
+      /* draw 'main border' */
+      
+      XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_c5c5c5.pixel);
+      
+      XDrawRectangles(xdpy, backbuffer, xft_backend->xgc, &rect, 1);
+      
+      /* shaded bottom line */
+      
+      XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f4f4f4.pixel);
+      XDrawLine(xdpy, backbuffer, xft_backend->xgc,
+	        rect.x + 1,
+	        rect.y + rect.height - 1,
+	        rect.x + rect.width -2 ,
+	        rect.y + rect.height - 1);
+      
+      /* Corners - XXX should really use drawpoints */
+      
+      XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f0f0f0.pixel);
+      
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y);
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y);
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+rect.height);
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+rect.height);
+      
+      /* soften them more */
+      
+      XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_d3d3d3.pixel);
+      
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+1, rect.y);
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+1);
+      
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width-1, rect.y);
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+1);
+      
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width-1, rect.y+rect.height);
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+rect.height-1);
+      
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+rect.height-1);
+      XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+1, rect.y+rect.height);
 
-  XDrawRectangles(xdpy, backbuffer, xft_backend->xgc, &rect, 1);
+      /* background */
 
-  /* shaded bottom line */
+      if (mb_kbd_key_is_held(kbd, key))
+        XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_a4a4a4.pixel);
+      else
+        XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f8f8f5.pixel);
 
-  XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f4f4f4.pixel);
-  XDrawLine(xdpy, backbuffer, xft_backend->xgc,
-	    rect.x + 1,
-	    rect.y + rect.height - 1,
-	    rect.x + rect.width -2 ,
-	    rect.y + rect.height - 1);
+      side_pad = 
+        mb_kbd_keys_border(kbd)
+        + mb_kbd_keys_margin(kbd)
+        + mb_kbd_keys_pad(kbd);
 
-  /* Corners - XXX should really use drawpoints */
+      /* Why does below need +1's ? */
+      XFillRectangle(xdpy, backbuffer, xft_backend->xgc, 
+                     rect.x + side_pad,
+                     rect.y + side_pad,
+                     rect.width  - (side_pad * 2) + 1,
+                     rect.height - (side_pad * 2) + 1);
+    }
 
-  XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f0f0f0.pixel);
-
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y);
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y);
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+rect.height);
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+rect.height);
-
-  /* soften them more */
-
-  XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_d3d3d3.pixel);
-
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+1, rect.y);
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+1);
-
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width-1, rect.y);
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+1);
-
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width-1, rect.y+rect.height);
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+rect.width, rect.y+rect.height-1);
-
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x, rect.y+rect.height-1);
-  XDrawPoint(xdpy, backbuffer, xft_backend->xgc, rect.x+1, rect.y+rect.height);
-
-  /* background */
-
-  if (mb_kbd_key_is_held(kbd, key))
-    XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_a4a4a4.pixel);
-  else
-    XSetForeground(xdpy, xft_backend->xgc, xft_backend->xcol_f8f8f5.pixel);
-
-  side_pad = 
-    mb_kbd_keys_border(kbd)
-    + mb_kbd_keys_margin(kbd)
-    + mb_kbd_keys_pad(kbd);
-
-  /* Why does below need +1's ? */
-  XFillRectangle(xdpy, backbuffer, xft_backend->xgc, 
-		 rect.x + side_pad,
-		 rect.y + side_pad,
-		 rect.width  - (side_pad * 2) + 1,
-		 rect.height - (side_pad * 2) + 1);
-
   /* real code is here */
 
   state = mb_kbd_keys_current_state(kbd); 

Modified: trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard.h	2007-01-10 08:54:13 UTC (rev 529)
+++ trunk/src/target/OM-2007/applications/openmoko-keyboard/src/matchbox-keyboard.h	2007-01-10 08:55:16 UTC (rev 530)
@@ -392,6 +392,12 @@
 mb_kbd_key_new(MBKeyboard *kbd);
 
 void
+mb_kbd_key_set_back_image(MBKeyboardKey *key, MBKeyboardImage *image);
+
+MBKeyboardImage *
+mb_kbd_key_get_back_image(MBKeyboardKey *key);
+
+void
 mb_kbd_key_set_obey_caps(MBKeyboardKey  *key, boolean obey);
 
 boolean





More information about the commitlog mailing list