Processing key input on a do loop
#9
(04-22-2023, 02:30 PM)TerryRitchie Wrote:
(04-22-2023, 11:48 AM)NasaCow Wrote: Terry,

This is exactly what I need. I love it! And I always like your documentation files, already printed and sitting next to my machine, studying up on everything. I also updated your file to work with EXPLICIT and NOPREFIX. Not much needed changing but just in case you want to add it to your library....


[Image: ff92f1bfaa8fe09b2e60f2e12a5e634.jpg]

Thanks again for sharing! I might have to go back through and update some other parts of my code with this awesome library!

You are most welcome. Thank you for sharing the changes you made to the code. I need to revisit it as well since I wrote it so long ago. I've gotten much better at coding with QB64 since then.

Hi Terry! I have been using your library for a few days and if you do revisit it, I do have a few thoughts. It would be awesome to add some kind of text wrapping to it. That would make it great for larger input, perhaps add an X-Y for the area like a LINE ,,B style (like for a comment box!) Also, it seems to race the CPU. I added three _LIMIT 60 commands, one in each DO LOOP I saw and that seems to really settle it down. Finally, hopefully an easy question, assuming you can remember the good old days when you coded it. How can I customize the allowed input for a flag. I want to make some a little bit more restrictive...

And here is a preview of what I am building right now, the add assignment screen. Hoping to show a working prototype soon.

[Image: image.png]

Here is the code (still working on it, still want to do a lot on this screen alone...) I know it isn't polished yet but I couldn't make it happen without this gem of a library so thanks again! Don't forget the include files in a subdirectory of ./include

Code: (Select All)
$DEBUG
$NOPREFIX
'$DYNAMIC
OPTION EXPLICIT
OPTION BASE 1


'$Include:'./include/Base64.bi'
'$include:'./include/Qprint.bi'
'$include:'./include/glinputtop.bi'

CONST FALSE = 0, TRUE = NOT FALSE

DIM AS STRING Buffer
DIM AS LONG BGImage

'Assignments for all students, populates the top of the gradebook
TYPE MasterAssignmentType
    ARName AS STRING * 20 'Assignment report name
    ADName AS STRING * 10 'Assignment display name (short name)
    AType AS UNSIGNED BYTE 'Assignment Type (Completeion, formative, summative, etc.)
    ACat AS STRING * 20 'Assignment Category (subject, unit, etc)
    AColor AS UNSIGNED BYTE 'Color coding assignment headers and for grouping for reports
    ACode AS UNSIGNED BYTE 'Reserved
    APts AS UNSIGNED INTEGER 'Total points allowed
    AWght AS UNSIGNED INTEGER 'For weighted assignments/100 = 100%
    Month AS UNSIGNED INTEGER
    Day AS UNSIGNED INTEGER
    Year AS UNSIGNED INTEGER
    AID AS INTEGER64 'Unique assignment ID
    ADetails AS STRING * 4096 'Space to write instructions for an assignment sheet to print.
END TYPE

'====================Flag codes====================
'1   - Extra credit allowed/Ignore pts allowed    |
'2   - Include in final grade                     |
'4   - Excuse All/Ignore/Shown on reports flagged |
'8   - Hidden/Future dated/Exclude from reports   |
'16  - Weighted                                   |
'32  - Reserved                                   |
'64  - Reserved                                   |
'128 - Reserved                                   |
'==================================================


RESTORE Blank
Buffer = LoadResource
BGImage = LOADIMAGE(Buffer, 32, "memory")
SCREEN NEWIMAGE(1280, 720, 32)
SCREENMOVE 0, 0
DIM AS INTEGER Count


'Sub Start
TYPE InputInfoType
    Response AS STRING
    Allowed AS INTEGER
    Required AS INTEGER
END TYPE

DIM AS STRING Titlee, Qu
DIM AS INTEGER X, Y, Counter, Al
DIM AS LONG GLInput(1 TO 14), AddImage, MainScreen
DIM AS INTEGER Re
REDIM AS InputInfoType InputInfo(0)

MainScreen = NEWIMAGE(1280, 720, 32)
SCREEN MainScreen

AddImage = NEWIMAGE(1280, 720, 32)
DEST AddImage

Titlee = "Add Assignment"
FONT LOADFONT("script.ttf", 60)

CLS

PUTIMAGE , BGImage

'Title of the page
'-------Title Box-----
QPrintString 640 - QPrintWidth(Titlee) / 2, 30, Titlee

'Top right quad
CIRCLES 840, 54, 20, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 840, 54, 21, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 840, 54, 22, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 840, 54, 23, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 840, 54, 24, RGB32(255, 255, 255), 0, 0.5 * PI, 1

'Top left quad
CIRCLES 440, 54, 20, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 440, 54, 21, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 440, 54, 22, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 440, 54, 23, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 440, 54, 24, RGB32(255, 255, 255), 0.5 * PI, PI, 1

'Bottom left quad
CIRCLES 440, 74, 20, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 440, 74, 21, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 440, 74, 22, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 440, 74, 23, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 440, 74, 24, RGB32(255, 255, 255), PI, PI * 1.5, 1

'Bottom right quad
CIRCLES 840, 74, 20, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 840, 74, 21, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 840, 74, 22, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 840, 74, 23, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 840, 74, 24, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1

'Connect the quads
LINE (440, 98)-(840, 94), , BF 'Bottom
LINE (416, 54)-(420, 74), , BF 'Left
LINE (860, 54)-(864, 74), , BF 'Right
'------End Title Box------

'------Large Title Box-----
'Top right quad
CIRCLES 1220, 54, 20, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 1220, 54, 21, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 1220, 54, 22, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 1220, 54, 23, RGB32(255, 255, 255), 0, 0.5 * PI, 1
CIRCLES 1220, 54, 24, RGB32(255, 255, 255), 0, 0.5 * PI, 1

'Top left quad
CIRCLES 58, 54, 20, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 58, 54, 21, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 58, 54, 22, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 58, 54, 23, RGB32(255, 255, 255), 0.5 * PI, PI, 1
CIRCLES 58, 54, 24, RGB32(255, 255, 255), 0.5 * PI, PI, 1

'Bottom left quad
CIRCLES 58, 665, 20, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 58, 665, 21, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 58, 665, 22, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 58, 665, 23, RGB32(255, 255, 255), PI, PI * 1.5, 1
CIRCLES 58, 665, 24, RGB32(255, 255, 255), PI, PI * 1.5, 1

'Bottom right quad
CIRCLES 1220, 665, 20, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 1220, 665, 21, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 1220, 665, 22, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 1220, 665, 23, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1
CIRCLES 1220, 665, 24, RGB32(255, 255, 255), PI * 1.5, 2 * PI, 1

'Connect the quads
LINE (58, 34)-(1220, 30), , BF 'Top
LINE (58, 685)-(1220, 689), , BF 'Bottom
LINE (34, 54)-(38, 665), , BF 'Left
LINE (1240, 54)-(1244, 665), , BF 'Right
'-------End Large Title Box------

FONT LOADFONT("arial.ttf", 32)

'Building the text on screen
X = 45: Y = 65

'Box for instructions
LINE (75, 600)-(1000, 684), Black, BF
LINE (45, Y + QFontHeight * 9.75)-(1235, 683), White, B

'Set the flags for the data field
RESTORE AAss

FOR Counter = 1 TO 5
    READ Qu, Al, Re
    IF Re THEN
        COLOR White
    ELSE
        COLOR RGB32(212, 212, 0)
    END IF
    GLInput(Counter) = GLIINPUT(X, Y + FONTHEIGHT * 1.2 * Counter, Al, Qu, TRUE)
    IF GLInput(Counter) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(Counter)) AS InputInfoType
    InputInfo(Counter).Required = Re
    InputInfo(Counter).Allowed = Al
    InputInfo(Counter).Response = ""
NEXT Counter

'Score type selection
QPrintString X + 220, Y + FONTHEIGHT * 1.2 * (Counter - 2), "Points"
CIRCLES X + 205, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 10, White, 0, 2 * PI, 1
CIRCLES X + 205, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 9, White, 0, 2 * PI, 1

QPrintString X + 370, Y + FONTHEIGHT * 1.2 * (Counter - 2), "Percentage"
CIRCLES X + 355, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 10, White, 0, 2 * PI, 1
CIRCLES X + 355, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 9, White, 0, 2 * PI, 1

QPrintString X + 610, Y + FONTHEIGHT * 1.2 * (Counter - 2), "Completion"
CIRCLES X + 595, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 10, White, 0, 2 * PI, 1
CIRCLES X + 595, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 9, White, 0, 2 * PI, 1

QPrintString X + 850, Y + FONTHEIGHT * 1.2 * (Counter - 2), "Letter"
CIRCLES X + 835, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 10, White, 0, 2 * PI, 1
CIRCLES X + 835, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 9, White, 0, 2 * PI, 1

QPrintString X + 1010, Y + FONTHEIGHT * 1.2 * (Counter - 2), "Free Entry"
CIRCLES X + 995, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 10, White, 0, 2 * PI, 1
CIRCLES X + 995, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 2), 9, White, 0, 2 * PI, 1

'Include in final selection
QPrintString X + 370, Y + FONTHEIGHT * 1.2 * (Counter - 1), "Yes"
CIRCLES X + 355, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 10, White, 0, 2 * PI, 1
CIRCLES X + 355, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 9, White, 0, 2 * PI, 1

QPrintString X + 470, Y + FONTHEIGHT * 1.2 * (Counter - 1), "No"
CIRCLES X + 455, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 10, White, 0, 2 * PI, 1
CIRCLES X + 455, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 9, White, 0, 2 * PI, 1


'Extra points allowed
READ Qu, Al, Re
COLOR White
GLInput(6) = GLIINPUT(X + 600, Y + FONTHEIGHT * 1.2 * (Counter - 1), Al, Qu, TRUE)
IF GLInput(6) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(6)) AS InputInfoType
InputInfo(6).Required = Re
InputInfo(6).Allowed = Al
InputInfo(6).Response = ""

QPrintString X + 935, Y + FONTHEIGHT * 1.2 * (Counter - 1), "Yes"
CIRCLES X + 920, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 10, White, 0, 2 * PI, 1
CIRCLES X + 920, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 9, White, 0, 2 * PI, 1

QPrintString X + 1070, Y + FONTHEIGHT * 1.2 * (Counter - 1), "No"
CIRCLES X + 1055, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 10, White, 0, 2 * PI, 1
CIRCLES X + 1055, Y + FONTHEIGHT * .5 + FONTHEIGHT * 1.2 * (Counter - 1), 9, White, 0, 2 * PI, 1

'Weight
READ Qu, Al, Re
COLOR White
GLInput(7) = GLIINPUT(X, Y + FONTHEIGHT * 1.2 * (Counter), Al, Qu, TRUE)
IF GLInput(7) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(7)) AS InputInfoType
InputInfo(7).Required = Re
InputInfo(7).Allowed = Al
InputInfo(7).Response = ""

'Due date mont
READ Qu, Al, Re
COLOR White
GLInput(8) = GLIINPUT(X, Y + FONTHEIGHT * 1.2 * (Counter + 1), Al, Qu, TRUE)
IF GLInput(8) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(8)) AS InputInfoType
InputInfo(8).Required = Re
InputInfo(8).Allowed = Al
InputInfo(8).Response = ""

'Dayh
READ Qu, Al, Re
COLOR White
GLInput(9) = GLIINPUT(X + 407, Y + FONTHEIGHT * 1.2 * (Counter + 1), Al, Qu, TRUE)
IF GLInput(9) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(9)) AS InputInfoType
InputInfo(9).Required = Re
InputInfo(9).Allowed = Al
InputInfo(9).Response = ""

'Year
READ Qu, Al, Re
COLOR White
GLInput(10) = GLIINPUT(X + 472, Y + FONTHEIGHT * 1.2 * (Counter + 1), Al, Qu, TRUE)
IF GLInput(10) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(10)) AS InputInfoType
InputInfo(10).Required = Re
InputInfo(10).Allowed = Al
InputInfo(10).Response = ""

'Assigned date month
READ Qu, Al, Re
COLOR White
GLInput(11) = GLIINPUT(X + 550, Y + FONTHEIGHT * 1.2 * (Counter + 1), Al, Qu, TRUE)
IF GLInput(11) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(11)) AS InputInfoType
InputInfo(11).Required = Re
InputInfo(11).Allowed = Al
InputInfo(11).Response = ""

'Day
READ Qu, Al, Re
COLOR White
GLInput(12) = GLIINPUT(X + 950, Y + FONTHEIGHT * 1.2 * (Counter + 1), Al, Qu, TRUE)
IF GLInput(12) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(12)) AS InputInfoType
InputInfo(12).Required = Re
InputInfo(12).Allowed = Al
InputInfo(12).Response = ""

'Year
READ Qu, Al, Re
COLOR White
GLInput(13) = GLIINPUT(X + 1015, Y + FONTHEIGHT * 1.2 * (Counter + 1), Al, Qu, TRUE)
IF GLInput(13) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(13)) AS InputInfoType
InputInfo(13).Required = Re
InputInfo(13).Allowed = Al
InputInfo(13).Response = ""

'Comments/Instruction
READ Qu, Al, Re
COLOR RGB32(212, 212, 0)
QPrintString X, Y + FONTHEIGHT * 1.18 * (Counter + 2), "Instruction/Description"
GLInput(14) = GLIINPUT(X, Y + FONTHEIGHT * 1.2 * (Counter + 3), Al, Qu, TRUE)
IF GLInput(14) > UBOUND(InputInfo) THEN REDIM PRESERVE InputInfo(GLInput(14)) AS InputInfoType
InputInfo(14).Required = Re
InputInfo(14).Allowed = Al
InputInfo(14).Response = ""

DEST MainScreen

GLICLOSE GLInput(4), FALSE
GLICLOSE GLInput(5), FALSE
GLICLOSE GLInput(6), FALSE


DO
    LIMIT 60
    GLICLEAR
    PUTIMAGE , AddImage
    GLIUPDATE
    DISPLAY
LOOP

'-----------End Sub----------------
SLEEP
SYSTEM

AAss:
DATA "Assignment Name: ",31,-1
DATA "Assignmnet Short Name: ",31,-1
DATA "Maximum Points Allowed: ",2,-1
DATA "Score Type",33,-1
DATA "Include in Final Grade",33,-1
DATA "Extra Points Allowed",33,-1
DATA "Weight (100 = 100%): ",2,-1
DATA "Due Date MM/DD/YY: ",2,-1
DATA " / ",2,-1
DATA " / ",2,-1
DATA "Assigned Date MM/DD/YY: ",2,-1
DATA " / ",2,-1
DATA " / ",2,-1
DATA "",29,0

'File holding data lines for embedded pictures.
'$include:'./include/PicData.bas'
'---------------End data entry---------------

SUB CIRCLES (cx%, cy%, r!, c~&, s!, e!, a!)
    DIM s%, e%, nx%, ny%, xr!, yr!, st!, en!, asp! '     local variables used
    DIM stepp!, C!

    st! = s! '                                           copy start radian to local variable
    en! = e! '                                           copy end radian to local variable
    asp! = a! '                                          copy aspect ratio to local variable
    IF asp! <= 0 THEN asp! = 1 '                         keep aspect ratio between 0 and 4
    IF asp! > 4 THEN asp! = 4
    IF asp! < 1 THEN xr! = r! * asp! * 4 ELSE xr! = r! ' calculate x/y radius based on aspect ratio
    IF asp! > 1 THEN yr! = r! * asp! ELSE yr! = r!
    IF st! < 0 THEN s% = -1: st! = -st! '                remember if line needs drawn from center to start radian
    IF en! < 0 THEN e% = -1: en! = -en! '                remember if line needs drawn from center to end radian
    IF s% THEN '                                         draw line from center to start radian?
        nx% = cx% + xr! * COS(st!) '                     yes, compute starting point on circle's circumference
        ny% = cy% + yr! * -SIN(st!)
        LINE (cx%, cy%)-(nx%, ny%), c~& '                draw line from center to radian
    END IF
    IF en! <= st! THEN en! = en! + 6.2831852 '           come back around to proper location (draw counterclockwise)
    stepp! = 0.159154945806 / r!
    C! = st! '                                           cycle from start radian to end radian
    DO
        nx% = cx% + xr! * COS(C!) '                      compute next point on circle's circumfrerence
        ny% = cy% + yr! * -SIN(C!)
        PSET (nx%, ny%), c~& '                           draw the point
        C! = C! + stepp!
    LOOP UNTIL C! >= en!
    IF e% THEN LINE -(cx%, cy%), c~& '                   draw line from center to end radian if needed
END SUB

'$include:'./include/np_glinput.bi'
'$include:'./include/qprint.bm'
'$Include:'./include/Base64.bas'


Attached Files
.zip   Include.zip (Size: 28.82 KB / Downloads: 19)
Reply


Messages In This Thread
Processing key input on a do loop - by NasaCow - 04-20-2023, 11:39 AM
RE: Processing key input on a do loop - by NasaCow - 04-27-2023, 12:09 PM



Users browsing this thread: 3 Guest(s)