Scrollarea black

Post bugreports for the Linux version here
Justin
Enthusiast
Enthusiast
Posts: 770
Joined: Sat Apr 26, 2003 2:49 pm

Scrollarea black

Post by Justin »

This is how it looks the pb scrollarea example, Linux Mint 20 PB6
Image
User avatar
StarBootics
Addict
Addict
Posts: 847
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Scrollarea black

Post by StarBootics »

This problem was present for a very long time.

The following code present a workaround for this problem.

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : ScrollAreaGadget() Black background
; File Name : ScrollAreaGadget - Workaround.pb
; File version: 0.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : August 4th, 2022
; Last Update : August 4th, 2022
; PureBasic code : V6.00 LTS
; Platform : Linux
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Module WindowBackgroundColor
  
  Procedure.l FindIt(Window)
    
    If StartDrawing(WindowOutput(Window))
      Color.l = Point(3, 3)
      StopDrawing()
    EndIf
    
    If Color = 0 
      Color = RGB(239,235,231)
      Debug "Default Window Back color used !"
    EndIf
    
    ProcedureReturn Color
  EndProcedure
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  Procedure BindScrollDatas()
    SetWindowTitle(0, "ScrollAreaGadget " +
                      "(" +
                      GetGadgetAttribute(0, #PB_ScrollArea_X) +
                      "," +                      
                      GetGadgetAttribute(0, #PB_ScrollArea_Y) +
                      ")" )
  EndProcedure
  
  If OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    ScrollAreaGadget(0, 10, 10, 390,220, 575, 575, 30)
      Dummy = TextGadget(#PB_Any, 0, 0, GetGadgetAttribute(0, #PB_ScrollArea_InnerWidth), GetGadgetAttribute(0, #PB_ScrollArea_InnerHeight), "")
      SetGadgetColor(Dummy, #PB_Gadget_BackColor, WindowBackgroundColor::FindIt(0))
      
      ButtonGadget  (1, 10, 10, 230, 30,"Bouton 1")
      ButtonGadget  (2, 50, 50, 230, 30,"Bouton 2")
      ButtonGadget  (3, 90, 90, 230, 30,"Bouton 3")
      TextGadget    (4,130,130, 230, 60,"Ceci est le contenu d'une zone de défilement !",#PB_Text_Right)
    CloseGadgetList() 
    
    BindGadgetEvent(0, @ BindScrollDatas())
    
    Repeat 
      Select WaitWindowEvent() 
        Case  #PB_Event_CloseWindow 
          End 
        Case  #PB_Event_Gadget 
          Select EventGadget()
            Case 0
              MessageRequester("Info","Un ascenseur a été utilisé ! (" + GetGadgetAttribute(0, #PB_ScrollArea_X) +"," + GetGadgetAttribute(0, #PB_ScrollArea_Y) +")" ,#PB_MessageRequester_Ok)
            Case 1
              MessageRequester("Info","Le bouton 1 a été appuyé !",#PB_MessageRequester_Ok)
            Case 2
              MessageRequester("Info","Le bouton 2 a été appuyé !",#PB_MessageRequester_Ok)
            Case 3
              MessageRequester("Info","Le bouton 3 a été appuyé !",#PB_MessageRequester_Ok)
          EndSelect
      EndSelect 
    ForEver 
  EndIf
  
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Justin
Enthusiast
Enthusiast
Posts: 770
Joined: Sat Apr 26, 2003 2:49 pm

Re: Scrollarea black

Post by Justin »

A pity it has not been fixed, thanks for the workaround.
Justin
Enthusiast
Enthusiast
Posts: 770
Joined: Sat Apr 26, 2003 2:49 pm

Re: Scrollarea black

Post by Justin »

This fixes the problem:

Code: Select all

EnableExplicit

ImportC ""
	gtk_widget_get_style_context_(wd.i) As "gtk_widget_get_style_context"
	gtk_widget_get_allocation_(wd.i, alloc.i) As "gtk_widget_get_allocation"
	gtk_render_background_(sc.i, cr.i, x.d, y.d, width.d, height.d) As "gtk_render_background"
	
	cairo_set_source_rgb_(cr.i, r.d, g.d, b.d) As "cairo_set_source_rgb"
	cairo_paint_(cr.i) As "cairo_paint"
EndImport

Procedure ScrollAreaGadget_Fixed_on_draw(wd.i, cr.i, gd.i)
	Protected.i sc
	Protected.GtkAllocation alloc
	Protected.l color

	color = GetGadgetColor(gd, #PB_Gadget_BackColor)
	If color = #PB_Default
		sc = gtk_widget_get_style_context_(wd)
		gtk_widget_get_allocation_(wd, @alloc)
		gtk_render_background_(sc, cr, 0, 0, alloc\width, alloc\height)
		
	Else
		cairo_set_source_rgb_(cr, Red(color)/255, Green(color)/255, Blue(color)/255)
		cairo_paint_(cr)
	EndIf 
	
	ProcedureReturn 0
EndProcedure

Procedure ScrollAreaGadget_Fixed(gd.i, x.l, y.l, width.l, height.i, scrAreaWidth.l, scrAreaHeight.l, scrollStep.l = 1, flags.l = 0)
	Protected.i gdid
	
	gdid = ScrollAreaGadget(gd, x, y, width, height, scrAreaWidth, scrAreaHeight, scrollStep, flags)
	If gd <> #PB_Any
		gdid = gd
	EndIf 
	g_signal_connect_(gtk_bin_get_child_(gtk_bin_get_child_(GadgetID(gdid))), "draw", @ScrollAreaGadget_Fixed_on_draw(), gd)

	ProcedureReturn gdid
EndProcedure

Procedure BindScrollDatas()
	SetWindowTitle(0, "ScrollAreaGadget " +
	"(" +
	GetGadgetAttribute(0, #PB_ScrollArea_X) +
	"," +                      
	GetGadgetAttribute(0, #PB_ScrollArea_Y) +
	")" )
EndProcedure

If OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ScrollAreaGadget_Fixed(0, 10, 10, 390,220, 575, 555, 30)
	ButtonGadget  (1, 10, 10, 230, 30,"Change Color")
	ButtonGadget  (2, 50, 50, 230, 30,"Default Color")
	ButtonGadget  (3, 90, 90, 230, 30,"Button 3")
	TextGadget    (4,130,130, 230, 20,"This is the content of a ScrollAreaGadget!",#PB_Text_Right)
	CloseGadgetList()
	
	BindGadgetEvent(0, @BindScrollDatas())
	
	Repeat
		Select WaitWindowEvent()
			Case  #PB_Event_CloseWindow
			End
			Case  #PB_Event_Gadget
			Select EventGadget()
				Case 0
				
				Case 1
					SetGadgetColor(0, #PB_Gadget_BackColor, RGB(Random(255, 0), Random(255, 0), Random(255, 0)))

				Case 2
					SetGadgetColor(0, #PB_Gadget_BackColor, #PB_Default)

				Case 3
					
			EndSelect
		EndSelect
	ForEver
EndIf
Justin
Enthusiast
Enthusiast
Posts: 770
Joined: Sat Apr 26, 2003 2:49 pm

Re: Scrollarea black

Post by Justin »

SetGadgetColor() was also broken so i fixed it, code updated.
Image
Image
Post Reply