REM           3D User Interface by Alberto REM                   February 2016 REM_____________________________________________________ Rem ! Make sure to avoid to use the following VARIABLE names within ! your code: X_Offset - Y_Offset - Set_Col - Set_Row - Width !            Height - TSize - MSize - BtN - RSp - CSp - F_W !            F_H - DW - DH - F_W - F_H - Index - ac - ar - a  !            F_Skip - False - True  !________________________________________________________  gosub Matrix !------------------------------------------------------- !             Setting for Keyboard layout !------------------------------------------------------- Let X_Offset = 105                     % Offset X axis Let Y_Offset = 170                     % Offset Y axis   Let Set_Col = 6                       % Number of Columns (max 6)   Let Set_Row = 4                       % Number of Rows  (max 4)     Let Width = 165                     % Key width    Let Height = 95                      % Key height !---------------- Setting Keys Text ---------------------     Let TSize = 30                      % Font size (Key Text) Let Btxt$[1] = "Key 1" Let Btxt$[2] = "Key 2" Let Btxt$[3] = "Key 3" Let Btxt$[4] = "Key 4" Let Btxt$[5] = "Key 5" Let Btxt$[6] = "Key 6" Let Btxt$[7] = "Key 7" Let Btxt$[8] = "Key 8" Let Btxt$[9] = "Key 9" Let Btxt$[10] = "Key 10" Let Btxt$[11] = "Key 11" Let Btxt$[12] = "Key 12" Let Btxt$[13] = "Key 13" Let Btxt$[14] = "Key 14" Let Btxt$[15] = "Key 15" Let Btxt$[16] = "Key 16" Let Btxt$[17] = "Key 17" Let Btxt$[18] = "Key 18" Let Btxt$[19] = "Key 19" Let Btxt$[20] = "Key 20" Let Btxt$[21] = "Key 21" Let Btxt$[22] = "Key 22" Let Btxt$[23] = "Key 23" Let Btxt$[24] = "Key 24" !------------ Set User Interface Text ------------     Let MSize = 45                      % Font size    Let M_Txt$ = "User Interface"        % Text !------------------------------------------------- !           End of Keyboard layout setting !-------------------------------------------------    If Set_Col < 1 then Set_Col = 1    If Set_Col > 6 then Set_Col = 6    If Set_Row < 1 then Set_Row = 1    If Set_Row > 4 then Set_Row = 4          Let BtN = (Set_Col * Set_Row)            Let RSp = ((720-(Y_Offset+60))/Set_Row)    If Set_Col = 1 then       Let CSp = ((1280 - (2*X_Offset)-(Set_Col*Width))) + Width    else       Let CSp = ((1280 - (2*X_Offset)-(Set_Col*Width))/(Set_Col-1)) + Width    Endif gosub Fix_Col !------------------------------------------------------- !                Open Graphic Screen !-------------------------------------------------------       Let F_W = 1280       Let F_H = 720 GR.OPEN 255, 130, 130, 130,0 GR.ORIENTATION 0 Pause 200 gr.screen DW, DH        Let SW = DW/F_W        Let SH = DH/F_H gr.scale SW, SH gosub Draw_HMI !----------------- program loop starts here -------------- Main_Loop: pause 5 !--------------- Your code goes here --------------- ! Index will return the number of the Key pressed  ! If no Key is pressed, Index will return zero (0)      If Index = 1 then gosub Test_1 !    If Index = 2 then gosub your code label_2 !    If Index = 24 then gosub your code label_24 ! ! First thing your sub-routine will do is to set F_Skip ! flag to TRUE to disable the screen touch routine. ! If your sub-routine uses the graphic screen then ! you will need to use gr.cls and before returning ! you will need to gr.cls to clean your screen and ! you will gosub to re-draw the menu screen ! As an example see how the sub-routine works ! Sub_routine can be removed at any time! !---------------------------------------------------     Let Index = 0                       % Reset Index  goto Main_Loop !---------------- program loop ends here ---------------- !------------------------------------------------------- !                    Ini sub-routines  !------------------------------------------------------- Matrix:     Dim TT[24]     Dim RT[24]     Dim BT[24,4]     Dim X1[24,2]     Dim Y1[24,2]     Dim Btxt$[24]     Let Index = 0    Let F_Skip = 0     Let False = 0      Let True = 1 Return !------------------------------------------------------- Fix_Col:            ac = 0            ar = 0         for a = 1 to BtN   Let X1[a,1] = X_Offset + (CSp*ac)   Let Y1[a,1] = Y_Offset + (RSp*ar)    if Set_Col > ac then ++ac    if Set_Col = ac then ac = 0    if Set_Row > ar & ac = 0 then ++ar         next a Return !-------------------------------------------------------- !----------------------- Draw Key style ---------------- Draw_HMI: Let F_Skip = False                      % Enable touch gr.color 255,0,0,0 gr.line M00,60,50,1220,50 gr.line M01,60,50,60,660 gr.color 255,255,255,255 gr.line M00,60,660,1220,660 gr.line M01,1220,50,1220,660         For a = 1 to BtN GR.COLOR 255, 185, 185, 185, 1   Let X1[a,2] = X1[a,1] + Width   Let Y1[a,2] = Y1[a,1] + Height GR.RECT RT[a], X1[a,1], Y1[a,1], X1[a,2], Y1[a,2] GR.COLOR 255, 225, 225, 225,0 gr.set.stroke 4 gr.line BT[a,1], X1[a,2], Y1[a,1], X1[a,2], Y1[a,2] gr.line BT[a,2], X1[a,1], Y1[a,1], X1[a,2], Y1[a,1] gr.color 255, 30, 30, 30, 1 gr.set.stroke 3 gr.line BT[a,3], X1[a,1], Y1[a,1], X1[a,1], Y1[a,2] gr.set.stroke 6 gr.line BT[a,4], X1[a,1], Y1[a,2], X1[a,2], Y1[a,2] gr.color 255,80,0,0 gr.text.size TSize gr.text.align 2 gr.text.draw TT[a],X1[a,1]+((X1[a,2]-X1[a,1])/2),Y1[a,1]+((Y1[a,2]-Y1[a,1])/2)+12,Btxt$[a]                  next a gr.color 255,0,0,0 gr.text.size MSize gr.text.align 2 gr.text.draw MT1,640,(Y_Offset/2)+40,M_Txt$ gr.color 255,255,255,255 gr.text.size MSize gr.text.align 2 gr.text.draw MT2,646,(Y_Offset/2)+40,M_Txt$ GR.RENDER Return !------------------------------------------------------- Test_1:                                 % Just an example. To be removed  F_Skip = True gr.cls gr.color 255,0,0,0 gr.rect SA,60,50,1220,660 gr.render gr.color 255,255,255,255 gr.text.draw tst,100,350,"JUST A TEST" for a = 200 to 1050 step 10 gr.modify tst,"x",a gr.render pause 30 next a gr.cls gr.render F_Skip = False gosub draw_HMI return !---------------------------------------------------- !------------- 3D effect & Touch decode ------------- OnGrTouch:     if F_Skip = True then goto Skip_0     Let Index = False         for a = 1 to BtN gr.bounded.touch touched,X1[a,1]*SW,Y1[a,1]*SH,X1[a,2]*SW,Y1[a,2]*SH if touched then Let Index = a         next a      if Index = 0 Then goto Skip_All         Let a = Index Skip_0: GR.TOUCH touched, x, y if F_Skip = True then goto Skip_1 gr.modify BT[a,1],"x1",X1[a,1],"y1",Y1[a,1],"x2",X1[a,1],"y2",Y1[a,2] gr.modify BT[a,2],"x1",X1[a,1],"y1",Y1[a,2],"x2",X1[a,2],"y2",Y1[a,2] gr.modify BT[a,3],"x1",X1[a,2],"y1",Y1[a,1],"x2",X1[a,2],"y2",Y1[a,2] gr.modify BT[a,4],"x1",X1[a,1],"y1",Y1[a,1],"x2",X1[a,2],"y2",Y1[a,1] gr.render Tone 600,80,0 Skip_1: DO GR.TOUCH touched, xx, yy UNTIL !touched if F_Skip = True then goto Skip_All gr.modify BT[a,1],"x1",X1[a,2],"y1",Y1[a,1],"x2",X1[a,2],"y2",Y1[a,2] gr.modify BT[a,2],"x1",X1[a,1],"y1",Y1[a,1],"x2",X1[a,2],"y2",Y1[a,1] gr.modify BT[a,3],"x1",X1[a,1],"y1",Y1[a,1],"x2",X1[a,1],"y2",Y1[a,2] gr.modify BT[a,4],"x1",X1[a,1],"y1",Y1[a,2],"x2",X1[a,2],"y2",Y1[a,2] gr.render Skip_All: Gr.onGrTouch.Resume !------------------------ End of code ------------------ end