Draw xor-ed text (windows)

Share your advanced PureBasic knowledge/code with the community.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Draw xor-ed text (windows)

Post by Trond »

Code updated For 5.20+

You might have noticed that if you set the drawing mode to XOR this doesn't work for text. You can, however, do it like this:

Code: Select all

    Procedure PlotText(hDC.i, X.i, Y.i, Angle.f, Fontsize.i, Txt.s, DrawMode.i, Color.i)
      Define SavedDC.i
      Define LAngle.i
      Define NewFont.i, OldFont.i
      Define dl.i
      Define iROP2.i
      Define Usebrush.i, Oldbrush.i
      Define Italic.i
      Define Underline.i
      Define Strikeout.i
     
      If Fontsize < 0
        ProcedureReturn 0
      EndIf
      LAngle = Int(Angle * 10) % 3600
      SavedDC = SaveDC_(hDC)
     
      NewFont = CreateFont_(Fontsize, 0, Langle, 0, 0, Italic, Underline, Strikeout, #ANSI_CHARSET, #OUT_TT_PRECIS, 0, #DEFAULT_QUALITY, #FF_DONTCARE, "Tahoma")
      OldFont = SelectObject_(hDC, NewFont)
      dl = SetBkMode_(hDC, #TRANSPARENT)
      dl = BeginPath_(hDC)
      dl = TextOut_(hDC, X, Y, Txt, Len(Txt))
      dl = EndPath_(hDC)
      dl = SelectObject_(hDC, OldFont)
      dl = DeleteObject_(NewFont)
      iROP2 = SetROP2_(hDC, DrawMode)
      Usebrush = CreateSolidBrush_(Color)
      Oldbrush = SelectObject_(hDC, Usebrush)
      dl = FillPath_(hDC)
      dl = SetROP2_(hDC, iROP2)
      dl = SelectObject_(hDC, Oldbrush)
      dl = DeleteObject_(Usebrush)
      dl = RestoreDC_(hDC, SavedDC)
    EndProcedure



    OpenWindow(0, 0, 0, 200, 150, "Boxes")
    hDC = StartDrawing(WindowOutput(0))
      ;DrawingMode(1)
      DrawingMode(1|2)
      Box(20, 20, 100, 60, RGB(200, 50, 180))
      Box(30, 30, 80,  30, RGB(90, 128, 172))
      FrontColor(RGB(50, 234, 87))
      DrawText(25, 40, "Apple")
      PlotText(hDC, 40, 25, 0, 46, "W00t", #R2_NOTXORPEN, $678945)
    StopDrawing()

    Repeat
    Until  WaitWindowEvent() = #PB_Event_CloseWindow
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Nice. 8)

I did a similar thing a while back, but not as elegant as your method.

Thanks.
I may look like a mule, but I'm not a complete ass.
Post Reply