Page 1 of 1

Touchscreen numpad with DCPUSHBUTTON

Posted: Tue Aug 09, 2016 11:15 am
by Leon Berger
A touchscreen numpad with DCPUSHBUTTONs

Image

Code: Select all

//////////////////////////////////////////////////////////////////////
//
//  CALC.PRG
//
//  Made by:
//      Leon Berger, 2016
//
//  Inhalt:
//      Touchscreen Numpad
//
//////////////////////////////////////////////////////////////////////

#include 'inkey.ch'
#include 'dccolor.ch'
#include 'appevent.ch'
#include 'gra.ch'
#include 'xbp.ch'
#include 'dcmsg.ch'
#include 'dcdialog.ch'

#define COLOR_RED        GraMakeRGBColor( { 255,   0,   0 } )
#define COLOR_DARKRED    GraMakeRGBColor( { 127,   0,   0 } )
#define COLOR_GREEN      GraMakeRGBColor( {   0, 255,   0 } )
#define COLOR_DARKGREEN  GraMakeRGBColor( {   0, 127,   0 } )
#define COLOR_BLUE       GraMakeRGBColor( {   0,   0, 255 } )
#define COLOR_DARKBLUE   GraMakeRGBColor( {   0,   0, 127 } )
#define COLOR_CYAN       GraMakeRGBColor( {   0, 255, 255 } )
#define COLOR_DARKCYAN   GraMakeRGBColor( {   0, 127, 127 } )
#define COLOR_YELLOW     GraMakeRGBColor( { 255, 255,   0 } )
#define COLOR_BROWN      GraMakeRGBColor( { 127, 127,   0 } )
#define COLOR_PINK       GraMakeRGBColor( { 255,   0, 255 } )
#define COLOR_DARKPINK   GraMakeRGBColor( { 127,   0, 127 } )
#define COLOR_WHITE      GraMakeRGBColor( { 255, 255, 255 } )
#define COLOR_BLACK      GraMakeRGBColor( {   0,   0,   0 } )
#define COLOR_PALEGRAY   GraMakeRGBColor( { 192, 192, 192 } )
#define COLOR_DARKGRAY   GraMakeRGBColor( { 127, 127, 127 } )
#define COLOR_ORANGE     GraMakeRGBColor( { 253, 120,  41 } )
#define COLOR_LTORANGE   GraMakeRGBColor( { 250, 205,   0 } )
#define COLOR_LTBLUE     GraMakeRGBColor( {  30, 187, 255 } )
#define COLOR_LTYELLOW   GraMakeRGBColor( { 128, 128,   0 } )
#define COLOR_DKYELLOW   GraMakeRGBColor( { 212, 212,   0 } )
#define COLOR_DKYELLOW2  GraMakeRGBColor( { 170, 170,   0 } )
#define COLOR_DKBROWN    GraMakeRGBColor( {  72,  72,   0 } )
#define COLOR_SLATEGRAY  GraMakeRGBColor( { 158, 182, 205 } )
#define COLOR_SILVER     GraMakeRGBColor( { 192, 192, 192 } )
#define COLOR_ICEGREEN   GraMakeRGBColor( { 222, 255, 189 } )

FUNCTION MAIN(nValue, lKomma, lMinus, aText, NoZero)
 * NumPadGui(nValue, lKomma, lMinus, {"Line 1 with text"}, .T.)
   NumPadGui(nValue, lKomma, lMinus, {"Line 1 with Text","Line 2 with text"}, .T.)
RETURN nValue


FUNCTION NumPadGui(nValue, lKomma, lMinus, aText, NoZero)
   LOCAL GetList := {}, GetOptions, nSaveValue, oCancelButton, ;
         cFont, cValue, lStatus, nZeile := 0, nLine := 0

   PRIVATE nAccum := nValue
   PRIVATE lFirstTime := .t.

   DEFAULT nValue := 0
   DEFAULT lKomma := .t.
   DEFAULT lMinus := .t.
   DEFAULT aText := {}
   DEFAULT NoZero := .f.

   SET CENTURY ON
   SET DATE TO GERMAN
   SET DELETED ON
   SET EXCLUSIVE OFF
   SET EPOCH to 1980
   DC_LangSet(DCLANG_GERMAN)

   cFont := '12.Arial Bold'

   nSaveValue := nValue

   cValue := Alltrim(Str(nValue))
   cValue := PadL(cValue,22)

   for nZeile := 1 to len(aText)
      nLine += 1
   next

   do case
   case nLine = 1
      @  -2, 0 DCSAY padr(atext[1],36);
         SAYFONT "15.Verdana";
         SAYSIZE 0;
         SAYCOLOR {||{COLOR_DARKBLUE,GRA_CLR_BACKGROUND}}
   case nLine = 2
      @  -3.5, 0 DCSAY padr(atext[1],36);
         SAYFONT "15.Verdana";
         SAYSIZE 0;
         SAYCOLOR {||{COLOR_DARKBLUE,GRA_CLR_BACKGROUND}}
         *SAYCOLOR {||{GRA_CLR_BLUE,GRA_CLR_BACKGROUND}}
      @  -2, 0 DCSAY padr(atext[2],36);
         SAYFONT "15.Verdana";
         SAYSIZE 0;
         SAYCOLOR {||{COLOR_DARKBLUE,GRA_CLR_BACKGROUND}}
   endcase

   @  -10, 0 DCGET cValue PICTURE REPL("X", 22) ;
      GETFONT "20.Verdana";
      PIXEL ;
      GETSIZE 380,45;
      GETCOLOR {||{GRA_CLR_BLUE,GRA_CLR_WHITE}};
      EDITPROTECT {||.t.} ID 'ACCUM'

   @  50,  0 DCPUSHBUTTON CAPTION '7' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(7,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('7')

   @  50, 90 DCPUSHBUTTON CAPTION '8' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(8,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('8')

   @  50,180 DCPUSHBUTTON CAPTION '9' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(9,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('9')

   @ 140,  0 DCPUSHBUTTON CAPTION '4' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(4,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('4')

   @ 140, 90 DCPUSHBUTTON CAPTION '5' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(5,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('5')

   @ 140,180 DCPUSHBUTTON CAPTION '6' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(6,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('6')

   @ 230,  0 DCPUSHBUTTON CAPTION '1' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(1,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('1')

   @ 230, 90 DCPUSHBUTTON CAPTION '2' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(2,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('2')

   @ 230,180 DCPUSHBUTTON CAPTION '3' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(3,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('3')

   @ 320, 0 DCPUSHBUTTON CAPTION '.' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(10,@cValue,GetList),DC_GetRefresh(GetList)} ;
      WHEN {||lKomma} ;
      HIDE {||lKomma = .f.} ;
      ACCELKEY 46

   @ 320, 90 DCPUSHBUTTON CAPTION '0' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(0,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY Asc('0')

   @ 320,180 DCPUSHBUTTON CAPTION '-' FONT cFont SIZE 80,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_LTBLUE;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(11,@cValue,GetList),DC_GetRefresh(GetList)} ;
      WHEN {||lMinus} ;
      HIDE {||lMinus = .f.} ;
      ACCELKEY 45

   @  50,280 DCPUSHBUTTON CAPTION 'CL' FONT cFont SIZE 100,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_PALEGRAY;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(12,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY { 67, 99 }

   @ 140,280 DCPUSHBUTTON CAPTION 'BS' FONT cFont SIZE 100,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_PALEGRAY;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {||Accum(13,@cValue,GetList),DC_GetRefresh(GetList)} ;
      ACCELKEY 8

   @ 230,280 DCPUSHBUTTON CAPTION 'ENTER' FONT cFont SIZE 100,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_GREEN;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACCELKEY 13 ;
      WHEN {|| (val(cValue) # 0 .and. NoZero) .or. NoZero = .F.} ;
      ACTION {||DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}

   @ 320,280 DCPUSHBUTTON CAPTION 'Esc' FONT cFont SIZE 100,80 PIXEL ;
      GRADIENT 5;
      RADIUS 10;
      COLOR COLOR_BLACK, COLOR_RED;
      MOUSECOLOR COLOR_BLACK, COLOR_LTORANGE;
      CLICKCOLOR COLOR_BLUE, COLOR_ORANGE;
      SELECTCOLOR COLOR_BLUE, COLOR_ORANGE;
      BORDERCOLOR {255,153, 51};
      FONT "18.Verdana";
      ACTION {|| DC_ReadGuiEvent(DCGUI_EXIT_ABORT,GetList)} ;
      ACCELKEY 27 ;
      OBJECT oCancelButton

    DCGETOPTIONS ;
       AUTORESIZE;
       NOMINBUTTON;
       NOMAXBUTTON;
       HIDE
       *NOTITLE ;

    DCREAD GUI FIT MODAL ;
           TITLE "Touch-number-pad" ;
           SETFOCUS @oCancelButton ;
           TO lStatus ;
           OPTIONS GetOptions ;
           EVAL {|o|DC_CenterObject(o,SetAppWindow()), ;
              o:show()}

   IF !lStatus
      nValue := nSaveValue
   ELSE
      nValue := Val(cValue)
   ENDIF

RETURN nValue

* --------------


* ----------------

STATIC FUNCTION Accum ( nKey, cValue, GetList )

   IF m->lFirstTime .AND. nKey # 20
      cValue := ''
   ELSE
      cValue := Alltrim(cValue)
   ENDIF

   m->lFirstTime := .f.


   IF nKey >= 0 .AND. nKey <= 9

      cValue += Alltrim(Str(nKey))

   ELSEIF nKey == 10 // Decimal key

      cValue := StrTran(cValue,'.','')
      cValue += '.'

   ELSEIF nKey == 11 // Minus Key

      IF Left(cValue,1) == '-'
         cValue := Substr(cValue,2)
      ELSE
         cValue := '-' + cValue
      ENDIF

   ELSEIF nKey == 12 // Clear

      cValue := ''

   ELSEIF nKey == 13 // Backspace

      cValue := Substr(cValue,1,Len(cValue)-1)

   ELSEIF nKey == 20 .AND. !('%'$cValue) // Percent

      cValue += '%'

   ENDIF

   cValue := Trim(cValue)

   IF '%' $ cValue
      cValue := Strtran(cValue,'%','') + '%'
   ENDIF

   cValue := PadL(cValue,22)

   DC_GetRefresh(GetList,'ACCUM')

RETURN nil


PROCEDURE AppSys
RETURN            
PROJECT.XPJ File:

Code: Select all

[PROJECT]
    DEBUG         = No
    VERSION       = 1.0;0.0
    GUI           = yes
    COMPILE       = xpp
    COMPILE_FLAGS = -q -w -wu
    DEBUG_SAVE    = no
    GUI           = yes
    LINKER        = alink
    LINK_FLAGS    =
    RC_COMPILE    = arc
    RC_FLAGS      = -v
    CALC.XPJ

[CALC.XPJ]
    CALC.EXE

[CALC.EXE]
    calc.obj
    DCLIP1.LIB
    DCLIPX.LIB
    calc.prg

Re: Touchscreen numpad with DCPUSHBUTTON

Posted: Tue Aug 09, 2016 12:55 pm
by rdonnay
Leon -

Very nice!!!

Thank you for your contribution.

I will add it to the samples in the next release.