Liberty BASIC Community Forum
« Need help with code. Many lines of text. »

Welcome Guest. Please Login or Register.
Sep 21st, 2017, 7:57pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Need help with code. Many lines of text.  (Read 314 times)
cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 626
exclamation Need help with code. Many lines of text.
« Thread started on: Jun 19th, 2016, 10:49am »

OK, first of all Alyce told me about José, he speaks Spanish. I'm trying to help him with LB and a problem he has. Dan already know about this, and now I have José's permission I will post his code so we can get help from other people. I will do the translation privately. It is important to mention that the TOS requires almost everything to be in English.

Code:
nomainwin
w=DisplayWidth: h=DisplayHeight: WindowWidth=w: WindowHeight=h
graphicbox #1.g,0,0,w,h
open "VERTSCROLLBAR" for window_popup as #1
#1.g,"cls ;down; setfocus; font Elephant 12 30; when leftButtonDown [final]"
y=0: sp$=space$(w)
for i=1 to 1000: y=y+30: x=200+int(rnd(1)*500)
#1.g, "place 0 ";y: #1.g, "\ ";sp$
#1.g, "place ";x;" ";y: #1.g, "\ ";str$(i)
#1.g, "place ";x+80;" ";y: #1.g, "\ ";"- - - - - - - - "
#1.g, "place ";x+200;" ";y: #1.g, "\ ";str$(y)
next i
#1.g, "flush; discard": finalscroll=y-h
#1.g,"vertscrollbar on 0 "; finalscroll
wait
[final]
close #1: end 
 

His first query : understanding the scrollbars. I think we solved that.
The problem continues because he needs big,large numbers on screen, and there are 30000 numbers. We test the code with smaller amounts, the code above has 1000 numbers on screen. The font pixel height is of 30.
This depends on the computer, and the video memory I believe.
« Last Edit: Jun 19th, 2016, 6:19pm by cundo » User IP Logged

cundo
cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 626
exclamation Re: Need help with code. Many lines of text.
« Reply #1 on: Jun 19th, 2016, 6:07pm »

This is the code I made with help of Dan, it requires lbgfx version 9.
Code:
nomainwin
    w=DisplayWidth: h=DisplayHeight: WindowWidth=w: WindowHeight=h
    graphicbox #1.g,-100,-100,0,0
    stylebits #1,_WS_SYSMENU,0,0,0
    open "VERTSCROLLBAR" for window_popup as #1
    global hLBGfx
    open DefaultDir$+"\LBGfx.dll" for dll as #lbgfx
    hLBGfx=CreateLBGfx(0,0,WindowWidth,WindowHeight,hwnd(#1),hwnd(#1.g))
     max=30000/200
    #1.g "when leftButtonDown [final]"
    y=0
    finalscroll=60*max+60
    scrollH= finalscroll
    call printCmds hLBGfx,"autosizeon;scrollxon ";w ;"; scrollyon "; scrollH
    call printCmds hLBGfx,"fill 100 100 150"
    for i=1 to max
        y=y+60 : x=122+int(rnd(1)*500)
        scan
        call doubleText str$(i);" - - - - - - - "; str$(y),x,y
    next i
    call printCmds hLBGfx,"flip"
wait
[final]
    call DestroyLBGfx hLBGfx
    close #lbgfx
close #1: end
function noEscape$(string$)
    for i = 1 to len(string$)
        l$=mid$(string$,i,1)
        select case l$
        case ""
            l$="\"
        case "'"
            l$="'"
        end select
        noEscape$=noEscape$+l$
    next i
end function
sub doubleText text$, x,y
    call printCmds hLBGfx,"backcolor red"
    call printCmds hLBGfx,"font 30 b 'Elephant'"
    call printCmds hLBGfx,"color black"
    for tx= -1 to 1
    for ty= -1 to 1
    call printCmds hLBGfx, "text "; x+tx; " "; y+ty; " 0 0 "; _DT_NOCLIP; " '"; noEscape$(text$); "' "
    next : next
    call printCmds hLBGfx, "text "; x-1; " "; y+1; " 0 0 "; _DT_NOCLIP; " '"; noEscape$(text$); "' "
    call printCmds hLBGfx,"font 30 b 'Elephant'"
    call printCmds hLBGfx,"color 255 185 145"
    call printCmds hLBGfx, "text "; x; " "; y; " 0 0 "; _DT_NOCLIP; " '"; noEscape$(text$); "' "
end sub
sub printCmds hwnd,text$
    calldll #lbgfx,"graphicCommand",hwnd as ulong,text$ as ptr,ret as void
end sub
function CreateLBGfx(x,y,w,h,hParent,hMessageHandler)'Returns 0 if fail, hWnd if pass
    style=_WS_VISIBLE+_WS_CHILD+_WS_CLIPCHILDREN
    calldll #kernel32,"GetModuleHandleA",0 as ulong,instance as ulong
    calldll #user32,"CreateWindowExA",_
    0 as long,_
    "LBGfx32" as ptr,_
    0 as ulong,_
    style as ulong,_
    x as long,y as long,w as long,h as long,_
    hParent as ulong,_
    0 as ulong,_
    instance as ulong,_
    hMessageHandler as ulong,_
    CreateLBGfx as ulong
end function
sub DestroyLBGfx hwnd
    calldll #user32, "DestroyWindow",_
    hwnd as ulong, _
    ret as long
end sub
 

It has this cool sub I made for a game, it shows the text with a border (doubleText).
Anyway, it becomes slow if set the max variable to just 30000.

The next one has my own custom scrollbars, and it display ten or so numbers at a time.
Code:
w=640  : h=480 : WindowWidth=w: WindowHeight=h
    UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
    CXVSCROLL=GetSystemMetrics( _SM_CXVSCROLL )
    CXBORDER=GetSystemMetrics(_SM_CXBORDER)

    stylebits #1.g, 0, _WS_BORDER, 0, 0
    graphicbox #1.g, 0, 0, w, h

    stylebits #1,_WS_SYSMENU,0,0,0

    Open "Window" for Window_popup as #1

        #1 "trapclose [final]"
            #1.g "when leftButtonDown [lbd]"
            #1.g "when leftButtonUp [lbu]"
                altura=60
            #1.g "font arial 15 ";altura;" bold"
            #1.g "down;fill white"
            #1.g "backcolor buttonface"

            #1.g "color blue"
            'dibujo barras de desplazamiento
            #1.g "place ";w-CXVSCROLL-CXBORDER;" ";0
            #1.g "boxfilled ";w-CXBORDER;" ";CXVSCROLL-CXBORDER*2

            #1.g "place ";w-CXVSCROLL-CXBORDER;" ";CXVSCROLL-CXBORDER
            #1.g "boxfilled ";w-CXBORDER;" ";h-CXVSCROLL-CXBORDER

            #1.g "place ";w-CXVSCROLL-CXBORDER;" ";h-CXVSCROLL
            #1.g "boxfilled ";w-CXBORDER;" ";h-CXBORDER

            'mantengo el gráfico en un segmento de nombre 'bar'
            #1.g "flush bar"

            max=2000
            dim x(max)

            #1.g "color blue"
            #1.g "backcolor white"

            nOfPrints= h/altura
            [repite]
                #1.g "delsegment segId"
                '#1.g "redraw bar"
                #1.g "place 0 0"
                #1.g "boxfilled ";w-CXVSCROLL-CXBORDER;" ";h
                #1.g "place 3 "; altura-1

            for i = 1+offset to  nOfPrints+offset
                if i<= max then
                    if x(i)=0 then x(i)=1+int(rnd(1)*50)
                    texto$ = space$( x(i) );i;" - - - - ";i*altura
                    #1.g "\";texto$

                end if
            next
                #1.g "flush segId;discard"
            wait

            [lbd]
            if MouseX > (w-CXVSCROLL) AND MouseX < w then

                select case
                    case MouseY >= 1 and MouseY<= CXVSCROLL
                        offset=offset-1
                        if offset<0 then offset= 0
                    case MouseY <= h and MouseY>= (h-CXVSCROLL)
                        offset=offset+1
                    case else
                        scrollLenght = h-CXVSCROLL*2 - CXBORDER*2
                       ' notice scrollLenght
                end select

                timer 100,[lbd]

                goto  [repite]

             end if

            if MouseX <w-CXVSCROLL-1 then [final]
            wait

    [final]

    close #1 : end

    [lbu]
        timer 0
    wait

Function GetSystemMetrics(nIndex)
    Calldll #user32, "GetSystemMetrics",_
        nIndex As uLong,_
        GetSystemMetrics As uLong
End Function
 

I think José prefers the real scrollbars.


This one has the real vertical scrollbar, but it doesn't behave correctly (try dragging the little thingy, the thumb-something)
Code:
nomainwin
    w=800  : h=600 : WindowWidth=w: WindowHeight=h
    UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY = INT((DisplayHeight-WindowHeight)/2)

    graphicbox #1.g, 0, 0, w, h
    stylebits #1,_WS_SYSMENU,0,0,0
    Open "Window" for Window_popup as #1
        #1 "trapclose [final]"
        #1.g "when leftButtonDown [final]"
        max=30000
         dim x(max)
        altura=60
        #1.g "vertscrollbar on [1 ";max*altura;"]"
        #1.g "down ; fill white"
        #1.g "font ARIAL 15 ";altura; " bold"
        #1.g "place -10 -10"

        prev=rnd(1) ' cualquier nro
        nOfPrints= h/altura ' cantidad de lineas por pantalla
       ' print nOfPrints
        [t]
        timer 0
        ScrollPos = GetScrollPos( hWnd(#1.g), _SBS_VERT )
        pos = INT(ScrollPos/altura)
        if prev<>ScrollPos then ' solo si diferente posición, dibuja
         prev=ScrollPos
            for i =pos to nOfPrints+pos ' solo 10 nros por pantalla
                if x(i)=0 then x(i)=int(rnd(1)*50)+1
                #1.g "place 0 "; altura*i

                #1.g "\"; space$(x(i)); i; " - - - - "; i*altura; space$(w/4)
            next i

        end if
        timer 56, [t]
    wait

    [final]
    close #1 : end

Function GetScrollPos( handle,scrollDir )
    CallDLL #user32, "GetScrollPos", _
        handle As ulong, _ 'handle of the Graphicbox
        scrollDir as uLong, _ '_SBS_HORZ or _SBS_VERT
        GetScrollPos as uLong 'The Position in decimal format
End Function
 

« Last Edit: Jun 19th, 2016, 6:11pm by cundo » User IP Logged

cundo
Dan Teel
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1130
exclamation Re: Need help with code. Many lines of text.
« Reply #2 on: Jun 19th, 2016, 8:45pm »

Make a fake scrollbar inside and draw the numbers on demand dependent on the scrollbars position instead of requiring a buffer 10000 billion pixels big and drawing them all at the start.
User IP Logged

ZPtr.net
cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 626
exclamation Re: Need help with code. Many lines of text.
« Reply #3 on: Jun 21st, 2016, 7:50pm »

Anyone knows how to get the scroll value using some API? I don't know how it is called but when you grab the thumb-box it advances 8 position each time, I want to know that value if possible.
« Last Edit: Jun 21st, 2016, 7:50pm by cundo » User IP Logged

cundo
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
exclamation Re: Need help with code. Many lines of text.
« Reply #4 on: Jun 22nd, 2016, 06:14am »

MSDN has detail

https://msdn.microsoft.com/en-us/library/windows/desktop/bb787585(v=vs.85).aspx

Also on the wiki Janet shows the getscrollpos api call, its near the end of the article just before the demo code.

http://lbpe.wikispaces.com/Graphicbox+and+Scrollbars
« Last Edit: Jun 22nd, 2016, 06:15am by Rod » User IP Logged

cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 626
exclamation Re: Need help with code. Many lines of text.
« Reply #5 on: Jun 24th, 2016, 7:57pm »

OK, thanks to both.
@Dan: Yes, that was an idea I had too. Check one of the codes above, the one in the middle has a scrollbar I made with graphics commands. It is not good enough, I need to implement a thumb-box.
@Rod: Thanks for the MS link, I will check that out. About Janet's article, yes, I've read that many times, in fact I took many ideas from there.
User IP Logged

cundo
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls