? zero width space (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
This is the development website, where we test out new features. This isn't the place you're looking for! Go here

zero width space

  • #1 ✎ 239 Lumage Head Admin Gardening I like to garden! Hobbies Reading I like to read books! Hobbies Drawing I like to draw! Hobbies ' -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/- '[ '[ VIEW module '[ '[ there are a bunch of unnamed constant values and inline statements that should really '[ be external functions but muh overhead ' -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/- 'todo: perhaps move some of the border-drawing into separate functions for modularity DIM __VIEW_touchStartCoords%[0] DIM __VIEW_touchEndCoords%[0] DIM __VIEW_objectList$[0] ' __VIEW.draw_textBox Lines$[], x%, y%, w%, h% ' draws a textbox of size w%*h% (including border) ' at (x%,y%) ' ' If there are fewer lines in string array Lines$ ' than height h%, empty rows will be printed ' ' Lines longer than the width of the box will be ' truncated with ellipsis DEF __VIEW_draw_textBox Lines$, x%, y%, w%, h% VAR tempStr$, lastrow%, i% tempStr$ = ""+""*(w%-2)+"" Locate x%,y% Print tempStr$ lastline% = Len(Lines$)-1 For i% = 0 to h%-3 if i% > lastline% then tempStr$ = ""+" "*(w%-2)+"" else tempStr$ = Lines$[i%] if Len(tempStr$) <= w% - 2 then tempStr$ = ""+tempStr$+" "*(w%-2-Len(tempStr$))+"" else tempStr$ = ""+Mid$(tempStr$,0,w%-3)+"…" endif endif Locate x%,y%+1+i% Print tempStr$ Next tempStr$ = ""+""*(w%-2)+"" Locate x%,y%+h%-1 Print tempStr$ END ' __VIEW.draw_highlightTextBox ' See __VIEW.draw_textBox ' hlmap$ is a char array representing color codes ' to apply to the lines in the text box. ' hlmap$ must be at least as long as the height ' of the textbox DEF __VIEW_draw_highlightTextBox Lines$, hlmap$, x%, y%, w%, h% VAR tempStr$, lastrow%, i%, bg% tempStr$ = ""+""*(w%-2)+"" Locate x%,y% Print tempStr$ lastline% = Len(Lines$)-1 For i% = 0 to h%-3 if i% > lastline% then tempStr$ = " "*w%-2 else tempStr$ = Lines$[i%] if (Len(tempStr$) <= w% - 2) then tempStr$ = tempStr$+" "*(w%-2-Len(tempStr$)) else tempStr$ = Mid$(tempStr$,0,w%-3)+"…" endif endif Locate x%,y%+1+i% Print ""; bg% = Val(Shift(hlmap$)) Color ,bg% Print tempStr$; Color ,0 Print "" Next tempStr$ = ""+""*(w%-2)+"" Locate x%,y%+h% Print tempStr$ END ' __VIEW.draw_button text$, pressed%, x%, y%, w%, h% ' Draws a "button" at (x%,y%) with minimal checks ' ' > text$ is the face text displayed, centered vertically ' No formatting is performed. Please make sure to pad ' beforehand. ' > pressed% is the push state of the button. False will ' display white, True will display grey. ' Other colors can be obtained as well... DEF __VIEW_draw_button text$, pressed%, x%, y%, w%, h% VAR tempStr$, i% Color #TWHITE - pressed% tempStr$ = ""+""*(w%-2)+"" Locate x%,y% Print tempStr$ For i% = 0 to h%-3 if i% == (h% >> 1) -1 then tempStr$ = ""+ text$ +"" else tempStr$ = ""+" "*(w%-2)+"" Locate x%,y%+1+i% Print tempStr$ Next tempStr$ = ""+""*(w%-2)+"" Locate x%,y%+h%-1 Print tempStr$ Color #TWHITE END ' object types: ' 0: textBox ' 1: highlightTextBox ' 2: button ' String <= __VIEW.createObject(type$, x%, y%, w%, h%, textType%, text$) ' Constructs a display object for use with the VIEW module ' Note that x%, y%, w%, h% coordinates are with respect ' to the console screen ' ' > textType% is a flag indicating whether the ' following string text$ is a literal string ' or variable name reference ' > text$ is a string, interpreted based on ' textType$, that either represents a text ' property of the object or a reference to ' a variable to be used for the text. DEF __VIEW_createObject(type%, x%, y%, w%, h%, callback$, textType%, text$) obj$ = Chr$(type%) +Chr$(x%)+Chr$(y%)+Chr$(w%)+Chr$(h%)+ Chr$(0) + Format$("% 8S",callback$) + Chr$(textType%) + text$ __VIEW_registerObject obj$ __VIEW_registerTouchRegion x%, y%, x% + w%, y% + h% return obj$ END ' __VIEW.registerTouchRegion x%, y%, x%, y% ' Add a VIEW object's position to the searchable ' list of hit regions ' please keep coordinates within 0-255 ' (they should be console coordinates anyway) DEF __VIEW_registerTouchRegion x1%, y1%, x2%, y2% Push __VIEW_touchStartCoords%, x1%<<8 OR y1% Push __VIEW_touchEndCoords%, x2%<<8 OR y2% Sort __VIEW_touchStartCoords%, __VIEW_touchEndCoords%, __VIEW_objectList$ END ' __VIEW.registerObject objectString$ ' Add a VIEW object to the list of searchables ' Use in conjunction with registerTouchRegion DEF __VIEW_registerObject obj$ Push __VIEW_objectList$, obj$ END ' __VIEW.update objectList$ DEF __VIEW_update objectList$ VAR i%, _$, hl$ DIM _text$[1] for i% = Len(objectList$)-1 to 0 step -1 _$ = objectList$[i%] if Asc(_$[14]) == 0 then _text$[0] = Mid$(_$,15,99) if Asc(_$) == 0 then __VIEW_draw_textbox _text$,Asc(_$[1]),Asc(_$[2]),Asc(_$[3]),Asc(_$[4]) elseif Asc(_$) == 1 then hl$ = Bin$(Asc(_$[5]),32) 'convert entire special field to highlight string __VIEW_draw_highlightTextbox _text$,hl$,Asc(_$[1]),Asc(_$[2]),Asc(_$[3]),Asc(_$[4]) elseif Asc(_$) == 2 then __VIEW_draw_button Mid$(_$,15,99),Asc(_$[5]) AND 1,Asc(_$[1]),Asc(_$[2]),Asc(_$[3]),Asc(_$[4]) endif else _text$ = VAR(Mid$(_$,15,99)) if Asc(_$) == 0 then __VIEW_draw_textbox _text$,Asc(_$[1]),Asc(_$[2]),Asc(_$[3]),Asc(_$[4]) elseif Asc(_$) == 1 then hl$ = Bin$(Asc(_$[5]),32) 'convert entire special field to highlight string __VIEW_draw_highlightTextbox _text$,hl$,Asc(_$[1]),Asc(_$[2]),Asc(_$[3]),Asc(_$[4]) elseif Asc(_$) == 2 then __VIEW_draw_button VAR(Mid$(_$,15,99)),Asc(_$[5]) AND 1,Asc(_$[1]),Asc(_$[2]),Asc(_$[3]),Asc(_$[4]) endif endif next END ' __VIEW.handleTouch ' In theory should probably check the lengths ' of the object and rectangle lists for sync ' but I don't have an error system so whatever DEF __VIEW_handleTouch x%, y% VAR i%, r1%, r2% x% = x% >> 3: y% = y% >> 3 'convert to console coords 'just loop through and check lol none of that search shit For i% = Len(__VIEW_touchStartCoords%) - 1 to 0 step -1 r1% = __VIEW_touchStartCoords%[i%] if (x% >= (r1% >> 8) && y% >= (r1% AND &hFF)) then r2% = __VIEW_touchEndCoords%[i%] ' We're not using overlapping fields, so if it's in one, that's the one. if (x% <= (r2% >> 8) && y% <= (r2% AND &hFF)) then break endif Next if i% >= 0 then DISPLAY.?"("+Mid$(__VIEW_objectList$[i%],6,8)+")"DISPLAY 1 CALL Mid$(__VIEW_objectList$[i%],6,8), i%, x%, y% ' VAR P1% = __VIEW_touchStartCoords%[i%] VAR P2% = __VIEW_touchEndCoords%[i%] GBOX (P1% >> 8) * 8, (P1% AND 255) * 8, (P2% >> 8) * 8, (P2% AND 255) * 8, RGB(255,0,127) ' endif END DEF __VIEW_badHandleTouch VAR X%, Y%, r%, TM% TOUCH OUT TM%, X%, Y% P% = X% << 5 OR Y% >> 3 : Y% = Y% >> 3 GBOX (P% >> 8)*8, (P% AND 255) * 8, (P% >> 8) * 8 + 7, (P% AND 255) * 8 + 8, RGB(255,0,0) GPSET X%, Y% * 8, RGB(0,0,255) VAR n% = Len(__VIEW_touchStartCoords%) - 1 VAR i% = 0 VAR L% = Floor(Log(n%,2)) VAR start% = MILLISEC REPEAT r% = __VIEW_touchStartCoords%[i% + (n%>>1)] LOCATE 38, 1:?r%>>8,r% AND 255 if P% >= r% && Y% >= r% AND 255 then n% = n% >> 1 else i% = i% + n% >> 1 n% = (n% >> 1) + 1 endif L% = L% - 1 UNTIL i% >= n% || L% == 0 L% = Floor(Log(n%,2)) LOCATE 38, 0:?i%, n% REPEAT r% = __VIEW_touchEndCoords%[i% + (n%>>1)] if P% <= r% && Y% <= r% AND 255 then r% = i% + (n% >> 1) break else n% = (n% >> 1) - 1 endif L% = L% - 1 r% = -1 UNTIL L% == 0 if r% >= 0 then VAR P1% = __VIEW_touchStartCoords%[r%] VAR P2% = __VIEW_touchEndCoords%[r%] GBOX (P1% >> 8) * 8, (P1% AND 255) * 8, (P2% >> 8) * 8, (P2% AND 255) * 8, RGB(255,0,127) endif END DIM TEXT$[20] TEXT$[0] = "ACLS" TEXT$[1] = "BEEP 0" TEXT$[2] = "PRINT HELLO WORLD" TEXT$[3] = "NINJA GAIDEN" TEXT$[4] = "NINJA GAIDEN" TEXT$[5] = "NINJA GAIDEN" TEXT$[6] = "NINJA GAIDEN" TEXT$[7] = "NINJA GAIDEN" TEXT$[8] = "NINJA GAIDEN" TEXT$[9] = "NINJA GAIDEN" TEXT$[10] = "Shadow meme" TEXT$[11] = "Shadow meme" TEXT$[12] = "Shadow meme" TEXT$[13] = "Shadow meme" TEXT$[14] = "Shadow meme" TEXT$[15] = "Shadow meme" TEXT$[16] = "Shadow meme" TEXT$[17] = "Shadow meme" TEXT$[18] = "Shadow meme" TEXT$[19] = "Shadow meme" DEF __CB_NOP a%,b%,c% END DEF CBBUTTON o%, x%, y% DIM single$[1] __VIEW_objectList$[o%][5] = Chr$(1) COPY single$, __VIEW_objectList$, o%, 1 __VIEW_update single$ __VIEW_objectList$[o%][5] = Chr$(0) END CLS:GCLS REM __VIEW_draw_textBox TEXT$, 0, 0, 15, 11 REM hl$=Chr$(0)+Chr$(0)+Chr$(0)+Chr$(12)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0) REM __VIEW_draw_highlightTextBox TEXT$, hl$, 10, 8, 10, 6 A$ = __VIEW_createObject(2, 0, 0, 5, 5, "CBBUTTON", 0, "HEY") A$ = __VIEW_createObject(2, 11, 2, 9, 3, "CBBUTTON", 0, " Hello ") A$ = __VIEW_createObject(0, 20, 12, 16, 8, "__CB_NOP", 1, "TEXT$") XSCREEN 2 DISPLAY 1 __VIEW_update __VIEW_objectList$ while 1 TOUCH OUT STTM,TX,TY GCLS IF STTM > 0 THEN __VIEW_handleTouch TX, TY VSYNC wend Posted