PureBoard
http://forums.purebasic.com/german/

Transparent Text mit LCLK/RCLK
http://forums.purebasic.com/german/viewtopic.php?f=16&t=31657
Seite 1 von 1

Autor:  Velindos [ 10.09.2019 17:19 ]
Betreff des Beitrags:  Transparent Text mit LCLK/RCLK

Hallo Leute!

Möchte den TEXT Tranparent anzeigen.

Erstelle eine Img_TransparenterText, ist aber nicht Transparent!

Code:
;===============================================================
UsePNGImageDecoder()
UsePNGImageEncoder()
;===============================================================
Enumeration
  #Gdt_Image
  #Gdt_String
 
  #Img_BackImage
  #Img_TransparenterText
  #Img_Transparente_Vorlage
  #Img_Transparente_Blender
EndEnumeration
;===============================================================
Global *gOldEditProc_01

Global K = 210

Global Present_Window
;===============================================================
Global Main_X = 320
Global Main_Y = 240
;===============================================================
; Warum geht das nicht mit #PB_Any
Global Img_BackImage = CreateImage(#Img_BackImage, Main_X ,Main_Y,24,#Red)

Global Font_Stichwort = LoadFont(#PB_Any, "Arial", 10, #PB_Font_Bold|#PB_Font_Italic|#PB_Font_HighQuality)

Global Img_TransparenterText = CreateImage(#Img_TransparenterText,200,20,24,#PB_Image_Transparent)
StartDrawing(ImageOutput(#Img_TransparenterText))
DrawingFont(FontID(Font_Stichwort))
DrawingMode(#PB_2DDrawing_Transparent )
; DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawText(0,0, "TransparenterText", $8B8B00)
StopDrawing()

Global Img_Transparente_Vorlage = CreateImage(#Img_Transparente_Vorlage,200,20,24,#PB_Image_Transparent)
StartDrawing(ImageOutput(#Img_Transparente_Vorlage))
DrawingFont(FontID(Font_Stichwort))
DrawingMode(#PB_2DDrawing_Transparent )
DrawText(0,0, "", $8B8B00)
StopDrawing()

Global Image_X = ImageWidth(#Img_BackImage)
Global Image_Y = ImageHeight(#Img_BackImage)
Main_X = Image_X
Main_Y = Image_Y
;===============================================================

Procedure SetWindowBackgroundImage(hWnd.i, hImage.i)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected Widget.I, Container.I, Layer.I
     
      Widget.I = gtk_bin_get_child_(hWnd)
      Container = gtk_container_get_children_(Widget)
      Layer = g_list_nth_data_(Container, 0)
      g_list_free_(Container)
      If Layer
        If PeekS(gtk_widget_get_name_(Layer), -1, #PB_UTF8) = "GtkFixed"
          gtk_fixed_put_(Layer, gtk_image_new_from_pixbuf_(hImage), 0, 0)
        Else
          gtk_layout_put_(Layer, gtk_image_new_from_pixbuf_(hImage), 0, 0)
        EndIf
       
        gtk_widget_show_all_(hWnd)
      EndIf
     
    CompilerCase #PB_OS_Windows
      Protected hBrush = CreatePatternBrush_(hImage)
      If hBrush
        SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
        InvalidateRect_(hWnd, 0, #True)
        UpdateWindow_(hWnd)
      EndIf
     
    CompilerCase #PB_OS_MacOS
      CocoaMessage(0, hWnd, "setBackgroundColor:",CocoaMessage(0, 0, "NSColor colorWithPatternImage:", hImage))
  CompilerEndSelect
EndProcedure
Procedure SetgadgetImageText(GGadget,TText.s)
  ; Macht die Schrift aber nicht Transparent
  CreateImage(#Img_Transparente_Blender,200,20,24,#PB_Image_Transparent)
  StartDrawing(ImageOutput(#Img_Transparente_Blender))
  DrawingFont(FontID(Font_Stichwort))
  DrawingMode(#PB_2DDrawing_Transparent )
  DrawText(0,0, TText, $8B8B00)
  StopDrawing()
  SetGadgetState(GGadget,ImageID(#Img_Transparente_Blender))
EndProcedure
;===============================================================

Procedure DplClk_Present_Image(Present_Window, uMsg, wParam, lParam)
  ; *gOldEditProc_01  =  SetWindowLongPtr_(GadgetID(#Gdt_Image), #GWL_WNDPROC, @DplClk_Present_Image())
  Protected Result
  Select uMsg
    Case #WM_LBUTTONDOWN
      Debug "LCLK"
      SetGadgetState(#Gdt_Image,ImageID(#Img_TransparenterText))
     
    Case #WM_RBUTTONDOWN
      Debug "RCLK"
      SetgadgetImageText(#Gdt_Image,"RCLK")
     
    Default
      Result   =  CallWindowProc_(*gOldEditProc_01, Present_Window, uMsg, wParam, lParam)
  EndSelect
  ProcedureReturn Result
EndProcedure

Present_Window = OpenWindow(#PB_Any,0,0,Main_X,Main_Y,"Transparent Text mit LCLK/RCLK",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowBackgroundImage(WindowID(Present_Window), ImageID(#Img_BackImage))
; 2.Version
ImageGadget(#Gdt_Image,10,10,200,20,ImageID(#Img_Transparente_Vorlage))
; DisableGadget(#Gdt_Image, #True)

*gOldEditProc_01  =  SetWindowLongPtr_(GadgetID(#Gdt_Image), #GWL_WNDPROC, @DplClk_Present_Image())
; *gOldEditProc_01  =  SetWindowLongPtr_(WindowID(Present_Window), #GWL_WNDPROC, @DplClk_Present_Image())

Repeat
  EventID = WaitWindowEvent()
 
  Select EventID
      ;     Case #WM_MOUSEHWHEEL
      ;     Case #WM_MOUSEMOVE
  EndSelect
Until EventID = #PB_Event_CloseWindow



Jemand eine Idee?

Gruss ... Velindos!

Autor:  Andesdaf [ 10.09.2019 23:08 ]
Betreff des Beitrags:  Re: Transparent Text mit LCLK/RCLK

Um #PB_Image_Transparent nutzen zu können, musst du zunächst mal die Farbtiefe auf 32 Bit umstellen.
Für Alpha-Zeichnen muss dann noch das #PB_2DDrawing_AlphaBlend-Flag und bei den Zeichen-
operationen auch der entsprechende Alpha-Wert gesetzt werden.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/