Annoying Window Gadget Redraw [SOLVED]

Just starting out? Need help? Post your questions and find answers here.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Annoying Window Gadget Redraw [SOLVED]

Post by LiK137 »

very polite Window Gadgets appearing, one by one.
Core i7 4930MX/32G/K5100M/500SSD/Win7
I will be very happy to see the code working smooth.

Code: Select all

;{ Declz
;{ Radar
#Width  = 625
#Height = 595

#RWidth= 320
#RHeight=340

PI.f = 3.141593

#x_0 = #RWidth / 2
#y_0 = #RHeight / 2

#rotator_speed = 2
#max_objects = 10
CurrentAngle = 180

Structure _OBJ
  x.l
  y.l
  Transparency.l
  Degree.f
EndStructure

Global Dim Objects._OBJ(#max_objects)

Declare.f winkel(x1.f,y1.f,x2.f,y2.f)
Declare.f GSin(winkel.f)
Declare.f GCos(winkel.f)
Declare ObjectSound(x)
Declare MakeSprites()
;}
;{ General
Declare Shell()
Declare .b WindowOnTop(ontop)
Declare.i SetWindowTransparency(Window.i, transparency.i) 
;}
;} Declz
Global RadarGo.b=#True

Shell()  

Procedure Shell()
;{ InProcDeclz  
Enumeration
   #SILDE_LEFT
   #SILDE_TOP
   #SILDE_RIGHT
   #SILDE_BOTTOM
EndEnumeration

Enumeration   
   #HIDE_CAPTION   
   #HIDE_ICON
   #HIDE_SLIDE
EndEnumeration

#SLIDE_ACCEL = 0.5
#SILDE_DIRECTION = #SILDE_RIGHT

#HIDE_TIMEOUT = 2000
#HIDE_METHOD = #HIDE_SLIDE

SlideAccel.f = 0
SlideSpeed.f = 0
;}
;{ INITWin
UsePNGImageDecoder()
OpenWindow(0,0,0,#Width,#Height,"KTIPOShell",#WS_OVERLAPPEDWINDOW | #WS_VISIBLE | 1 | #PB_Window_BorderLess)
HideFromTaskBar(WindowID(0),1)
WindowOnTop(WindowID(0))
Color = RGB(0, 0, 0)
InitWW = WindowWidth(0):InitWH = WindowHeight(0)
SetWindowColor(0, Color)
SetWindowTransparency(0,240)
SetWindowLong_(WindowID(0),#GWL_STYLE,#WS_DLGFRAME | #WS_VISIBLE)
ResizeWindow(0,#PB_Ignore,#PB_Ignore,InitWW,InitWH)
;}
;{ AddGadgets
   CatchImage(0, ?Bio1)
   CatchImage(1, ?NET)
   CatchImage(2, ?Hostname)
   CatchImage(3, ?IP)
   CatchImage(4, ?Tutor)
   CatchImage(5, ?ShutDown)
   ButtonImageGadget(0, 5, 5, 150, 110, ImageID(0),#PB_Button_Toggle)
   ButtonImageGadget(1, 160, 5, 150, 110, ImageID(1),#PB_Button_Toggle)
   ButtonImageGadget(2, 5, 120, 150, 110, ImageID(2),#PB_Button_Toggle)
   ButtonImageGadget(3, 160, 120, 150, 110, ImageID(3),#PB_Button_Toggle)
   ButtonImageGadget(4, 5, 235, 150, 110, ImageID(4))
   ButtonImageGadget(5, 160, 235, 150, 110, ImageID(5))
   
   EditorGadget(9, 5, 345, 305, 220,#PB_Editor_ReadOnly|#PB_Editor_WordWrap):SetGadgetColor(9,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(9,#PB_Gadget_BackColor,RGB(0,0,0))
   ComboBoxGadget(10, 5, 570, 305, 20,#PB_ComboBox_Editable)
   AddGadgetItem(10, -1, "SomeItm1")
   AddGadgetItem(10, -1, "SomeItm2")
   AddGadgetItem(10, -1, "SomeItm3")
   AddGadgetItem(10, -1, "SomeItm4")
   AddGadgetItem(10, -1, "SomeItm5")
   AddGadgetItem(10, -1, "SomeItm6")
   AddGadgetItem(10, -1, "SomeItm7")
   AddGadgetItem(10, -1, "SomeItm8")
   AddGadgetItem(10, -1, "SomeItm9")
   AddGadgetItem(10, -1, "SomeItm10")
   AddGadgetItem(10, -1, "SomeItm11")
   AddGadgetItem(10, -1, "SomeItm12")
   AddGadgetItem(10, -1, "SomeItm13")
   SetGadgetState(10,0)
   
   StringGadget(11, 315, 345, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(11,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(11,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(12, 315, 365, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(12,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(12,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(13, 315, 385, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(13,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(13,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(14, 315, 405, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(14,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(14,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(15, 315, 425, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(15,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(15,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(16, 315, 445, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(16,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(16,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(17, 315, 465, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(17,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(17,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(18, 315, 485, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(18,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(18,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(19, 315, 505, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(19,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(19,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(20, 315, 525, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(20,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(20,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(21, 315, 545, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(21,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(21,#PB_Gadget_BackColor,RGB(0,0,0))
   StringGadget(22, 315, 570, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(22,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(22,#PB_Gadget_BackColor,RGB(0,0,0))

   ;}   
;{ AddShortCuts
AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Home, 1)
AddKeyboardShortcut(0, #PB_Shortcut_End, 2)
AddKeyboardShortcut(0, #PB_Shortcut_PageUp, 3)
AddKeyboardShortcut(0, #PB_Shortcut_PageDown, 4)
AddKeyboardShortcut(0, #PB_Shortcut_Up, 5)
AddKeyboardShortcut(0, #PB_Shortcut_Down, 6)

AddKeyboardShortcut(0, #PB_Shortcut_Alt|#PB_Shortcut_Up, 7)
AddKeyboardShortcut(0, #PB_Shortcut_Alt|#PB_Shortcut_Down, 8)
;}
;{ Screen
  InitKeyboard()
  InitSprite()
  InitSound()
  OpenWindowedScreen(WindowID(0),#Width/2,0,#RWidth,#RHeight,0,0, #PB_Screen_SmartSynchronization)
  CatchSound(0,?Sonar)
  CatchSound(2,?BGSound)
  MakeSprites()
;}
;{ - Init RadarObjects
;{ Object3
xKoo = 5
yKoo = 30
Objects(3)\x      = xKoo
Objects(3)\y      = yKoo
If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) > 360
  Objects(3)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) - 360
Else
  Objects(3)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1)
EndIf
;}
;}
;}
;{ Main LOOP
  PlaySound(2,1)
  SoundVolume(0, 50)
  SoundVolume(2, 60)
  
  dLh.l = FindWindow_("ComboLBox",0) 
 
Repeat
  If SoundStat.b=#True
    SetWindowTransparency(0,240)
    ResumeSound(2) 
  Else
    SetWindowTransparency(0,70)
    PauseSound(2)
  EndIf
  
  ;{ HideWin  
   ;{ Get cursor position & window metrics
   GetCursorPos_(cpt.POINT)
   GetWindowRect_(WindowID(0),wrc.RECT)
   
   WX = wrc\left : WW = wrc\right-wrc\left
   WY = wrc\top : WH = wrc\bottom-wrc\top
   ;}
   ;{ Check wether mouse is out- or inside the window
   If (cpt\x < WX Or cpt\x >= (WX + WW) Or cpt\y < WY Or cpt\y >= (WY + WH)) : SoundStat.b=#False
      If isTimeSet = #False
         isTimeSet = #True
         
         HideWindow = #True
         
         InitWX = WX : InitWW = WindowWidth(0)
         InitWY = WY   : InitWH = WindowHeight(0)
         
         TimerInit = ElapsedMilliseconds()
      EndIf
   Else
      If SlideOut = #False : HideWindow = #False : isTimeSet = #False : EndIf
      SoundStat.b=#True
     ;} 
   ;{ Restore from slide mode
      If (cpt\x >= WX Or cpt\y >= WY Or cpt\y < (WY + WH)) And isHidden = #True And #HIDE_METHOD = #HIDE_SLIDE And SlideIn = #False
         SlideIn = #True
      EndIf
   EndIf
      ;}
   ;{ Sliding window back in sight
   If SlideIn = #True
      SlideAccel + #SLIDE_ACCEL
      SlideSpeed + SlideAccel      
      If WindowX(0) <=InitWX
         SlideOut = #False
         SlideIn = #False
         isHidden = #False
         
         SlideAccel = 0 : SlideSpeed = 0
         ;SetWindowLong_(WindowID(0),#GWL_STYLE,#WS_OVERLAPPEDWINDOW ) ; ShowCaption
         ;HideWindow(0,0)
         RadarPreStat.b=RadarStat.b
         RadarStat.b=#True
         ;AU3_AutoItSetOption_("MouseCoordMode",0)  ; set x,y coordinates to active window
         ;AU3_MouseMove_(620,590,9)  ; last parm controls speed, 5 is default
         
      Else
        ResizeWindow(0,WX - SlideSpeed,#PB_Ignore,#PB_Ignore,#PB_Ignore)  ; SlideIn
      EndIf   
   EndIf
   ;}
   If RadarStat.b<>RadarPreStat.b:If RadarStat.b=#True:RadarGo.b=#True:Else:RadarGo.b=#False:EndIf:EndIf 
   RadarPreStat.b=RadarStat.b  
   ;{ Choose hiding method
   If HideWindow = #True And isHidden = #False And (ElapsedMilliseconds() - TimerInit) >= #HIDE_TIMEOUT

      Select #HIDE_METHOD
         Case #HIDE_CAPTION
         ResizeWindow(0,#PB_Ignore,#PB_Ignore,#PB_Ignore,0)         
         HideWindow = #False
         isHidden = #True
         
         Case #HIDE_ICON
         HideWindow = #False : isHidden = #True

         Case #HIDE_SLIDE
         SlideAccel + #SLIDE_ACCEL
         SlideSpeed + SlideAccel

         If SlideOut = #False
            SlideOut = #True : WX = WindowX(0)
            ScreenWidth = GetSystemMetrics_(#SM_CXSCREEN)
         EndIf
         
         If WindowX(0) > ScreenWidth
            HideWindow = #False : isHidden = #True
            
            SlideAccel = 0 : SlideSpeed = 0
            
            SetWindowLong_(WindowID(0),#GWL_STYLE,#WS_DLGFRAME | #WS_VISIBLE)
            ResizeWindow(0,ScreenWidth-20,#PB_Ignore,#PB_Ignore,#PB_Ignore)
         Else
            ResizeWindow(0,WX + SlideSpeed,#PB_Ignore,#PB_Ignore,#PB_Ignore)  ; SlideOut
         EndIf               
         RadarPreStat.b=RadarStat.b 
         RadarStat.b=#False    
     EndSelect      
   EndIf
 ;}  
 ;}
    EventID = WindowEvent() ;: Delay(1)   
    timer = ElapsedMilliseconds()
    time = timeGetTime_()
;{ RadarTurn    
  If SoundStat=#True    
    ;If IsScreenActive() And ScreenDeactivated = #False   ;sdfg
    Angle.f + #rotator_speed
    If Angle > 360:Angle-360
    EndIf   
    If CurrentAngle = 0 And HideWindow=#False
          If SoundStat.b=#True:ObjectSound(0):EndIf
    EndIf
    ClearScreen(RGB(0,0,0))
    SpriteQuality(#PB_Sprite_BilinearFiltering)
    ZoomSprite(1,#RHeight+10,#RHeight+10)
     
    RotateSprite(1,Angle,#PB_Absolute)
     
    CurrentAngle + #rotator_speed
    If CurrentAngle >= 180 And Angle = 180: CurrentAngle = 0
    EndIf
    DisplaySprite(1,(#RWidth-#RHeight)/2+0,0)
    DisplayTransparentSprite(3,(#RWidth-#RHeight)/2+0,0)

;      SpriteBlendingMode(5,2)
      ; Objects

    For a = 0 To #max_objects
     
      StartDrawing(SpriteOutput(4))
            DrawingMode(4)
            Box(0, 0, 140, 20, RGB(0, 255, 0))
            DrawingMode(4)
            Box(1, 1, 138, 17, RGB(0, 0, 0))
            FrontColor(RGB(0, 255, 0))
            DrawText(5, 2,"ServerIP: IPaddress$")
      StopDrawing()
         
      If Objects(a)\x Or Objects(a)\y
        If (CurrentAngle + 180) < Objects(a)\Degree + 180 And (CurrentAngle + 180) > Objects(a)\Degree +175 And Objects(a)\Transparency<200
          Objects(a)\Transparency=255
        EndIf
      EndIf
      If Objects(a)>0
        Objects(a)\Transparency-#rotator_speed
        If Objects(a)\Transparency<0
          Objects(a)\Transparency=0
        EndIf
      EndIf
      If Objects(a)\x Or Objects(a)\y
          DisplayTransparentSprite(2, (#x_0 - 16) + Objects(a)\x, (#y_0 - 16) - Objects(a)\y, Objects(a)\Transparency)
          DisplayTransparentSprite(4, (#x_0 - 16) + Objects(a)\x + 15, (#y_0 - 16) - Objects(a)\y - 5, 255)
      EndIf 
    Next a


    g + 1
    If g = 10
      For a = 1 To #max_objects
     
        Select(a)
          Case 1
            Objects(a)\x - 0;3
            Objects(a)\y + 0;2
          Case 2
            Objects(a)\x + 0;2
            Objects(a)\y - 0;1
          Case 3
            Objects(a)\x + 0;1
            Objects(a)\y + 0       
        EndSelect

        If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1) > 360
          Objects(a)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1) - 360
        Else
          Objects(a)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1)
        EndIf
      Next a
      g = 0
    EndIf

  ;EndIf ;sdfg
  FlipBuffers()
  Else
    If SoundStat=#False:PauseSound(2):EndIf
  EndIf
;}  
  Repeat:Until timeGetTime_()-20>=time
;{ EventCatcher
;{ Hom End PgUp PgDn Up Dn Ret
  Select EventID
    Case #PB_Event_Menu 
      Select EventMenu() 
          Case 0  ; Ret
            If GetActiveGadget() = 10
              If CurChatComboState=#False
                CDate$=FormatDate("%dd/%mm/%yyyy", Date())
                CHour$=FormatDate("%hh:%ii", Date())
                
                If CDate$=LDate$
                  xDate$=""
                Else
                  xDate$=CDate$
                EndIf
                
                If CHour$=LHour$
                  xHour$=""
                Else
                  xHour$=CHour$+Chr(13)
                EndIf
                
                TexGadget.s=GetGadgetText(9)+Chr(13)+ xDate$+" "+xHour$+"     "+GetGadgetText(10)
                SetGadgetText(9,TexGadget)
                SetGadgetText(10,"")
                LDate$=CDate$
                LHour$=CHour$
              Else
                SetGadgetState(10,ComboID.l)
                ChatID.l=ComboID.l
                Debug "ChatID="+Str(ChatID)
                SendMessage_(GadgetID(10),#CB_SHOWDROPDOWN,0,0)
                SetGadgetText(10,"")
              EndIf
            EndIf
          Case  1   ;Home
            If GetActiveGadget() = 10
               SendMessage_(GadgetID(9), #EM_SETSEL,0,0)      
            EndIf
          Case  2  ;End
            If GetActiveGadget() = 10
              SendMessage_(GadgetID(9), #EM_SETSEL,-1,-1)      
            EndIf
          Case 3  ;PgUp
            If GetActiveGadget() = 10
              SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, -13)
            EndIf
          Case 4  ;PgDn
            If GetActiveGadget() = 10
              SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, 13)
            EndIf
          Case 5  ;Up
            If GetActiveGadget() = 10
              If CurChatComboState=#False 
                SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, -1)
              Else
                PrevComboID.l=ComboID.l
                ComboID.l=GetGadgetState(10)
                If ComboID.l>0
                  ComboID.l=ComboID.l-1
                  Debug "ComboID="+Str(ComboID)
                  ComboVAL.s = GetGadgetItemText(10,ComboID.l)
                  SetGadgetState(10,ComboID.l)
                EndIf
              EndIf
            EndIf
          Case 6   ;Down
            If GetActiveGadget() = 10
              If CurChatComboState=#False 
                SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, 1)
              Else            
                PrevComboID.l=ComboID.l
                ComboID.l=GetGadgetState(10)
                If ComboID.l<12
                  ComboID.l=ComboID.l+1
                  Debug "ComboID="+Str(ComboID)
                  ComboVAL.s = GetGadgetItemText(10,ComboID.l)
                  SetGadgetState(10,ComboID.l)
                EndIf
              EndIf
            EndIf
          Case 7  ;AltUp
              SendMessage_(GadgetID(10),#CB_SHOWDROPDOWN,0,0)
            If GetActiveGadget()<>10
              SetActiveGadget(10)
            EndIf  
          Case 8   ;AltDown
              SendMessage_(GadgetID(10),#CB_SHOWDROPDOWN,1,0)
            If GetActiveGadget()<>10
              SetActiveGadget(10)
            EndIf
        EndSelect   
    Case #PB_Event_Gadget  
      Select EventGadget()
        Case 0
          RunProgram("notepad")
        Case 1
          RunProgram("calc")
        Case 5
          End
      EndSelect  
   Case #PB_Event_SizeWindow
   Default
     If CurChatComboState=#True And PrevChatComboState=#False
       SetGadgetState(10,ChatID)
     EndIf
     PrevChatComboState=CurChatComboState
     If IsWindowVisible_( dLh)
        CurChatComboState=#True
     Else
        CurChatComboState=#False
     EndIf
     If CurChatComboState<>PrevChatComboState
        Debug CurChatComboState
     EndIf              
  EndSelect
 ;}   
;} EventCatcher
ForEver
;} MainLoop
EndProcedure

;{ SubProcedurez
;{ Radar Procedurez
Procedure.f winkel(x1.f,y1.f,x2.f,y2.f)
  a.f = x2-x1
  b.f = y2-y1
  c.f = Sqr(a*a+b*b)
  winkel.f = ACos(a/c)*57.29577
  If y1 < y2 : winkel=360-winkel : EndIf
  ProcedureReturn winkel
EndProcedure
Procedure.f GSin(winkel.f)
   ProcedureReturn Sin(winkel*(2*3.14159265/360))
EndProcedure
Procedure.f GCos(winkel.f)
   ProcedureReturn Cos(winkel*(2*3.14159265/360))
EndProcedure
Procedure ObjectSound(x)
  PlaySound(0)
EndProcedure
Procedure MakeSprites()

  h = #RHeight-100

  CreateSprite(1,512,512,#PB_Sprite_PixelCollision)
  CreateSprite(2,200,200,#PB_Sprite_PixelCollision)
  CreateSprite(3,h+100,h+100,#PB_Sprite_PixelCollision)
  CreateSprite(4, 140, 20)
 
  ; Radar rotator (green > black)
  StartDrawing(SpriteOutput(1))
    angle.f=90
    Repeat
      Line(255,255,GSin(angle)*255.0,GCos(angle)*255,RGB(0, Int(255-angle*2.8), 0))
      angle.f - 0.001
    Until angle <=0
  StopDrawing()

  ; Radar objects
  StartDrawing(SpriteOutput(2))
    For a = 127 To 0 Step -1
      Circle(127,127,a,RGB(255-2*a,255-2*a,255-2*a))
    Next a
  StopDrawing()
  ZoomSprite(2,13,13)

  ; Radar chassis
  StartDrawing(SpriteOutput(3))
    DrawingMode(4)
    Circle(h/1.36,h/1.36,h/15,RGB($40,$40,$40))
    Circle(h/1.36,h/1.36,h/15,RGB($00,$00,$00))
    For a = 0 To 7
      Circle(h/1.36,h/1.36,h/10*a,RGB($40,$40,$40))
    Next a
    For a = 0 To 67
      Circle(h/1.36,h/1.36,h/10*7+a,RGB($40,$40,$40))
    Next a

    For a = -2 To 2
      Line(0,h/2+a,h,0,RGB($40,$40,$40))
    Next a
    For a = -2 To 2
      Line(h/2+a,0,0,h,RGB($40,$40,$40))
    Next a
    For a = 30 To 330 Step 30
      Line(h/1.36,h/1.36,GSin(a)*h,GCos(a)*h,RGB($40,$40,$40))
    Next a
    For i = 0 To #RWidth+20 Step 16
      LineXY(0, i, #RWidth+20, i, RGB(0, 80, 0))
    Next i
    For i = 0 To #RWidth+20 Step 16
      LineXY(i, 0, i, #RWidth+20, RGB(0, 80, 0))
    Next i
  StopDrawing()
 
EndProcedure
;}
;{ General Procedures
Procedure.i SetWindowTransparency(Window.i, transparency.i) ; Fenster durchsichtig machen (transparency : 0-255)
 
  If IsWindow(Window)
    Protected WindowID = WindowID(Window)
    SetWindowLongPtr_(WindowID,#GWL_EXSTYLE,#WS_EX_LAYERED)
    SetLayeredWindowAttributes_(WindowID,0,transparency,#LWA_ALPHA)
  EndIf

EndProcedure
Procedure.b WindowOnTop(ontop)
; ontop = True (1) for window to be on top, else False (0)
Hwin = WindowID(0) ; Window handle
If ontop
ontop = 1
zorder = #HWND_TOPMOST
BringWindowToTop_(Hwin)
Else
zorder = #HWND_NOTOPMOST
EndIf
; Make the on top request persistent
begindeferstruct = BeginDeferWindowPos_(1)
If begindeferstruct

deferstruct = DeferWindowPos_(begindeferstruct, Hwin, zorder, 0, 0, 0, 0, #SWP_NOMOVE+#SWP_NOSIZE+#SWP_SHOWWINDOW*ontop)

If deferstruct
res.b = EndDeferWindowPos_(deferstruct)
ProcedureReturn res
EndIf
EndIf
EndProcedure
;}
;} SubProcedurez

;{ Dataz
;{ Pix
  DataSection
    Bio1: 
    IncludeBinary "btn\Bio1.png"
  EndDataSection
  DataSection
    NET: 
    IncludeBinary "btn\NET.png"
  EndDataSection
  DataSection
    ShutDown: 
    IncludeBinary "btn\ShutDown.png"
  EndDataSection
  DataSection
    IP: 
    IncludeBinary "btn\IP.png"
  EndDataSection
  DataSection
    Hostname: 
    IncludeBinary "btn\Hostname.png"
  EndDataSection
  DataSection
    Tutor: 
    IncludeBinary "btn\Tutor.png"
  EndDataSection
;{ Soundz
    DataSection
    Sonar: 
      IncludeBinary "sonar2.wav"
    EndDataSection
    DataSection
    BGSound: 
      IncludeBinary "background.wav"
    EndDataSection
;}  
;} Dataz  

Button Images are 150x120 and sound files can be changed
I apologize that cannot attach Includes because cannot find attach button
Last edited by LiK137 on Tue Jan 10, 2017 11:03 am, edited 1 time in total.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Annoying Window Gadget Redraw

Post by IdeasVacuum »

There isn't an attach button, which explains why it is hard to find..... :)
What you can do is insert a URL link for a download (from your website or DropBox etc).

A better alternative for the forum is to include the images as Data instead. See this snippet for an example of how to do it: http://www.purebasic.fr/english/viewtop ... 09#p453009

...and this is an app that generates the DataSection for you: http://www.purebasic.fr/english/viewtopic.php?p=374183
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Annoying Window Gadget Redraw

Post by Danilo »

Changed 4 small things, see comments:

Code: Select all

;{ Declz
;{ Radar
#Width  = 625
#Height = 595

#RWidth= 320
#RHeight=340

PI.f = 3.141593

#x_0 = #RWidth / 2
#y_0 = #RHeight / 2

#rotator_speed = 2
#max_objects = 10
CurrentAngle = 180

Structure _OBJ
    x.l
    y.l
    Transparency.l
    Degree.f
EndStructure

Global Dim Objects._OBJ(#max_objects)

Declare.f winkel(x1.f,y1.f,x2.f,y2.f)
Declare.f GSin(winkel.f)
Declare.f GCos(winkel.f)
Declare ObjectSound(x)
Declare MakeSprites()
;}
;{ General
Declare Shell()
Declare .b WindowOnTop(ontop)
Declare.i SetWindowTransparency(Window.i, transparency.i) 
;}
;} Declz
Global RadarGo.b=#True

Shell()  

Procedure Shell()
    ;{ InProcDeclz  
    Enumeration
        #SILDE_LEFT
        #SILDE_TOP
        #SILDE_RIGHT
        #SILDE_BOTTOM
    EndEnumeration
    
    Enumeration   
        #HIDE_CAPTION   
        #HIDE_ICON
        #HIDE_SLIDE
    EndEnumeration
    
    #SLIDE_ACCEL = 0.5
    #SILDE_DIRECTION = #SILDE_RIGHT
    
    #HIDE_TIMEOUT = 2000
    #HIDE_METHOD = #HIDE_SLIDE
    
    SlideAccel.f = 0
    SlideSpeed.f = 0
    ;}
    ;{ INITWin
    UsePNGImageDecoder()
    OpenWindow(0,0,0,#Width,#Height,"KTIPOShell",#WS_OVERLAPPEDWINDOW | 1 | #PB_Window_BorderLess | #PB_Window_Invisible) ;(1)__-=::[ CREATE INVISIBLE/HIDDEN WINDOW ]::=-__
    HideFromTaskBar(WindowID(0),1)
    WindowOnTop(WindowID(0))
    Color = RGB(0, 0, 0)
    InitWW = WindowWidth(0):InitWH = WindowHeight(0)
    SetWindowColor(0, Color)
    SetWindowTransparency(0,240)
    SetWindowLong_(WindowID(0),#GWL_STYLE,#WS_DLGFRAME )
    ResizeWindow(0,#PB_Ignore,#PB_Ignore,InitWW,InitWH)
    ;}
    ;{ AddGadgets
    CatchImage(0, ?Bio1)
    CatchImage(1, ?NET)
    CatchImage(2, ?Hostname)
    CatchImage(3, ?IP)
    CatchImage(4, ?Tutor)
    CatchImage(5, ?ShutDown)
    ButtonImageGadget(0, 5, 5, 150, 110, ImageID(0),#PB_Button_Toggle)
    ButtonImageGadget(1, 160, 5, 150, 110, ImageID(1),#PB_Button_Toggle)
    ButtonImageGadget(2, 5, 120, 150, 110, ImageID(2),#PB_Button_Toggle)
    ButtonImageGadget(3, 160, 120, 150, 110, ImageID(3),#PB_Button_Toggle)
    ButtonImageGadget(4, 5, 235, 150, 110, ImageID(4))
    ButtonImageGadget(5, 160, 235, 150, 110, ImageID(5))
    
    EditorGadget(9, 5, 345, 305, 220,#PB_Editor_ReadOnly|#PB_Editor_WordWrap):SetGadgetColor(9,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(9,#PB_Gadget_BackColor,RGB(0,0,0))
    ComboBoxGadget(10, 5, 570, 305, 20,#PB_ComboBox_Editable)
    AddGadgetItem(10, -1, "SomeItm1")
    AddGadgetItem(10, -1, "SomeItm2")
    AddGadgetItem(10, -1, "SomeItm3")
    AddGadgetItem(10, -1, "SomeItm4")
    AddGadgetItem(10, -1, "SomeItm5")
    AddGadgetItem(10, -1, "SomeItm6")
    AddGadgetItem(10, -1, "SomeItm7")
    AddGadgetItem(10, -1, "SomeItm8")
    AddGadgetItem(10, -1, "SomeItm9")
    AddGadgetItem(10, -1, "SomeItm10")
    AddGadgetItem(10, -1, "SomeItm11")
    AddGadgetItem(10, -1, "SomeItm12")
    AddGadgetItem(10, -1, "SomeItm13")
    SetGadgetState(10,0)
    
    StringGadget(11, 315, 345, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(11,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(11,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(12, 315, 365, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(12,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(12,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(13, 315, 385, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(13,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(13,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(14, 315, 405, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(14,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(14,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(15, 315, 425, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(15,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(15,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(16, 315, 445, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(16,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(16,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(17, 315, 465, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(17,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(17,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(18, 315, 485, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(18,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(18,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(19, 315, 505, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(19,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(19,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(20, 315, 525, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(20,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(20,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(21, 315, 545, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(21,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(21,#PB_Gadget_BackColor,RGB(0,0,0))
    StringGadget(22, 315, 570, 305, 20,"",#PB_String_ReadOnly):SetGadgetColor(22,#PB_Gadget_FrontColor,RGB(30,100,20)):SetGadgetColor(22,#PB_Gadget_BackColor,RGB(0,0,0))
    
    ;}   
    ;{ AddShortCuts
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
    AddKeyboardShortcut(0, #PB_Shortcut_Home, 1)
    AddKeyboardShortcut(0, #PB_Shortcut_End, 2)
    AddKeyboardShortcut(0, #PB_Shortcut_PageUp, 3)
    AddKeyboardShortcut(0, #PB_Shortcut_PageDown, 4)
    AddKeyboardShortcut(0, #PB_Shortcut_Up, 5)
    AddKeyboardShortcut(0, #PB_Shortcut_Down, 6)
    
    AddKeyboardShortcut(0, #PB_Shortcut_Alt|#PB_Shortcut_Up, 7)
    AddKeyboardShortcut(0, #PB_Shortcut_Alt|#PB_Shortcut_Down, 8)
    ;}
    ;{ Screen
    InitKeyboard()
    InitSprite()
    InitSound()
    OpenWindowedScreen(WindowID(0),#Width/2,0,#RWidth,#RHeight,0,0, #PB_Screen_SmartSynchronization)
    CatchSound(0,?Sonar)
    CatchSound(2,?BGSound)
    MakeSprites()
    ;}
    ;{ - Init RadarObjects
    ;{ Object3
    xKoo = 5
    yKoo = 30
    Objects(3)\x      = xKoo
    Objects(3)\y      = yKoo
    If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) > 360
        Objects(3)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) - 360
    Else
        Objects(3)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1)
    EndIf
    ;}
    ;}
    ;}
    ;{ Main LOOP
    PlaySound(2,1)
    SoundVolume(0, 50)
    SoundVolume(2, 60)
    
    dLh.l = FindWindow_("ComboLBox",0) 
    
    While WindowEvent():Wend  ;(2)__-=::[ PROCESS ALL EVENTS NOW (gadget creation etc.) ]::=-__
    HideWindow(0,0)           ;(3)__-=::[ SHOW/UN-HIDE THE WINDOW                       ]::=-__
    
    Repeat
        If SoundStat.b=#True
            SetWindowTransparency(0,240)
            ResumeSound(2) 
        Else
            SetWindowTransparency(0,70)
            PauseSound(2)
        EndIf
        
        ;{ HideWin  
        ;{ Get cursor position & window metrics
        GetCursorPos_(cpt.POINT)
        GetWindowRect_(WindowID(0),wrc.RECT)
        
        WX = wrc\left : WW = wrc\right-wrc\left
        WY = wrc\top : WH = wrc\bottom-wrc\top
        ;}
        ;{ Check wether mouse is out- or inside the window
        If (cpt\x < WX Or cpt\x >= (WX + WW) Or cpt\y < WY Or cpt\y >= (WY + WH)) : SoundStat.b=#False
            If isTimeSet = #False
                isTimeSet = #True
                
                HideWindow = #True
                
                InitWX = WX : InitWW = WindowWidth(0)
                InitWY = WY   : InitWH = WindowHeight(0)
                
                TimerInit = ElapsedMilliseconds()
            EndIf
        Else
            If SlideOut = #False : HideWindow = #False : isTimeSet = #False : EndIf
            SoundStat.b=#True
            ;} 
            ;{ Restore from slide mode
            If (cpt\x >= WX Or cpt\y >= WY Or cpt\y < (WY + WH)) And isHidden = #True And #HIDE_METHOD = #HIDE_SLIDE And SlideIn = #False
                SlideIn = #True
            EndIf
        EndIf
        ;}
        ;{ Sliding window back in sight
        If SlideIn = #True
            SlideAccel + #SLIDE_ACCEL
            SlideSpeed + SlideAccel      
            If WindowX(0) <=InitWX
                SlideOut = #False
                SlideIn = #False
                isHidden = #False
                
                SlideAccel = 0 : SlideSpeed = 0
                ;SetWindowLong_(WindowID(0),#GWL_STYLE,#WS_OVERLAPPEDWINDOW ) ; ShowCaption
                ;HideWindow(0,0)
                RadarPreStat.b=RadarStat.b
                RadarStat.b=#True
                ;AU3_AutoItSetOption_("MouseCoordMode",0)  ; set x,y coordinates to active window
                ;AU3_MouseMove_(620,590,9)  ; last parm controls speed, 5 is default
                
            Else
                ResizeWindow(0,WX - SlideSpeed,#PB_Ignore,#PB_Ignore,#PB_Ignore)  ; SlideIn
            EndIf   
        EndIf
        ;}
        If RadarStat.b<>RadarPreStat.b:If RadarStat.b=#True:RadarGo.b=#True:Else:RadarGo.b=#False:EndIf:EndIf 
        RadarPreStat.b=RadarStat.b  
        ;{ Choose hiding method
        If HideWindow = #True And isHidden = #False And (ElapsedMilliseconds() - TimerInit) >= #HIDE_TIMEOUT
            
            Select #HIDE_METHOD
                Case #HIDE_CAPTION
                    ResizeWindow(0,#PB_Ignore,#PB_Ignore,#PB_Ignore,0)         
                    HideWindow = #False
                    isHidden = #True
                    
                Case #HIDE_ICON
                    HideWindow = #False : isHidden = #True
                    
                Case #HIDE_SLIDE
                    SlideAccel + #SLIDE_ACCEL
                    SlideSpeed + SlideAccel
                    
                    If SlideOut = #False
                        SlideOut = #True : WX = WindowX(0)
                        ScreenWidth = GetSystemMetrics_(#SM_CXSCREEN)
                    EndIf
                    
                    If WindowX(0) > ScreenWidth
                        HideWindow = #False : isHidden = #True
                        
                        SlideAccel = 0 : SlideSpeed = 0
                        
                        SetWindowLong_(WindowID(0),#GWL_STYLE,#WS_DLGFRAME | #WS_VISIBLE)
                        ResizeWindow(0,ScreenWidth-20,#PB_Ignore,#PB_Ignore,#PB_Ignore)
                    Else
                        ResizeWindow(0,WX + SlideSpeed,#PB_Ignore,#PB_Ignore,#PB_Ignore)  ; SlideOut
                    EndIf               
                    RadarPreStat.b=RadarStat.b 
                    RadarStat.b=#False    
            EndSelect      
        EndIf
        ;}  
        ;}
        timer = ElapsedMilliseconds()
        time = timeGetTime_()
        ;{ RadarTurn    
        If SoundStat=#True    
            ;If IsScreenActive() And ScreenDeactivated = #False   ;sdfg
            Angle.f + #rotator_speed
            If Angle > 360:Angle-360
            EndIf   
            If CurrentAngle = 0 And HideWindow=#False
                If SoundStat.b=#True:ObjectSound(0):EndIf
            EndIf
            ClearScreen(RGB(0,0,0))
            SpriteQuality(#PB_Sprite_BilinearFiltering)
            ZoomSprite(1,#RHeight+10,#RHeight+10)
            
            RotateSprite(1,Angle,#PB_Absolute)
            
            CurrentAngle + #rotator_speed
            If CurrentAngle >= 180 And Angle = 180: CurrentAngle = 0
            EndIf
            DisplaySprite(1,(#RWidth-#RHeight)/2+0,0)
            DisplayTransparentSprite(3,(#RWidth-#RHeight)/2+0,0)
            
            ;      SpriteBlendingMode(5,2)
            ; Objects
            
            For a = 0 To #max_objects
                
                StartDrawing(SpriteOutput(4))
                DrawingMode(4)
                Box(0, 0, 140, 20, RGB(0, 255, 0))
                DrawingMode(4)
                Box(1, 1, 138, 17, RGB(0, 0, 0))
                FrontColor(RGB(0, 255, 0))
                DrawText(5, 2,"ServerIP: IPaddress$")
                StopDrawing()
                
                If Objects(a)\x Or Objects(a)\y
                    If (CurrentAngle + 180) < Objects(a)\Degree + 180 And (CurrentAngle + 180) > Objects(a)\Degree +175 And Objects(a)\Transparency<200
                        Objects(a)\Transparency=255
                    EndIf
                EndIf
                If Objects(a)>0
                    Objects(a)\Transparency-#rotator_speed
                    If Objects(a)\Transparency<0
                        Objects(a)\Transparency=0
                    EndIf
                EndIf
                If Objects(a)\x Or Objects(a)\y
                    DisplayTransparentSprite(2, (#x_0 - 16) + Objects(a)\x, (#y_0 - 16) - Objects(a)\y, Objects(a)\Transparency)
                    DisplayTransparentSprite(4, (#x_0 - 16) + Objects(a)\x + 15, (#y_0 - 16) - Objects(a)\y - 5, 255)
                EndIf 
            Next a
            
            
            g + 1
            If g = 10
                For a = 1 To #max_objects
                    
                    Select(a)
                        Case 1
                            Objects(a)\x - 0;3
                            Objects(a)\y + 0;2
                        Case 2
                            Objects(a)\x + 0;2
                            Objects(a)\y - 0;1
                        Case 3
                            Objects(a)\x + 0;1
                            Objects(a)\y + 0       
                    EndSelect
                    
                    If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1) > 360
                        Objects(a)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1) - 360
                    Else
                        Objects(a)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1)
                    EndIf
                Next a
                g = 0
            EndIf
            
            ;EndIf ;sdfg
            FlipBuffers()
        Else
            If SoundStat=#False:PauseSound(2):EndIf
        EndIf
        ;}  
        Repeat:Until timeGetTime_()-20>=time
        ;{ EventCatcher
        ;{ Hom End PgUp PgDn Up Dn Ret
        Repeat                                                    ;(4)__-=::[ PROCESS ALL EVENTS IN THE MESSAGE QUEUE ]::=-__
           EventID = WindowEvent() ;: Delay(1)

            Select EventID
                Case #PB_Event_Menu 
                    Select EventMenu() 
                        Case 0  ; Ret
                            If GetActiveGadget() = 10
                                If CurChatComboState=#False
                                    CDate$=FormatDate("%dd/%mm/%yyyy", Date())
                                    CHour$=FormatDate("%hh:%ii", Date())
                                    
                                    If CDate$=LDate$
                                        xDate$=""
                                    Else
                                        xDate$=CDate$
                                    EndIf
                                    
                                    If CHour$=LHour$
                                        xHour$=""
                                    Else
                                        xHour$=CHour$+Chr(13)
                                    EndIf
                                    
                                    TexGadget.s=GetGadgetText(9)+Chr(13)+ xDate$+" "+xHour$+"     "+GetGadgetText(10)
                                    SetGadgetText(9,TexGadget)
                                    SetGadgetText(10,"")
                                    LDate$=CDate$
                                    LHour$=CHour$
                                Else
                                    SetGadgetState(10,ComboID.l)
                                    ChatID.l=ComboID.l
                                    Debug "ChatID="+Str(ChatID)
                                    SendMessage_(GadgetID(10),#CB_SHOWDROPDOWN,0,0)
                                    SetGadgetText(10,"")
                                EndIf
                            EndIf
                        Case  1   ;Home
                            If GetActiveGadget() = 10
                                SendMessage_(GadgetID(9), #EM_SETSEL,0,0)      
                            EndIf
                        Case  2  ;End
                            If GetActiveGadget() = 10
                                SendMessage_(GadgetID(9), #EM_SETSEL,-1,-1)      
                            EndIf
                        Case 3  ;PgUp
                            If GetActiveGadget() = 10
                                SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, -13)
                            EndIf
                        Case 4  ;PgDn
                            If GetActiveGadget() = 10
                                SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, 13)
                            EndIf
                        Case 5  ;Up
                            If GetActiveGadget() = 10
                                If CurChatComboState=#False 
                                    SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, -1)
                                Else
                                    PrevComboID.l=ComboID.l
                                    ComboID.l=GetGadgetState(10)
                                    If ComboID.l>0
                                        ComboID.l=ComboID.l-1
                                        Debug "ComboID="+Str(ComboID)
                                        ComboVAL.s = GetGadgetItemText(10,ComboID.l)
                                        SetGadgetState(10,ComboID.l)
                                    EndIf
                                EndIf
                            EndIf
                        Case 6   ;Down
                            If GetActiveGadget() = 10
                                If CurChatComboState=#False 
                                    SendMessage_(GadgetID(9), #EM_LINESCROLL, 0, 1)
                                Else            
                                    PrevComboID.l=ComboID.l
                                    ComboID.l=GetGadgetState(10)
                                    If ComboID.l<12
                                        ComboID.l=ComboID.l+1
                                        Debug "ComboID="+Str(ComboID)
                                        ComboVAL.s = GetGadgetItemText(10,ComboID.l)
                                        SetGadgetState(10,ComboID.l)
                                    EndIf
                                EndIf
                            EndIf
                        Case 7  ;AltUp
                            SendMessage_(GadgetID(10),#CB_SHOWDROPDOWN,0,0)
                            If GetActiveGadget()<>10
                                SetActiveGadget(10)
                            EndIf  
                        Case 8   ;AltDown
                            SendMessage_(GadgetID(10),#CB_SHOWDROPDOWN,1,0)
                            If GetActiveGadget()<>10
                                SetActiveGadget(10)
                            EndIf
                    EndSelect   
                Case #PB_Event_Gadget  
                    Select EventGadget()
                        Case 0
                            RunProgram("notepad")
                        Case 1
                            RunProgram("calc")
                        Case 5
                            End
                    EndSelect  
                Case #PB_Event_SizeWindow
                Default
                    If CurChatComboState=#True And PrevChatComboState=#False
                        SetGadgetState(10,ChatID)
                    EndIf
                    PrevChatComboState=CurChatComboState
                    If IsWindowVisible_( dLh)
                        CurChatComboState=#True
                    Else
                        CurChatComboState=#False
                    EndIf
                    If CurChatComboState<>PrevChatComboState
                        Debug CurChatComboState
                    EndIf              
            EndSelect
        Until EventID = 0
        ;}   
        ;} EventCatcher
    ForEver
    ;} MainLoop
EndProcedure

;{ SubProcedurez
;{ Radar Procedurez
Procedure.f winkel(x1.f,y1.f,x2.f,y2.f)
    a.f = x2-x1
    b.f = y2-y1
    c.f = Sqr(a*a+b*b)
    winkel.f = ACos(a/c)*57.29577
    If y1 < y2 : winkel=360-winkel : EndIf
    ProcedureReturn winkel
EndProcedure
Procedure.f GSin(winkel.f)
    ProcedureReturn Sin(winkel*(2*3.14159265/360))
EndProcedure
Procedure.f GCos(winkel.f)
    ProcedureReturn Cos(winkel*(2*3.14159265/360))
EndProcedure
Procedure ObjectSound(x)
    PlaySound(0)
EndProcedure
Procedure MakeSprites()
    
    h = #RHeight-100
    
    CreateSprite(1,512,512,#PB_Sprite_PixelCollision)
    CreateSprite(2,200,200,#PB_Sprite_PixelCollision)
    CreateSprite(3,h+100,h+100,#PB_Sprite_PixelCollision)
    CreateSprite(4, 140, 20)
    
    ; Radar rotator (green > black)
    StartDrawing(SpriteOutput(1))
    angle.f=90
    Repeat
        Line(255,255,GSin(angle)*255.0,GCos(angle)*255,RGB(0, Int(255-angle*2.8), 0))
        angle.f - 0.001
    Until angle <=0
    StopDrawing()
    
    ; Radar objects
    StartDrawing(SpriteOutput(2))
    For a = 127 To 0 Step -1
        Circle(127,127,a,RGB(255-2*a,255-2*a,255-2*a))
    Next a
    StopDrawing()
    ZoomSprite(2,13,13)
    
    ; Radar chassis
    StartDrawing(SpriteOutput(3))
    DrawingMode(4)
    Circle(h/1.36,h/1.36,h/15,RGB($40,$40,$40))
    Circle(h/1.36,h/1.36,h/15,RGB($00,$00,$00))
    For a = 0 To 7
        Circle(h/1.36,h/1.36,h/10*a,RGB($40,$40,$40))
    Next a
    For a = 0 To 67
        Circle(h/1.36,h/1.36,h/10*7+a,RGB($40,$40,$40))
    Next a
    
    For a = -2 To 2
        Line(0,h/2+a,h,0,RGB($40,$40,$40))
    Next a
    For a = -2 To 2
        Line(h/2+a,0,0,h,RGB($40,$40,$40))
    Next a
    For a = 30 To 330 Step 30
        Line(h/1.36,h/1.36,GSin(a)*h,GCos(a)*h,RGB($40,$40,$40))
    Next a
    For i = 0 To #RWidth+20 Step 16
        LineXY(0, i, #RWidth+20, i, RGB(0, 80, 0))
    Next i
    For i = 0 To #RWidth+20 Step 16
        LineXY(i, 0, i, #RWidth+20, RGB(0, 80, 0))
    Next i
    StopDrawing()
    
EndProcedure
;}
;{ General Procedures
Procedure.i SetWindowTransparency(Window.i, transparency.i) ; Fenster durchsichtig machen (transparency : 0-255)
    
    If IsWindow(Window)
        Protected WindowID = WindowID(Window)
        SetWindowLongPtr_(WindowID,#GWL_EXSTYLE,#WS_EX_LAYERED)
        SetLayeredWindowAttributes_(WindowID,0,transparency,#LWA_ALPHA)
    EndIf
    
EndProcedure
Procedure.b WindowOnTop(ontop)
    ; ontop = True (1) for window to be on top, else False (0)
    Hwin = WindowID(0) ; Window handle
    If ontop
        ontop = 1
        zorder = #HWND_TOPMOST
        BringWindowToTop_(Hwin)
    Else
        zorder = #HWND_NOTOPMOST
    EndIf
    ; Make the on top request persistent
    begindeferstruct = BeginDeferWindowPos_(1)
    If begindeferstruct
        
        deferstruct = DeferWindowPos_(begindeferstruct, Hwin, zorder, 0, 0, 0, 0, #SWP_NOMOVE+#SWP_NOSIZE+#SWP_SHOWWINDOW*ontop)
        
        If deferstruct
            res.b = EndDeferWindowPos_(deferstruct)
            ProcedureReturn res
        EndIf
    EndIf
EndProcedure
;}
;} SubProcedurez

;{ Dataz
;{ Pix
DataSection
    Bio1: 
    IncludeBinary "btn\Bio1.png"
EndDataSection
DataSection
    NET: 
    IncludeBinary "btn\NET.png"
EndDataSection
DataSection
    ShutDown: 
    IncludeBinary "btn\ShutDown.png"
EndDataSection
DataSection
    IP: 
    IncludeBinary "btn\IP.png"
EndDataSection
DataSection
    Hostname: 
    IncludeBinary "btn\Hostname.png"
EndDataSection
DataSection
    Tutor: 
    IncludeBinary "btn\Tutor.png"
EndDataSection
;{ Soundz
DataSection
    Sonar: 
    IncludeBinary "sonar2.wav"
EndDataSection
DataSection
    BGSound: 
    IncludeBinary "background.wav"
EndDataSection
;}  
;} Dataz
The code works without the images, by commenting out the IncludeBinary lines and the function call 'HideFromTaskBar()'.

The problem was, you processed only 1 event in every loop. With OpenWindowedScreen() and FlipBuffers(), you get most
likely 60 FPS on Desktop, so your event loop can process a maximum of 60 messages a second. If you have 60 messages
waiting in the message queue (for gadget creation, window resize, etc.), it takes 1 second to process those messages and
show + draw the gadgets.
I made a loop out of the part 'EventCatcher', so all remaining messages get processed immediately. That's all.
Additionally I changed the window creation to start as a hidden window, and show the window after gadget creation.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: Annoying Window Gadget Redraw

Post by LiK137 »

ThanQ IdeasVacuum for great Ideas of including in DataSection as Hex. That is very useful, going to use only this method from now.

And big thanx to Danilo for great solution. Now I at least will not repeat this event processing mistake.
Post Reply