Announcement

Collapse
No announcement yet.

How to print a down arrow in Graphic Window

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

  • How to print a down arrow in Graphic Window

    Hey members I am having a problem printing a down arrow CHR$(25) in a graphic window. All others print fine, CHR$(24) up arrow, CHR$(26) right arrow, and CHR$(27) left arrow these all print fine, I just can't get the CHR$(25) down arrow to print. It prints something like this ? . I have tried the UCODEPAGE OEM and UCODEPAGE ANSI but neither affects the output. Can anyone help me on this. The CHR$(25) prints fine on a console screen but not on graphic window. Can someone help me.

    Thanks in advance

  • #2
    AFAIC none of those should print! They are all control codes.

    Do you have some source (minimal compilable) that demonstrates how you're trying?
    Dale

    Comment


    • #3
      Mr. Dale Yarker

      Here is the entire program, it is not finished yet. I wrote this in dBase IV and was just messing around with it in PB.


      #COMPILE EXE
      #DIM ALL
      #CONSOLE OFF

      FUNCTION PBMAIN () AS LONG
      UCODEPAGE OEM
      LOCAL hWin,hFont,pFont AS DWORD
      LOCAL w,h,cw,ch,x,y AS LONG
      LOCAL m_Draw,xcnt,xcnt2,m_exit AS INTEGER
      LOCAL m_esc AS STRING
      LOCAL a$
      w = 400 :h = 250 ' desired dialog size
      DESKTOP GET LOC TO x, y ' in case taskbar is on Left/Up side
      DESKTOP GET CLIENT TO cw, ch ' need DeskTop clien size
      x = x + ((cw - w) / 2) ' calculate centered x
      y = y + ((ch - h) / 2) ' calculate centered y

      GRAPHIC WINDOW "", x, y, w, h TO hWin
      GRAPHIC ATTACH hWin, 0
      GRAPHIC WINDOW STABILIZE hWin
      GRAPHIC COLOR %RGB_PURPLE, %RGB_PURPLE
      GRAPHIC CLEAR
      GRAPHIC WIDTH 2
      GRAPHIC LINE (5,5)-(5,245), %RGB_WHITE
      GRAPHIC LINE (5,245)-(395,245), %RGB_WHITE
      GRAPHIC LINE (395,245)-(395,5), %RGB_WHITE
      GRAPHIC LINE (5,5)-(395,5), %RGB_WHITE
      GRAPHIC BOX (13,13)-(387,237),0,,%RGB_RED,0

      ' Draw 1st inside box and color for chisel effect
      GRAPHIC LINE (30,30)-(30,220), %RGB_BLACK
      GRAPHIC LINE (30,220)-(40,220), %RGB_BLACK
      GRAPHIC LINE (30,30)-(360,30), %RGB_BLACK
      GRAPHIC LINE (40,220)-(370,220), %RGB_WHITE
      GRAPHIC LINE (370,220)-(370,30), %RGB_WHITE
      GRAPHIC LINE (360,30)-(370,30), %RGB_WHITE

      GRAPHIC BOX (50,50)-(350,200),0,%RGB_RED, %RGB_RED,0
      ' GRAPHIC BOX (60,60)-(330,190),0,%RGB_gray, %RGB_gray,0
      GRAPHIC LINE (60,60)-(60,190), %RGB_WHITE
      GRAPHIC LINE (60,190)-(70,190), %RGB_WHITE
      GRAPHIC LINE (60,60)-(320,60), %RGB_WHITE
      GRAPHIC LINE (70,190)-(330,190), %RGB_BLACK
      GRAPHIC LINE (330,190)-(330,60), %RGB_BLACK
      GRAPHIC LINE (320,60)-(330,60), %RGB_BLACK

      GRAPHIC COLOR %RGB_GOLD, %RGB_RED
      FONT NEW "Comic Sans MS", 14, 1 TO hFont
      FONT NEW "Courier New", 10,1 TO pFont
      GRAPHIC SET FONT hFont
      GRAPHIC SET POS(80,105): GRAPHIC PRINT "Press (ESC) Key to Exit"
      FONT END hFont
      GRAPHIC SET FONT pFont


      m_draw = 2 : m_exit = 0
      DO WHILE m_esc <> CHR$(27)
      xcnt = 5
      DO WHILE xcnt < 245
      GRAPHIC COLOR %RGB_BLACK, %RGB_PURPLE
      m_esc = GRAPHIC$(INKEY$)
      IF xcnt > 5 THEN
      IF m_draw = 1 THEN
      GRAPHIC COLOR %RGB_WHITE, %RGB_PURPLE
      GRAPHIC LINE (5,xcnt-10)-(5,xcnt)
      ELSE
      GRAPHIC SET POS (0,xcnt-10) : GRAPHIC PRINT " "
      END IF
      END IF
      GRAPHIC SET POS(0,xcnt): GRAPHIC PRINT CHR$(25)
      SLEEP 100
      xcnt = xcnt + 10
      IF m_esc = CHR$(27) THEN
      m_exit = 1
      EXIT
      END IF
      LOOP
      IF m_exit = 1 THEN
      EXIT
      END IF



      IF m_draw = 1 THEN
      GRAPHIC LINE (5,xcnt-10)-(5,xcnt)
      ELSE
      GRAPHIC SET POS (0,xcnt-10) : GRAPHIC PRINT " "
      END IF

      xcnt2 = 5
      DO WHILE xcnt2 < 395
      m_esc = GRAPHIC$(INKEY$)
      GRAPHIC COLOR %RGB_BLACK, %RGB_PURPLE
      IF xcnt2 > 5 THEN
      IF m_draw = 1 THEN
      GRAPHIC COLOR %RGB_WHITE, %RGB_PURPLE
      GRAPHIC SET POS (xcnt2-10,238):GRAPHIC PRINT " "
      GRAPHIC LINE (xcnt2-20,245)-(xcnt2,245)
      ELSE
      GRAPHIC SET POS (xcnt2-10,237) : GRAPHIC PRINT " "
      END IF
      END IF
      GRAPHIC SET POS(xcnt2,237): GRAPHIC PRINT "->"
      SLEEP 100
      xcnt2 = xcnt2 + 10
      IF m_esc = CHR$(27) THEN
      m_exit = 1
      EXIT
      END IF
      LOOP
      IF m_exit = 1 THEN
      EXIT
      END IF
      IF m_draw = 1 THEN
      GRAPHIC LINE (xcnt2,237)-(xcnt2+10,237)
      ELSE
      GRAPHIC SET POS (xcnt2-10,237) : GRAPHIC PRINT " "
      END IF
      xcnt = 237
      DO WHILE xcnt > 0
      m_esc = GRAPHIC$(INKEY$)
      GRAPHIC COLOR %RGB_BLACK, %RGB_PURPLE
      IF xcnt < 237 THEN
      IF m_draw = 1 THEN
      GRAPHIC COLOR %RGB_WHITE, %RGB_PURPLE
      GRAPHIC LINE (390,xcnt)-(390,xcnt+10)
      ELSE
      GRAPHIC SET POS (390,xcnt+10): GRAPHIC PRINT " "
      END IF
      END IF
      GRAPHIC SET POS (390,xcnt) : GRAPHIC PRINT CHR$(24)
      SLEEP 100
      xcnt = xcnt - 10
      IF m_esc = CHR$(27) THEN
      m_exit = 1
      EXIT
      END IF
      LOOP
      IF m_exit = 1 THEN
      EXIT
      END IF
      IF m_draw = 1 THEN
      GRAPHIC LINE (390,xcnt)-(390,xcnt+10)
      ELSE
      GRAPHIC SET POS (390,xcnt+10): GRAPHIC PRINT " "
      GRAPHIC SET POS (390,xcnt): GRAPHIC PRINT " "
      END IF
      xcnt2 = 390
      DO WHILE xcnt2 > 0
      m_esc = GRAPHIC$(INKEY$)
      GRAPHIC COLOR %RGB_BLACK, %RGB_PURPLE
      IF xcnt2 < 390 THEN
      IF m_draw = 1 THEN
      GRAPHIC COLOR %RGB_WHITE, %RGB_PURPLE
      GRAPHIC LINE (xcnt2,-2)-(xcnt2+10,-2)
      ELSE
      GRAPHIC SET POS (xcnt2,-2) : GRAPHIC PRINT " "
      END IF
      END IF
      GRAPHIC SET POS (xcnt2,-2) : GRAPHIC PRINT CHR$(27)
      SLEEP 100
      xcnt2 = xcnt2 - 10
      IF m_esc = CHR$(27) THEN
      m_exit = 1
      EXIT
      END IF
      LOOP
      IF m_exit = 1 THEN
      EXIT
      END IF
      IF m_draw = 1 THEN
      GRAPHIC LINE (xcnt2-10,-2)-(xcnt2,-2)
      ELSE
      GRAPHIC SET POS (xcnt2,-2) : GRAPHIC PRINT " "
      END IF
      SELECT CASE m_draw
      CASE = 1
      m_draw = 2
      CASE = 2
      m_draw = 1
      END SELECT
      LOOP
      GRAPHIC WINDOW END hWin

      END FUNCTION

      Comment


      • #4
        Okay, poking around your code.

        Long time since I've even heard of anyone else doing .prg in dBase.

        If anyone else has any ideas, feel free!
        Dale

        Comment


        • #5
          We know why CHR$(27) isn't working as expected, as Dale says, ASCII codes below 32 are "non-prining control codes".

          The question is: Why is Windows displaying CHR$(24 -27) as those glyphs? .

          (Note, it's not just PB that does it. A quick test shows that an Access Msgbox and the VBA IDE do it too.
          )Click image for larger version  Name:	chrs.jpg Views:	1 Size:	4.5 KB ID:	770588


          https://en.wikipedia.org/wiki/Code_page_437

          "The following tables show code page 437. Each character is shown with its equivalent Unicode code point and its decimal code point. See also the notes below, as there are multiple equivalent Unicode characters for some code points. The decimal codes are also known as Alt codes.

          Although the ROM provides a graphic for all 256 different possible 8-bit codes, some APIs will not print some code points, in particular the range 1-31 and the code at 127.[4] Instead they will interpret them as control characters. For instance many methods of outputting text on the original IBM PC would interpret the codes for BEL, BS, CR and LF. Many printers were also unable to print these characters.".

          Table extract:
          Click image for larger version  Name:	OEM.jpg Views:	1 Size:	2.8 KB ID:	770589

          So Windows is displaying ROM graphics, but a quick check shows that many (all?) common Windows font have the same wrong glyphs for CHR$(25).

          The simple solution is don't use "non-prinint control codes" i.e.Chr$(0-31) for display purposes. (with the obvious exception of Chr$(9) (TAB)

          And since DOS/OEM doesn't have "printable" arrow codes, you can't port your code directly to Windows lie that .

          However, WIndows does have suitable arrows in many fonts.

          You could use
          FONT NEW "WINGDINGS" to hFont1
          GRAPHIC SET FONT hFont1
          and CHR$(223-226)

          Or any Unicode font such as ARIAL or COURIER NEW and CHR$$( 8592 - 8595) - note the double "$"



          Comment


          • #6
            I suggest -
            Change the program to Unicode (WSTRING type variables and CHR$$() to convert numbers to wstring)

            Font "Lucida Console" has arrows starting at h2190 (d8592), and other interesting characters to hFB02 (d64258) (see Character Map)

            Programs | Accessories | System Tools for Windows Character Map.

            Cheers,
            Dale

            Comment


            • #7
              Or this..
              Click image for larger version

Name:	Arrows.png
Views:	56
Size:	10.5 KB
ID:	770598
              Code:
              #COMPILE EXE
              #DIM ALL
              #CONSOLE OFF
              #INCLUDE "win32api.inc"
              
              FUNCTION PBMAIN() AS LONG
               LOCAL w, h, x, y, cw, ch AS LONG
               LOCAL pFont, hWin AS DWORD
               '  UCODEPAGE OEM
              
                FONT NEW "Terminal", 14, 0, 255 TO pFont
              
                w = 400 : h = 250 ' desired dialog size
                DESKTOP GET LOC TO x, y ' in case taskbar is on Left/Up side
                DESKTOP GET CLIENT TO cw, ch ' need DeskTop clien size
                x = x + ((cw - w) / 2) ' calculate centered x
                y = y + ((ch - h) / 2) ' calculate centered y
              
                GRAPHIC WINDOW "Arrows", x, y, w, h TO hWin
                GRAPHIC PRINT $CR + "PrintChr$(24,25,26,27)"
                GRAPHIC SET FONT pFont
                GRAPHIC PRINT CHR$(24,25,26,27)
                GRAPHIC SET FONT 0
                GRAPHIC PRINT "Esc to quit"
                GRAPHIC WAITKEY$($ESC)
              
              END FUNCTION
              Attached Files
              Rgds, Dave

              Comment


              • #8
                I don't have Terminal font on my Win 7 PC. WIth which versions of Windows does it come as standard?

                Edit: Correction, It is there in Charmap, but for some reason it doesn't show as an option in MS Word (which is where I initially went looking).




                Comment


                • #9
                  Dear Members:
                  Thanks for ALL the suggestions they ALL worked. 1st the chr$$(8595) worked great. 2nd the suggestion by Mr. Biggs worked also but only if I used the "Terminal" font name, why is this and where can I find these font names. I am a beginner at this power basic and it is embarrassing that I don't know about all this UNICODE stuff and etc. Where in power basic does it tell about the CHR$$ codes. Any way I really appreciate everyone taking the time to help me, it was very kind of you indeed. There are some very intelligent people on this forum and we are blessed to have you doing it. Again I greatly appreciate the help.

                  Leroy Hindman

                  Comment


                  • #10
                    Where in power basic does it tell about the CHR$$ codes.
                    It doesn't.

                    PowerBASIC Help will tell you how to use PB functions and statements (like CHR$ and CHR$$ in this case), but since PB does not create fonts, or assign values to characters, those are not documented in PB. You must other sources (like the Windows Character Map in this case). Character Map gives names of installed fonts, and the value for each character as hexidecimal. Note that CHR$() (and CHR$$()) can take literal inputs as decimal or hexdecimal (and binary etc), or as numeric variables.
                    Dale

                    Comment


                    • #11
                      Originally posted by Dale Yarker View Post
                      You must other sources (like the Windows Character Map in this case). Character Map gives names of installed fonts, and the value for each character as hexidecimal. Note that CHR$() (and CHR$$()) can take literal inputs as decimal or hexdecimal (and binary etc), or as numeric variables.
                      Note that CharMap displays the code for any selected character at the bottom left of the window. It will either appear in Hexadecimal notation as something like 0xDE or U+00DE

                      If the value is FF or less, you can use CHR$. If it is greater than FF, you need to use CHR$$. Bith CHR$ and CHR$$ can take either a Hexadecimal or Decimal value.

                      So ? CHR$(&HDE) or CHR$(222) will work.

                      When I want get the decimal value of Hex numbers (&HDE =222), I use the Windows calculator: Open CALC and hit Alt+F3 (or hit View - Programmer). Click on "Hex" enter your Hex value and click on "Dec".



                      Comment


                      • #12
                        Originally posted by Leroy Hindman View Post
                        Dear Members:
                        Thanks for ALL the suggestions they ALL worked. 1st the chr$$(8595) worked great. 2nd the suggestion by Mr. Biggs worked also but only if I used the "Terminal" font name, why is this
                        It's because Terminal was designed deliberately to emulate the OEM characters, including the arrows as code points 24-27.

                        Note that Terminal is not a Truetype font. It is a "raster" or "bitmapped" font so it is not "scaleable". You can only use a few defined sizes). It also is quite buggy if you try to use it like a Truetype font and not the defined sizes. I'd stick with a Unicode Truetype font and the higher code points.

                        Here's a couple of screen caps using Terminal font in Excel at various sizes and various Zoom levels. The left column is at 100% zoom, the right column is at 90% zoom.
                        Notice that there is no consistency in sizes depending on size and zoom, increasing the font size can actually display smaller characters and changing the Zoom changes the "point" at which the size changes.

                        Click image for larger version  Name:	TerminalZooms.jpg Views:	1 Size:	95.6 KB ID:	770614

                        See https://en.wikipedia.org/wiki/Terminal_(typeface)

                        Comment


                        • #13
                          Then again you can create your own Truetype font from the IBM CP437 as I did years ago and gee it scales very nicely.

                          Comment


                          • #14
                            Originally posted by Jim Fritts View Post
                            Then again you can create your own Truetype font from the IBM CP437 as I did years ago and gee it scales very nicely.
                            That sounds like an awful lot of work considering what the OP is trying to achieve - i.e. draw arrows in a graphic window

                            Comment


                            • #15
                              Yeah, it took a little work. You know, young dumb, and full of questions. Wingdings 3 is mostly Arrows even at 45, 135, 225, and 315 degrees. Or use the traditional arrows as found in Symbol.

                              Using Dave Biggs method and Symbol:

                              Code:
                              #COMPILE EXE
                              #DIM ALL
                              '#CONSOLE OFF
                              #INCLUDE "win32api.inc"
                              
                              FUNCTION PBMAIN() AS LONG
                               LOCAL w, h, x, y, cw, ch AS LONG
                               LOCAL pFont, hWin AS DWORD
                               '  UCODEPAGE OEM
                              
                                'FONT NEW "Terminal", 14, 0, 255 TO pFont
                                FONT NEW "Symbol", 14, 0, 255 TO pFont
                                'up     0xAD  173
                                'down   0xAF  175
                                'right  0xAE  174
                                'left   0xAC  172
                              
                                w = 400 : h = 250 ' desired dialog size
                                DESKTOP GET LOC TO x, y ' in case taskbar is on Left/Up side
                                DESKTOP GET CLIENT TO cw, ch ' need DeskTop clien size
                                x = x + ((cw - w) / 2) ' calculate centered x
                                y = y + ((ch - h) / 2) ' calculate centered y
                              
                                GRAPHIC WINDOW "Arrows", x, y, w, h TO hWin
                                GRAPHIC PRINT $CR + "PrintChr$(173,175,174,172)"
                                GRAPHIC SET FONT pFont
                                GRAPHIC PRINT CHR$(173,175,174,172)
                                GRAPHIC SET FONT 0
                                GRAPHIC PRINT "Esc to quit"
                                GRAPHIC WAITKEY$($ESC)
                              
                              END FUNCTION
                                                          
                              Last edited by Jim Fritts; 8 Mar 2018, 08:46 AM.

                              Comment

                              Working...
                              X