; drawTextLF.pbi ; [..just a LineFeed-able drawText ] Global drawTextLF_EndX.l ; use these variables after a call of drawTextLF() to retrieve the pixel Global drawTextLF_EndY.l ; position where drawTextLF() finished (the upper right corner of end of text) Global drawTextLF_MaxX.l ; right side of last drawn text area (x + length in pixel of the longest line) ; parameters: ; x / y : starting position ; text : text to be drawn on current drawing-output. ; color : textcolor ; xWrapTo : x-position of further drawing after linefeed occurrence (default value is your passed 'x'-parameter) ; lineSeperator$ : the string that is used in 'text' as line seperator (default value is '#LF$') Procedure drawTextLF(x.l, y.l, text.s, color.l, xWrapTo.l=-1, lineSeperator$=#LF$) Static yPitch.l Static xPitch.l Static line.s Static i.l Static n.l drawTextLF_MaxX = 0 If xWrapTo=-1 xWrapTo=x EndIf yPitch=TextHeight("X") n=CountString(text,lineSeperator$) For i=0 To n line=StringField(text,i+1,lineSeperator$) xPitch=DrawText( x, y+i*yPitch, line, color) If xPitch>drawTextLF_MaxX drawTextLF_MaxX = xPitch EndIf If i=0 x=xWrapTo EndIf Next drawTextLF_EndX = xPitch drawTextLF_EndY = y+(i-1)*yPitch EndProcedure ; [merge_end] ;######### CompilerIf 0 ;######### set to 1 to see examples text.s="X|"+#LF$ text + "X|---------------------------------"+#LF$ text + "[gk::X12+]"+#LF$ text + "----------------------------------"+#LF$ text + "62.214.64.185"+#LF$ text + "89.247.11.224"+#LF$ text + "----------------------------------"+#LF$ text + ""+#LF$ text + "----------------------------------"+#LF$ text + "etkj-7070371@+"+#LF$ text + "## # # # ä"+#LF$ text + "----------------------------------" InitSprite() InitMouse() InitKeyboard() ww=800 wh=600 hWin=OpenWindow(0, 50,50,ww,wh, "EXAMPLE - drawTextLF.pbi") OpenWindowedScreen( hWin, 0,0,ww,wh, 0,0,0) Repeat ExamineMouse() ExamineKeyboard() StartDrawing(ScreenOutput()) DrawingMode(#PB_2DDrawing_Transparent) drawTextLF(MouseX(),MouseY(),text, $336633) StopDrawing() FlipBuffers() ClearScreen($333333) Delay(10) Until WaitWindowEvent(50)=#PB_Event_CloseWindow Or KeyboardPushed(1) Or MouseButton(2) While MouseButton(2):ExamineMouse():Wend ;############ CompilerEndIf ;############ ; IDE Options = PureBasic 4.20 Beta 3 (Windows - x86) ; CursorPosition = 58 ; FirstLine = 48 ; Folding = - ; CompileSourceDirectory