Text Contrast Test

Share your advanced PureBasic knowledge/code with the community.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Text Contrast Test

Post by chris319 »

Here is an odd little program which tests the contrast between text foreground and background.

Note that the characters take on a faded gray appearance when the background is white, at least they do on my monitor (Samsung) -- do they on yours? I don't know why that is.

Press the ESC key to exit the program.

Code: Select all

H_RES = GetSystemMetrics_(#SM_CXSCREEN)
V_RES = GetSystemMetrics_(#SM_CYSCREEN)

InitKeyboard()

OpenWindow(1, 0, 0, H_RES, V_RES, "",#PB_Window_BorderLess)
AddKeyboardShortcut(1,#PB_Shortcut_Escape, #PB_Shortcut_Escape) ;"ESCAPE" KEY TO QUIT PROGRAM
ShowCursor_(#False)
LoadFont(1,"Arial",36)

Repeat
SetWindowColor(1, #Black)

timeout = ElapsedMilliseconds() + 2000
    While ElapsedMilliseconds() < timeout
StartDrawing(WindowOutput(1))
;Box(H_RES/2-200,V_RES/2-200,400,400,#Gray)
DrawingFont(FontID(1))

DrawingMode(#PB_2DDrawing_Transparent)
DrawText(H_RES/2-TextWidth("TEXT CONTRAST TEST")/2,V_RES/2-18,"TEXT CONTRAST TEST",#White)

StopDrawing()
      event = WaitWindowEvent(1)
If event = #PB_Event_Menu ;KEYBOARD INPUT
      menuItem = EventMenu()

      Select menuItem
        Case #PB_Shortcut_Escape
        CloseWindow(1):End  
EndSelect
EndIf


    Wend
If event = #PB_Event_CloseWindow:CloseWindow(1):End:EndIf
SetWindowColor(1, #White)

timeout = ElapsedMilliseconds()+2000
    While ElapsedMilliseconds() < timeout
StartDrawing(WindowOutput(1))
;Box(H_RES/2-200,V_RES/2-200,400,400,#Gray)
DrawingFont(FontID(1))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(H_RES/2-TextWidth("TEXT CONTRAST TEST")/2,V_RES/2-18,"TEXT CONTRAST TEST",#Black)
StopDrawing()

      event = WaitWindowEvent(1)

If event = #PB_Event_Menu ;KEYBOARD INPUT
      menuItem = EventMenu()

      Select menuItem
        Case #PB_Shortcut_Escape
        CloseWindow(1):End  
EndSelect
EndIf

    Wend

ForEver