EditorGadget invisible?

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

EditorGadget invisible?

Post by charvista »

Hi

I have a problem with the EditorGadget: it is invisible???
Please launch the program below, then press Ctrl+A. You will then see the selection of the invisible EditorGadget.
The problem occurs when on an image. Most other gadgets do not have this problem.
Am I missing something?

Code: Select all

Win=OpenWindow(#PB_Any, 0, 0, 400, 255, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Im=CreateImage(#PB_Any, 400, 255)
StartDrawing(ImageOutput(Im))
For k=0 To 255
    FrontColor(RGB(k,0,k))
    Line(0,k,400,1)
Next
StopDrawing()

LoadFont(9,"Courier New",18)
E=EditorGadget(#PB_Any, 8, 8, 350, 210,#PB_Editor_WordWrap)
SetGadgetColor(E,#PB_Gadget_BackColor,$FF0000)
SetGadgetColor(E,#PB_Gadget_FrontColor,$FFFFFF)
SetGadgetFont(E,FontID(9))
For a = 0 To 5
    AddGadgetItem(E, a, "Line "+Str(a))
Next
SetActiveGadget(E); we put the cursor in the EditorGadget

Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Repaint
        StartDrawing(WindowOutput(Win))
        DrawImage(ImageID(Im),0,0)
        StopDrawing()    
    EndIf
    
Until Event = #PB_Event_CloseWindow
Thanks!
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: EditorGadget invisible?

Post by Danilo »

You are drawing an image over the gadget, so it is logical it's invisible.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: EditorGadget invisible?

Post by netmaestro »

The following code shows how to use a background window image on the Windows OS:

Code: Select all

Win=OpenWindow(#PB_Any, 0, 0, 400, 255, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Im=CreateImage(#PB_Any, 400, 255)
StartDrawing(ImageOutput(Im))
  For k=0 To 255
    FrontColor(RGB(k,0,k))
    Line(0,k,400,1)
  Next
StopDrawing()

LoadFont(9,"Courier New",18)
E=EditorGadget(#PB_Any, 8, 8, 350, 210,#PB_Editor_WordWrap)
SetGadgetColor(E,#PB_Gadget_BackColor,$FF0000)
SetGadgetColor(E,#PB_Gadget_FrontColor,$FFFFFF)
SetGadgetFont(E,FontID(9))
For a = 0 To 5
  AddGadgetItem(E, a, "Line "+Str(a))
Next
SetActiveGadget(E); we put the cursor in the EditorGadget

hBrush=CreatePatternBrush_(ImageID(Im))
SetClassLongPtr_(WindowID(Win),#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(WindowID(Win),0,1)

Repeat
  Event = WaitWindowEvent()
  
Until Event = #PB_Event_CloseWindow
DeleteObject_(hBrush)
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget invisible?

Post by IdeasVacuum »

Another solution that works, but is not officially supported so a future PB release could break it: CanvasGadget, draw on the Canvas, disable the CanvasGadget, plonk your other gadgets on top.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget invisible?

Post by RASHAD »

Hi
Another approach

Code: Select all

Im=CreateImage(#PB_Any, 400, 255)
StartDrawing(ImageOutput(Im))
For k=0 To 255
    FrontColor(RGB(k,0,k))
    Line(0,k,400,1)
Next
StopDrawing()

Win=OpenWindow(#PB_Any, 0, 0, 400, 255, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
I = ImageGadget(#PB_Any,0,0,400,255,ImageID(Im))
DisableGadget(I,1)

LoadFont(9,"Courier New",18)
ContainerGadget(#PB_Any,8,8,350,210,#PB_Container_BorderLess)                          ;For No Border EditorGadget 
  E=EditorGadget(#PB_Any, -2, -2, 354, 214,#PB_Editor_WordWrap)
CloseGadgetList()

;E=EditorGadget(#PB_Any, 8, 8, 350, 210,#PB_Editor_WordWrap)  

SetGadgetColor(E,#PB_Gadget_BackColor,$FF0000)
SetGadgetColor(E,#PB_Gadget_FrontColor,$FFFFFF)
SetGadgetFont(E,FontID(9))
For a = 0 To 5
    AddGadgetItem(E, a, "Line "+Str(a))
Next

SetWindowLongPtr_(GadgetID(I), #GWL_STYLE, GetWindowLongPtr_(GadgetID(I), #GWL_STYLE) | #WS_CLIPSIBLINGS )
SetWindowPos_(GadgetID(I), #HWND_BOTTOM, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)

SetActiveGadget(E); we put the cursor in the EditorGadget

Repeat
    Event = WaitWindowEvent()
   
;     If Event = #PB_Event_Repaint
;         StartDrawing(WindowOutput(Win))
;         DrawImage(ImageID(Im),0,0)
;         StopDrawing()   
;     EndIf
   
Until Event = #PB_Event_CloseWindow

Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: EditorGadget invisible?

Post by charvista »

@Danilo
Yes, it is logical, but a TextGadget() for example can be drawn on an image. I thought that the EditorGadget() would work similarly :wink:

@netmaestro
Thank you so much for your solution! And it works. Perfect! :D

@IdeasVacuum
This morning, when I wake up, I had the same idea as you, defining a CanvasGadget() on which I could put the EditorGadget(). But netmaestro's and RASHAD's solutions are easier. Thank you for the idea, and yes, who knows that a future release of PB could combine internally the Canvas with the different gadgets to make them useable on background images. :wink:

@RASHAD
Thank you so much for your solution RASHAD! Very interesting alternative, because it is frameless, which is excellent for creating a custom-made EditorGadget(). :D


Cheers!
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget invisible?

Post by IdeasVacuum »

...you can use Rashad's code with a CanvasGadget instead of an ImageGadget (as demonstrated by Rashed in another post).
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: EditorGadget invisible?

Post by charvista »

Hi again,

Bad news. :( I was too happy with the solutions, I used a simple example and it seemed to work.
However, my real code contains LinearGradient, and I still have many troubles with the EditorGadget it.
I could replicate a problem that fails.

Code: Select all

X=0:Y=0:W=400:H=255
Win=OpenWindow(#PB_Any,X,Y,W,H, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Im=CreateImage(#PB_Any, 400, 255)
ImGad=ImageGadget(#PB_Any,X,Y,W,H,ImageID(Im))

StartDrawing(ImageOutput(Im))
Box(0,0,W,H,$FFFFFF)
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($00FFFF)
FrontColor($FF0000)
LinearGradient(W/2,0+Y,W/2,H+Y)
Box(X,Y,W,H)

;For k=0 To 255
;    FrontColor(RGB(k,0,k))
;    Line(0,k,400,1)
;Next

StopDrawing()

SetGadgetState(ImGad,ImageID(Im))
DisableGadget(ImGad,1)

T=TextGadget(#PB_Any,10,235,380,15,"This is a textgadget over an image, it works.")
SetGadgetColor(T,#PB_Gadget_BackColor,$404040)

LoadFont(9,"Courier New",12)
E=EditorGadget(#PB_Any, 18, 18, 300, 180,#PB_Editor_WordWrap)
SetGadgetColor(E,#PB_Gadget_BackColor,$FF0000)
SetGadgetColor(E,#PB_Gadget_FrontColor,$FFFFFF)
SetGadgetFont(E,FontID(9))
For a = 0 To 3
    AddGadgetItem(E, a, "Line "+Str(a))
Next
AddGadgetItem(E,5,"Hit 3 times on [Enter]")
AddGadgetItem(E,6,"and the gadget will vanish!")
SetActiveGadget(E)

hBrush=CreatePatternBrush_(ImageID(Im))
SetClassLongPtr_(WindowID(Win),#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(WindowID(Win),0,1)

Repeat
    Event = WaitWindowEvent()
    
Until Event = #PB_Event_CloseWindow
Hit 3 times on the Enter key and you will see the problem. Looks like a big bug...

Using PureBasic 5.20 LTS (x86) on Windows 8.1

Thanks for looking at it.
Cheers
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: EditorGadget invisible?

Post by netmaestro »

There is no bug as the method you're using involves overlapping gadgets. Overlapped gadgets are unsupported in PureBasic. If overlapping seems to work in some cases, fine but in any case where you get odd behavior, it's because the rules weren't followed. If you use a background brush, you'll be able to hit enter until your finger falls off and then you won't have a finger but you will still be able to see your editor gadget. Small consolation, I know :wink:
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget invisible?

Post by IdeasVacuum »

...hit Enter 4 times and it is back again...... it looks like it has something to do with how 'overflow' text is handled - I thought perhaps the scroll bar needs to be 'always on'. It's not a bug because we are trying to do something here which is not officially supported by PB. Surprised it is not working though, apparently because of the gradient shading.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget invisible?

Post by RASHAD »

Hi charvista
Not tested with Windows 8.1 :)
But it should be OK

Code: Select all

X=0:Y=0:W=400:H=255
Win=OpenWindow(#PB_Any,X,Y,W,H, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Im=CreateImage(#PB_Any, 400, 255)
ImGad=ImageGadget(#PB_Any,X,Y,W,H,ImageID(Im))

StartDrawing(ImageOutput(Im))
Box(0,0,W,H,$FFFFFF)
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($00FFFF)
FrontColor($FF0000)
LinearGradient(W/2,0+Y,W/2,H+Y)
Box(X,Y,W,H)

;For k=0 To 255
;    FrontColor(RGB(k,0,k))
;    Line(0,k,400,1)
;Next

StopDrawing()

SetGadgetState(ImGad,ImageID(Im))
DisableGadget(ImGad,1)

T=TextGadget(#PB_Any,10,230,380,20,"This is a textgadget over an image, it works.",#SS_CENTERIMAGE | #SS_CENTER| #WS_BORDER)
SetGadgetColor(T,#PB_Gadget_BackColor,$B0B0B2)

LoadFont(9,"Courier New",12)
E=EditorGadget(#PB_Any, 18, 18, 300, 180,#PB_Editor_WordWrap)
SetGadgetColor(E,#PB_Gadget_BackColor,$FF0000)
SetGadgetColor(E,#PB_Gadget_FrontColor,$FFFFFF)
SetGadgetFont(E,FontID(9))
For a = 0 To 3
    AddGadgetItem(E, a, "Line "+Str(a))
Next
AddGadgetItem(E,5,"Hit 3 times on [Enter]")
AddGadgetItem(E,6,"and the gadget will vanish!")

SetWindowLongPtr_(GadgetID(ImGad), #GWL_STYLE, GetWindowLongPtr_(GadgetID(ImGad), #GWL_STYLE) | #WS_CLIPSIBLINGS )
SetWindowPos_(GadgetID(ImGad), #HWND_BOTTOM, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)

SetActiveGadget(E)

; hBrush=CreatePatternBrush_(ImageID(Im))
; SetClassLongPtr_(WindowID(Win),#GCL_HBRBACKGROUND,hBrush)
; InvalidateRect_(WindowID(Win),0,1)

Repeat
    Event = WaitWindowEvent()
   
Until Event = #PB_Event_CloseWindow
Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: EditorGadget invisible? AnimateWindow_()

Post by charvista »

It seems that I have about the same kind of problem as Poshu... http://purebasic.fr/english/viewtopic.php?f=13&t=57156
RASHAD's last code works perfectly on Windows 8.1!
But I still had problems. Hard problems, the EditorGadget refused to be displayed!
I searched all day for the reason, and finally found it: AnimateWindow_() !
Here is my test code:

Code: Select all

ExamineDesktops()
Global _DW.i=DesktopWidth(0)
Global _DH.i=DesktopHeight(0)

Procedure.i zBaseImage(Array ImX.i(1),X.i,Y.i,W.i,H.i)
    Dim ImX.i(1)
    ImCre=CreateImage(#PB_Any,W,H)
    ImGad=ImageGadget(#PB_Any,X,Y,W,H,ImageID(ImCre))
    DisableGadget(ImGad,1)
    InvalidateRect_(GadgetID(ImGad),0,1)
    ImX(0)=ImCre; #Image
    ImX(1)=ImGad; #Gadget
    ProcedureReturn ImGad
EndProcedure

Procedure zGradient(Array Im.i(1),Dir.i,X.i,Y.i,W.i,H.i,Color1.i,Color2.i,Update.i=1)
    StartDrawing(ImageOutput(Im(0)))
        DrawingMode(#PB_2DDrawing_Gradient)
        BackColor(Color1)
        FrontColor(Color2)
        LinearGradient(W/2,0+Y,W/2,H+Y)
        Box(X,Y,W,H)
    StopDrawing()
    If Update
        SetGadgetState(Im(1),ImageID(Im(0)))
    EndIf
    DisableGadget(Im(1),1); no click on it
    ;InvalidateRect_(GadgetID(Im(1)),0,1)
EndProcedure

Procedure.i zEdit(Array ImX.i(1),X.i,Y.i,W.i,H.i,StrValue.s)
    BkColor=$004000
    Color=$FFFFFF
    Label=EditorGadget(#PB_Any,X,Y,W,H,#PB_Editor_WordWrap)
    SetGadgetColor(Label,#PB_Gadget_BackColor,BkColor)
    SetGadgetColor(Label,#PB_Gadget_FrontColor,Color)
    AddGadgetItem(Label,0,StrValue.s)
    SetGadgetState(ImX(1),ImageID(ImX(0)))
    ;DisableGadget(ImX(1),1); no click on it
    ;InvalidateRect_(GadgetID(ImX(1)),0,1)
    ProcedureReturn Label
EndProcedure
; =======================================================================================================================
Win=OpenWindow(#PB_Any,0,0,_DW,_DH,"",#PB_Window_BorderLess|#PB_Window_Invisible)
Dim ImA(0)
zBaseImage(ImA(),0,0,_DW,_DH)
zGradient(ImA(),1,0,0,_DW,_DH,$000000,$D419FF,0)
HideWindow(Win,0)

; =======================================================================================================================
Dim ImB(0)
DisableWindow(Win,1)
Win2=OpenWindow(#PB_Any,50,50,_DW-100,_DH-100,"",#PB_Window_BorderLess|#PB_Window_Invisible,WindowID(Win))
zBaseImage(ImB(),0,0,_DW-100,_DH-100)
zGradient(ImB(),1,0,0,_DW-100,_DH-100,$000000,$D4194A,0)
Btn2=ButtonGadget(#PB_Any,350,100,100,30,"Exit")

E2=zEdit(ImB(),100,100,200,200,"This is an EditorGadget")
SetWindowLongPtr_(GadgetID(ImB(1)), #GWL_STYLE, GetWindowLongPtr_(GadgetID(ImB(1)), #GWL_STYLE) | #WS_CLIPSIBLINGS )
SetWindowPos_(GadgetID(ImB(1)),#HWND_BOTTOM, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)

SetActiveGadget(E2)

; The problem is that the API AnimateWindow_() works differently than HideWindow()!
; Try first with HideWindow(), it will work correctly,
; then try with AnimateWindow_(), nothing will be visible (Press Alt+F4 to exit!)

; AnimateWindow_(WindowID(Win2.i),Speed.i,#AW_ACTIVATE|#AW_BLEND)
HideWindow(Win2,0)

Repeat
    Event=WaitWindowEvent(5)
    Select Event
    Case #PB_Event_CloseWindow
        Quit=1
    Case #PB_Event_Gadget
        Gadget=EventGadget()
        Select Gadget
        Case Btn2
            Quit=1
        EndSelect
    EndSelect
Until Quit
CloseWindow(Win2)
DisableWindow(Win,0)
First try it as coded: it will work.
Then, activate line 68 and deactivate line 69, and run it. Empty!!
Press Alt+F4 to exit...
I am using AnimateWindow_() because it is softer than HideWindow().

So, in my code, I do not change AnimateWindow_() for HideWindow(), but then I cannot use EditorGadget().
However, I have found an alternative in the CodeArchive4:

Code: Select all

; English forum: http://www.purebasic.fr/english/viewtopic.php?t=6507
; Author: PB (updated for PB4.00 by blbltheworm)
; Date: 12. June 2003
; OS: Windows
; Demo: Yes

If OpenWindow(0,200,200,300,200,"test",#PB_Window_SystemMenu) 
  CreateGadgetList(WindowID(0)) 
  t$="This text goes inside a multiline StringGadget."+Chr(13)+Chr(10) 
  For r=1 To 10 : t$+Str(r)+Chr(13)+Chr(10) : Next 
  StringGadget(0,10,10,200,100,t$,#ES_MULTILINE|#ES_AUTOVSCROLL|#WS_VSCROLL|#WS_HSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT) 
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 
EndIf 
and this works with AnimatedWindow_() and background images :)

Cheers
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Post Reply