Announcement

Collapse
No announcement yet.

Word wrap in a graphics window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Word wrap in a graphics window

    So, I'm just beginning to use the graphics functions in PBCC (until now I've been using Console Graphics). I can't figure out how to show text and get in to wrap in the window. There's got to be an option for this, but I just can't see it in the functions given. I'm using v4.03. Can anyone help?
    Craig J. Slane
    Nostalga Sim Baseball

  • #2
    This does word wrap, but only for fixed fonts. http://www.powerbasic.com/support/pb...ad.php?t=38994

    Comment


    • #3
      Thanks, Chris. I may give that a try if I get desperate. Right now, I can't even get a line break to work. Perhaps I have to write my own code to get a break in a graphics window. I'm not experienced at it yet. Here's what I've written:

      DIM wT(1 to 100) As String
      DIM iL AS STRING
      iL = PARSE$(remControl(36),ANY ":",2)

      'open a 2nd window for the wizard
      Local messageWin As DWORD
      GRAPHIC WINDOW "Get Started Wizard", 10,10, 300,600 TO messageWin???
      GRAPHIC ATTACH messageWin, 0
      GRAPHIC SET LOC 10,300

      wT(1)= "Important! It's time to install your league "+ $CRLF +"and team, and I can help you. " _
      +"But first, you will need to find your personal install code. It should have arrived in your " _
      +"e-mail inbox within 24 hours (usually it's much sooner) after registering at our website. If you " _
      +"haven't registered at the website, do so now, and come back after you get your code. If you've registered " _
      +"but can't find your code even after 24 hours, check your spam/junk folder. Or, you can logon to the site " _
      +"and locate your code by selecting 'Edit Owner Profile' and selecting the 'Install Code' tab." _
      +"Once you locate your code, highlight it, right click, and select copy. Next, click on the 'Leagues' button " _
      +"on the title screen of this software, select 'Install New', right click the mouse, and paste your code into the input box. "


      GRAPHIC BOX (10,100) - (290,500) ,20,0,%Black,0
      GRAPHIC FONT "Arial Narrow",10,0
      GRAPHIC COLOR %LoWhite,%Black
      GRAPHIC SET POS (15,110)
      GRAPHIC Width 80
      GRAPHIC PRINT wT(1)
      Craig J. Slane
      Nostalga Sim Baseball

      Comment


      • #4
        Don't you have to measure the text length to decide at which word boundary to truncate each line?

        There are a couple of clues in this thread: http://www.powerbasic.com/support/pb...ht=text+length

        Comment


        • #5
          Documentation for GRAPHIC PRINT suggests you will never get a word break to a new line:
          Drawing begins at the last point referenced (POS) by another statement, or the point specified by GRAPHIC SET POS. The upper left corner of the text is positioned at the POS. Upon completion, the POS is moved to the left margin of the next line. However, if a trailing semi-colon is included, movement to the next line is suppressed.
          Looks to me like GRAPHIC PRINT is very much "line" oriented, not that "line" is a particularly "graphic" term. For LPRINT/XPRINT a "line" has meaning, but "line" would not seem to have any meaning in a pure graphic environment. If it did, you'd think there would be a 'GRAPHIC SET LINE SPACING' command or something like that.
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            DrawText() API can do wrapping, i assume you can get a DC-handle on this graphic thingy?
            Last edited by Edwin Knoppert; 22 Dec 2008, 11:15 AM.
            hellobasic

            Comment


            • #7
              >... last point referenced (POS)

              Not "LPR?"

              Another one where someone must be saying, "I wish we would have...." ???

              "GRAPHIC SET LPR"....instead of "GRAPHIC SET POS?"

              Well, maybe not in that POS is pretty familiar to BASIC-lanugage programmers... who programmed in the 80s and early 90s, anyway...

              MCM
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Edwin Knoppert View Post
                DrawText() API can do wrapping, i assume you can get a DC-handle on this graphic thingy?
                I tried DrawText(). I think it would work for me but I can't figure out how the syntax works for LPRECT (see below). That parameters point to a structure (i.e., RECT) which apparently I don't know how to build as an API.

                int DrawText(
                HDC hDC, // handle to device context
                LPCTSTR lpString, // pointer to string to draw
                int nCount, // string length, in characters
                LPRECT lpRect, // pointer to structure with formatting dimensions
                UINT uFormat // text-drawing flags
                );
                Craig J. Slane
                Nostalga Sim Baseball

                Comment


                • #9
                  Use MSDN or Win32 Programmer's reference (F1 on your IDE?) to look at the RECT structure and the GetClientRect API, also look at the same structures and APIs in their groups, and use the forum Search to find source code examples - worked for me!

                  Rect and point (POINTAPI is the equivalent PowerBasic UDT) is fundamental to a number of Windows operations and is a good one to learn. If you want to see how these Windows structures are mapped in PB look at the WIN32API.INC file.

                  The DrawText with DT_CALCRECT will give you the text length and height in pixels by modifying the Rect. With this flag it does not draw, you will have to call it again for that.

                  Or you could use GRAPHIC PRINT /GRAPHIC TEXT SIZE in a GRAPHIC WINDOW.
                  Last edited by Chris Holbrook; 22 Dec 2008, 11:46 PM.

                  Comment


                  • #10
                    Well, it is Christmas...

                    Code:
                    #compile exe
                    #dim all
                    global hGW as dword 'graphic window ahndle
                    
                    function pbmain () as long
                        local skey as string
                        local hfont as dword
                        local s, stext as string
                        local pxtextwidth as long ' the width in pixels to which we want to wrap the text
                        local i, j, k, l, sol, w, h as long
                    
                        graphic window "GW text wrap Esc to end                        Chris Holbrook Dec 2008", 300, 100, 500, 400 to hGW
                        graphic attach hGW, 0, redraw
                        font new "Arial", 12 to hfont
                        graphic set font hfont
                    
                        pxtextwidth = 450
                        stext = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor" + _
                                "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis " + _
                                "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " + _
                                "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu" + _
                                "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, " + _
                                "sunt in culpa qui officia deserunt mollit anim id est laborum."
                        
                        sol = 1' start of line char pos
                        k = 1
                        while 1=1
                            s = mid$(stext, sol, k - sol + 1)
                            graphic text size s to W, H
                            if w > pxtextwidth then
                                l = len(s)
                                for j = l to 1 step -1
                                    if mid$(s,j,1) = " " then
                                        s = mid$(stext, sol, j)
                                        sol = sol + j
                                        k = sol
                                        graphic print s
                                        exit for
                                    end if
                                next
                            else
                                incr k
                            end if
                            if k > len(stext) then exit loop
                        wend
                    
                        if len(s) then graphic print s
                        graphic redraw
                        graphic waitkey$ to skey$
                    
                    
                    end function

                    Comment


                    • #11
                      >Well, it is Christmas

                      I'm glad you included that.

                      I'd hate for anyone to start thinking others will write your code for you!
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Wow. Merry Christmas to Me. I gave it a spin. After a few little tweaks (I'm not yet working with PBCC 5) I got a sweet little present. I appreciate seeing how you did this. I'm very grateful! And all without an API call - a thing of beauty. Merry Christmas to you.
                        Craig J. Slane
                        Nostalga Sim Baseball

                        Comment


                        • #13
                          It could all be so much better.
                          The drawtext can modify the text passed and has profi wrapping.
                          Once modified (with high speed) you can draw each line..
                          hellobasic

                          Comment


                          • #14
                            Originally posted by Edwin Knoppert View Post
                            It could all be so much better.
                            How about an example?

                            Comment


                            • #15
                              I just looked it up but i implemented it into our printengine (no code available).

                              The idea is to use end ellipsis and modify string flags.
                              You have to break the lines having enters and then break each line using drawtext by looking up the ellipsis.
                              While a little more work, you can make it more efficient then the code above.

                              Mid$() is not very fast, use buffers.
                              hellobasic

                              Comment


                              • #16
                                >(no code available).

                                = VAPORWARE

                                Sheesh.

                                Whatever happened to the days when, if someone thought they could do it better, they let their code do the talkin'?
                                Michael Mattias
                                Tal Systems Inc. (retired)
                                Racine WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  That's because it was more code to write as anticipated (but still convinced faster and anticipating wordwrap rules).

                                  Sorry..

                                  btw, what's wrong with a hint?
                                  hellobasic

                                  Comment


                                  • #18
                                    Originally posted by Edwin Knoppert View Post
                                    btw, what's wrong with a hint?
                                    Absolutely nothing wrong, thanks for the hint!

                                    Comment


                                    • #19
                                      Nothing's wrong with a hint. I personally have been known to from time to time respond with only the name of an intrinsic function or external API call, not supplying detailed code... a hint.

                                      BUt saying "I have code to do that but I'm not going to show you" seems a tad tacky.

                                      Better methinks to just leave the hint.
                                      Michael Mattias
                                      Tal Systems Inc. (retired)
                                      Racine WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        Well, my question was actually a very poor one.
                                        When i post a question i often get numerous work arounds while i ask a specific question.
                                        That frustrates me since it happens each time.
                                        I know the work arounds and if not i ask for it.

                                        So slap my hand, i was wrong myself..
                                        hellobasic

                                        Comment

                                        Working...
                                        X