Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
OrbWorks Community Forum • View topic - Free Signature gadget

Free Signature gadget

Discuss OrbForms Designer and PocketC Architect

Postby jobie on Thu Jan 18, 2007 1:10 pm

I wrote this for a project I'm working on, and thought some of you might find it useful.

It's a signature gadget, but it has a very nice property; it can convert itself to/from an encoded string value suitable for use in CSV file.

Since a string is a naturally variable-length field, you don't have to perform any orbpdb gymnastics to import/export the signature; it is simply a string.

The signature is stored in vector form for compactness. A neat side effect is that when it gets redrawn, it is redrawn in the same way it was created...i.e. it's like watching a phantom write their name.

Anyway, feel free to use this in your own projects if you find it useful.

The methods intended for public use are:
* Reset() -- clears the signature
* ToHexString -- returns a hex-encoded string with the signature
* FromHexString -- takes a hex-encoded string and initializes

The downside is (at least on an old device) it can be a little slow, especially for complex signatures. This is partially due to the fact that I am using the hex function to create a string, but then I have to jump through some hoops to strip out the leading '0x' and do some checking/prepending to ensure that I'm left with a 2-digit hex value. For every vertex.

Anyway...here it is, warts and all.

begin sign_gadget.oc
--------------------------------------
Code: Select all
struct point
{
   int x, y;
};

struct signgadget
{
   // A UIGadget must always be the first member of a gadget
   UIGadget    gadget;
   point      Signature[1000];
   int         LastPt;
   
   point      RefPt;
   
   // Draw object
   Draw   draw;
   
   // events
   void onopen();
   void ondraw();
   void onpendown();
   void onpenup();
   void onpenmove();
   
   // public functions
   void    Reset( );
   string    ToHexString( );
   void   FromHexString( string H );
};

void signgadget.Reset( )
{
   LastPt = 0;
}

void signgadget.onopen()
{
   draw.attachGadget( gadget );
   
   draw.begin();
   draw.rect( clrBG, 0, 0, gadget.w-1, gadget.h-1, 0 );
   draw.frame( clrFG, 1, 1, gadget.w-1, gadget.h-1, 3, 1 );
   draw.end();
   //Reset();
}

void signgadget.ondraw()
{
   int i;

   draw.begin();

   draw.rect( clrBG, 0, 0, gadget.w-1, gadget.h-1, 0 );
   draw.frame( clrFG, 1, 1, gadget.w-1, gadget.h-1, 3, 1 );
   
   for ( i = 1; i < LastPt; i++ )
   {
      if ( (Signature[i-1].x) && (Signature[i].x) )
      {   
         draw.line( clrFG, Signature[i-1].x, Signature[i-1].y, Signature[i].x, Signature[i].y );
      }
   }
   
   draw.end();
}


void signgadget.onpendown()
{
   RefPt.x = event.x;
   RefPt.y = event.y;
   
   if ( LastPt < 990 )
   {   
      Signature[LastPt].x = event.x;
      Signature[LastPt].y = event.y;
      LastPt++;
   }
   
}

void signgadget.onpenup()
{
   if ( LastPt < 1000 )
   {
      Signature[LastPt].x = 0;
      Signature[LastPt].y = 0;
      LastPt++;
   }
}

void signgadget.onpenmove()
{
   if ( LastPt < 998 )
   {
      Signature[LastPt].x = event.x;
      Signature[LastPt].y = event.y;
      LastPt++;   
      
      draw.begin();
      draw.line( clrFG, RefPt.x, RefPt.y, event.x, event.y );
      draw.end();
      
      RefPt.x = event.x;
      RefPt.y = event.y;
   }
}

string signgadget.ToHexString( )
{
   int i;
   string res;
   string tmp;
   int l;
   
   for ( i = 0; i < LastPt; i++ )
   {
      tmp = hex(Signature[i].x);
      l = strlen(tmp);
      if ( l == 3 )
         res += ( "0" + strright(tmp, 1) );
      else
         res += ( strright(tmp, 2) );

      tmp = hex(Signature[i].y);
      l = strlen(tmp);
      if ( l == 3 )
         res += ( "0" + strright(tmp, 1) );
      else
         res += ( strright(tmp, 2) );
   }
   
   return res;
}

int DecodeHexDigit( char Digit )
{
   switch(Digit)
   {
      case '0':      return 0;
      case '1':      return 1;   
      case '2':      return 2;
      case '3':      return 3;
      case '4':      return 4;
      case '5':      return 5;
      case '6':      return 6;
      case '7':      return 7;
      case '8':      return 8;
      case '9':      return 9;
      case 'a':      return 10;
      case 'b':      return 11;
      case 'c':      return 12;
      case 'd':      return 13;
      case 'e':      return 14;
      case 'f':      return 15;
      default:
         break;
   }
   return -1;
}

void signgadget.FromHexString( string H )
{
   int i;
   int n;
   int c;
   string  res;
   char   ch[3];   // allow for null, not sure if it's there or not
   
   LastPt = 0;
   
   n = strlen(H);   
   
   for ( i = 0; i < n; i+=4 )
   {
      res = substr( H, i, 2 );
      c = strstoc( res, ch );
      Signature[LastPt].x = DecodeHexDigit(ch[0]) * 16 + DecodeHexDigit(ch[1]);
      res = substr( H, i+2, 2 );
      strstoc( res, ch );
      Signature[LastPt].y = DecodeHexDigit(ch[0]) * 16 + DecodeHexDigit(ch[1]);   
      LastPt++;
   }
}
jobie
 
Posts: 23
Joined: Wed Dec 27, 2006 8:53 pm
Location: USA

Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 2 guests

cron