flackernder imagegadget
-
- Beiträge: 173
- Registriert: 30.11.2010 02:34
flackernder imagegadget
hallo leute,
bin im forum nicht zufriedenstellend fündig geworden, daher frage ich nun:
ich habe ein imagegadget zum clientbereich des fensters gemacht. also x=0,y=0,width=windowwidth,height=windowheight.
so nun lade ich ein komplettes bild in das imagegadget.
das bild auf dem imagegadget enthält grafische buttons, die ein bestandteil des bildes sind.
mit einer funktion kann ich mittels koordinate problemlos feststellen, auf welchem dieser buttons der mauszeiger sich gerade befindet. ab dem moment soll sich aber nun eine art mouseover-effekt auf den bildabschnitt das den "scheinbaren" button enthält auswirken. was auch sauber funktioniert.
das problem ist nur, das ich den imagegadget dauerhaft neuzeichnen muss. dabei flackert das bild heftig. ich habe zwar mittels delay() das ganze etwas hinbekommen, aber zufrieden bin ich nicht.
gibt es keine möglichkeit, das flackern des imagegadgets zu unterbinden?
mfg
kurt
bin im forum nicht zufriedenstellend fündig geworden, daher frage ich nun:
ich habe ein imagegadget zum clientbereich des fensters gemacht. also x=0,y=0,width=windowwidth,height=windowheight.
so nun lade ich ein komplettes bild in das imagegadget.
das bild auf dem imagegadget enthält grafische buttons, die ein bestandteil des bildes sind.
mit einer funktion kann ich mittels koordinate problemlos feststellen, auf welchem dieser buttons der mauszeiger sich gerade befindet. ab dem moment soll sich aber nun eine art mouseover-effekt auf den bildabschnitt das den "scheinbaren" button enthält auswirken. was auch sauber funktioniert.
das problem ist nur, das ich den imagegadget dauerhaft neuzeichnen muss. dabei flackert das bild heftig. ich habe zwar mittels delay() das ganze etwas hinbekommen, aber zufrieden bin ich nicht.
gibt es keine möglichkeit, das flackern des imagegadgets zu unterbinden?
mfg
kurt
Re: flackernder imagegadget
Einfach nicht dauerhaft zeichen.
Wozu soll das gut sein?
Du musst doch nur was zeichnen, wenn sich was verändert, also immer, wenn sich die Maus auf einen Button bewegt, oder von einem Button runter ins "normale" Bild.
Wozu soll das gut sein?
Du musst doch nur was zeichnen, wenn sich was verändert, also immer, wenn sich die Maus auf einen Button bewegt, oder von einem Button runter ins "normale" Bild.
Re: flackernder imagegadget
Einerseits hilft
SmartWindowRefresh(#Window, Status)
und zum anderen sollte das Image (wenn es nicht das schon ist) nur 24Bit haben, also kein Alpha-Kanal.
Habe kein Probem bei 100Hz Erneuerungsfrequenz
SmartWindowRefresh(#Window, Status)
und zum anderen sollte das Image (wenn es nicht das schon ist) nur 24Bit haben, also kein Alpha-Kanal.
Code: Alles auswählen
CreateImage(1, 200, 200, 24)
OpenWindow(1, 0, 0, 200, 200, "Circle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SmartWindowRefresh(1, #True)
ImageGadget(1,0,0,200,200,0)
AddWindowTimer(1, 1, 10)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Timer
Select EventTimer()
Case 1
T.f = ElapsedMilliseconds()*0.001
StartDrawing(ImageOutput(1))
Box(0, 0, 200, 200, 0)
Circle(100+Cos(T)*80, 100+Sin(T)*80, 10, $00FF00)
Circle(100+Cos(-T*2)*80, 100+Sin(-T*2)*80, 10, $FF0000)
StopDrawing()
SetGadgetState(1, ImageID(1))
EndSelect
EndSelect
ForEver
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
-
- Beiträge: 173
- Registriert: 30.11.2010 02:34
Re: flackernder imagegadget
also ich habe das so gemacht, das über ein flag-variable geprüft wird, ob der maus über ein button ist, wenn ja wird einmal aktualisiert, sonst auch nur einmal. so das der imagegadget nicht dauerhaft neugezeichnet wird.
SmartWindowRefresh(#Window, Status) macht keinen unterschied.
das mit dem flackern hat sich zwar ziemlich reduziert, aber ein wenig dennoch bemerkbar... kann man das nicht vollständig unterbinden?
SmartWindowRefresh(#Window, Status) macht keinen unterschied.
das mit dem flackern hat sich zwar ziemlich reduziert, aber ein wenig dennoch bemerkbar... kann man das nicht vollständig unterbinden?
Re: flackernder imagegadget
Klar. Einfach keine anderen Gadgets drauf positionieren...
Ansonsten flackert da rein gar nichts.
Das muss an deinem Code liegen und ohne den können wir dir nicht helfen.
Ansonsten flackert da rein gar nichts.
Das muss an deinem Code liegen und ohne den können wir dir nicht helfen.
Re: flackernder imagegadget
So ein Problem hatte schonmal jemand, kann aber den Thread leider nicht mehr finden. Lag auf jeden Fall auch an seinem Code. Poste mal den Code.
Ich hab bei mir keine Probleme mit flackern.
Ich hab bei mir keine Probleme mit flackern.
Zu mir kommen behinderte Delphine um mit mir zu schwimmen.
Wir fordern mehr Aufmerksamkeit für umfallende Reissäcke!
Wir fordern mehr Aufmerksamkeit für umfallende Reissäcke!

-
- Beiträge: 173
- Registriert: 30.11.2010 02:34
Re: flackernder imagegadget
hallo leute, nochmals zu diesem thema:
die nötigen bilder könnt ihr von meiner seiter hier laden:
http://www.gonuldefterim.de/pb/pics
die bilder müssen im selben verzeichnis liegen, wie die test-datei.
es handelt sich hierbei um einen ersten versuch, eine toolbar zu basteln, das unter mac, win und lin gleichermaßen funktioniert.
die darstellung lässt sich per bilder steuern. ich dachte mir, das man unter win die uxtheme verwendet könnte, unter mac die mac theme oder eine eigene png-datei und unter linux kann man es auch entweder mit bildern oder dynamischen zeichnen oder so regeln.
allerdings funktioniert der code bei mir unter ubuntu 9 nicht korrekt. es ladet zwar. sobald ich mit dem mauszeiger auf ein element draufgehe, crasht das programm.
wäre echt sehr dankbar für eine gute lösung.
da wäre noch ne frage, wie kann ich auf einem imagegadget die keyboard-tasten abfragen. danke erstmal.
mfg
kurt
Code: Alles auswählen
; --------------------------------------------------------------------------------------- ;
; Temporary declarations
; --------------------------------------------------------------------------------------- ;
Global temp_bar_icon.l
Global capi_GID.l
Global capi_MID.l
Global capi_SID.l
Global capi_WID.l
; --------------------------------------------------------------------------------------- ;
; Incremental gadget-number vendor
; --------------------------------------------------------------------------------------- ;
Procedure.l newGID()
Define x.l
x = capi_GID
capi_GID + 1
ProcedureReturn x
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Incremental menu-number vendor
; --------------------------------------------------------------------------------------- ;
Procedure.l newMID()
Define x.l
x = capi_MID
capi_MID + 1
ProcedureReturn x
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Incremental statusbar-number vendor
; --------------------------------------------------------------------------------------- ;
Procedure.l newSID()
Define x.l
x = capi_SID
capi_SID + 1
ProcedureReturn x
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Incremental window-number vendor
; --------------------------------------------------------------------------------------- ;
Procedure.l newWID()
Define x.l
x = capi_WID
capi_WID + 1
ProcedureReturn x
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Area Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_area
x.l
y.l
w.l
h.l
EndStructure
; --------------------------------------------------------------------------------------- ;
; Matrix Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_matrix
col.l
row.l
EndStructure
; --------------------------------------------------------------------------------------- ;
; Image Data
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_image
image_id.l
x.l
y.l
EndStructure
; --------------------------------------------------------------------------------------- ;
; Image Grabber Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_pict_rect
image_id.l ; Image Number
size.l ; Pixel size. Samples: 4, 8, 16, 24, 32, 48, 64, 128, etc...
EndStructure
; --------------------------------------------------------------------------------------- ;
; Resource Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_resource
source.struct_capi_pict_rect
target.l
EndStructure
; --------------------------------------------------------------------------------------- ;
; Bar Flag Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_bar_flag
OverBar.b
ItemPtr.l
ItemGot.b
ItemClk.b
EndStructure
; --------------------------------------------------------------------------------------- ;
; Related items
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_related_items
key.s
nbr.l
EndStructure
; --------------------------------------------------------------------------------------- ;
; Popup-Menu Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_popup_menu
List key.s()
List pba.struct_capi_related_items()
List text.s()
List node.b() ; 0 = MenuTitle, 1 = SubMenu, 2 = MenuItem, 3 = Separator, 4 = Close SubMenu
List icon.l()
List usage.b() ; #False = Disabled, #True = Enabled
id.l ; Identifer of the popup-menu
EndStructure
; --------------------------------------------------------------------------------------- ;
; Items Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_items
List icon.struct_capi_matrix()
List key.s()
List text.s()
List cursor.struct_capi_area()
List type.b() ; 0 = button, 1 = dropdownBtn
List check.b() ; Checkable > 0 = False, 1 = True
List cstate.b() ; True, False
List group.l() ; Group for checkability > GroupID
List disabled.b() ; True, False
List invisible.b() ; True, False
List popupid.l() ; ID number of the popup-menu
List itempop.l() ; Items of the bar - popup-menu
List popups.struct_capi_popup_menu()
popup_visible.b
parent.l
EndStructure
; --------------------------------------------------------------------------------------- ;
; Container Background Structure
; --------------------------------------------------------------------------------------- ;
Structure struct_capi_con_bkg
bkg_color.l
light_color.l
dark_color.l
bkg_picture.l
use_picture.b
bkg_size.l
bkg_pos.l
length.l
EndStructure
; --------------------------------------------------------------------------------------- ;
; Add Popup-Menu
; --------------------------------------------------------------------------------------- ;
Procedure capi_add_popup_menu(*items.struct_capi_items,popup_id_nr.l)
AddElement(*items\popups())
*items\popups()\id = popup_id_nr
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Add Popup-Menu-Item
; --------------------------------------------------------------------------------------- ;
Procedure capi_add_popup_item(*items.struct_capi_items,popup_id_nr.l,node.s,text.s="",key.s="",icon.l=-1,usage.b=#True)
ForEach *items\popups()
If *items\popups()\id = popup_id_nr
AddElement(*items\popups()\usage())
*items\popups()\usage() = usage
AddElement(*items\popups()\key())
*items\popups()\key() = key
AddElement(*items\popups()\text())
*items\popups()\text() = text
AddElement(*items\popups()\icon())
*items\popups()\icon() = icon
Select LCase(node)
Case "0", "root"
AddElement(*items\popups()\node())
*items\popups()\node() = 0
Case "1", "sub", "submenu", "subm"
AddElement(*items\popups()\node())
*items\popups()\node() = 1
Case "2", "item"
AddElement(*items\popups()\node())
*items\popups()\node() = 2
Case "3", "sepr", "seperator", "separator", "sep", "free", ""
AddElement(*items\popups()\node())
*items\popups()\node() = 3
Case "4", "ends"
AddElement(*items\popups()\node())
*items\popups()\node() = 4
EndSelect
Break
EndIf
Next
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Mouse Cursor over a Gadget
; --------------------------------------------------------------------------------------- ;
Procedure.l capi_cursor_over_item(gadget_id.l,*items.struct_capi_items)
Define x.l = WindowMouseX(0)
Define y.l = WindowMouseY(0)
Define n.l = -1
If x >= GadgetX(gadget_id) And x <= GadgetX(gadget_id)+GadgetWidth(gadget_id) And y >= GadgetY(gadget_id) And y <= GadgetY(gadget_id)+GadgetHeight(gadget_id)
ForEach *items\cursor()
If *items\popup_visible = #False
If x >= GadgetX(gadget_id)+ *items\cursor()\x And x <= GadgetX(gadget_id)+ *items\cursor()\x + *items\cursor()\w And y >= GadgetY(gadget_id) + *items\cursor()\y And y <= GadgetY(gadget_id) + *items\cursor()\y + *items\cursor()\h
SelectElement(*items\disabled(),ListIndex(*items\cursor()))
SelectElement(*items\invisible(),ListIndex(*items\cursor()))
If *items\disabled() = #False Or *items\invisible() = #True
n = ListIndex(*items\cursor())
SelectElement(*items\key(),n)
SelectElement(*items\text(),n)
;SetWindowTitle(0,*items\text())
GadgetToolTip(gadget_id,*items\text())
EndIf
Break
EndIf
Else
If x >= GadgetX(gadget_id)+WindowWidth(*items\parent)-12 And x <= GadgetX(gadget_id)+WindowWidth(*items\parent) And y >= GadgetY(gadget_id) And y <= GadgetY(gadget_id) + WindowHeight(*items\parent)
n = -2 ; Popup Butto
Break
Else
If x >= GadgetX(gadget_id)+ *items\cursor()\x And x <= GadgetX(gadget_id)+ *items\cursor()\x + *items\cursor()\w And y >= GadgetY(gadget_id) + *items\cursor()\y And y <= GadgetY(gadget_id) + *items\cursor()\y + *items\cursor()\h
SelectElement(*items\disabled(),ListIndex(*items\cursor()))
SelectElement(*items\invisible(),ListIndex(*items\cursor()))
If *items\disabled() = #False Or *items\invisible() = #True
n = ListIndex(*items\cursor())
SelectElement(*items\key(),n)
SelectElement(*items\text(),n)
GadgetToolTip(gadget_id,*items\text())
EndIf
Break
EndIf
EndIf
EndIf
Next
ProcedureReturn n
Else
ProcedureReturn -1
EndIf
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Find an item by it's key
; --------------------------------------------------------------------------------------- ;
Procedure.s capi_get_item_key(gadget_id.l,*items.struct_capi_items)
Define x.l = WindowMouseX(0)
Define y.l = WindowMouseY(0)
Define n.l = -1
Define t.s = ""
If x >= GadgetX(gadget_id) And x <= GadgetX(gadget_id)+GadgetWidth(gadget_id) And y >= GadgetY(gadget_id) And y <= GadgetY(gadget_id)+GadgetHeight(gadget_id)
ForEach *items\cursor()
If *items\popup_visible = #False
If x >= GadgetX(gadget_id)+ *items\cursor()\x And x <= GadgetX(gadget_id)+ *items\cursor()\x + *items\cursor()\w And y >= GadgetY(gadget_id) + *items\cursor()\y And y <= GadgetY(gadget_id) + *items\cursor()\y + *items\cursor()\h
SelectElement(*items\disabled(),ListIndex(*items\cursor()))
SelectElement(*items\invisible(),ListIndex(*items\cursor()))
If *items\disabled() = #False Or *items\invisible() = #True
n = ListIndex(*items\cursor())
SelectElement(*items\key(),n)
t = *items\key()
EndIf
Break
EndIf
Else
If x >= GadgetX(gadget_id)+WindowWidth(*items\parent)-12 And x <= GadgetX(gadget_id)+WindowWidth(*items\parent) And y >= GadgetY(gadget_id) And y <= GadgetY(gadget_id) + WindowHeight(*items\parent)
t = ""
Break
Else
If x >= GadgetX(gadget_id)+ *items\cursor()\x And x <= GadgetX(gadget_id)+ *items\cursor()\x + *items\cursor()\w And y >= GadgetY(gadget_id) + *items\cursor()\y And y <= GadgetY(gadget_id) + *items\cursor()\y + *items\cursor()\h
SelectElement(*items\disabled(),ListIndex(*items\cursor()))
SelectElement(*items\invisible(),ListIndex(*items\cursor()))
If *items\disabled() = #False Or *items\invisible() = #True
n = ListIndex(*items\cursor())
SelectElement(*items\key(),n)
t = *items\key()
EndIf
Break
EndIf
EndIf
EndIf
Next
ProcedureReturn t
Else
ProcedureReturn t
EndIf
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Find a menu-item by it's key
; --------------------------------------------------------------------------------------- ;
Procedure.s capi_get_menu_key(*items.struct_capi_items,e.l)
Define found.b = #False
Define k.s
ForEach *items\popups()
ForEach *items\popups()\pba()
If *items\popups()\pba()\nbr = e
k = *items\popups()\pba()\key
found = #True
Break
EndIf
Next
If found = #True : Break : EndIf
Next
If found = #False
ForEach *items\itempop()
If *items\itempop() = e
SelectElement(*items\key(),ListIndex(*items\itempop()))
k = *items\key()
Break
EndIf
Next
EndIf
ProcedureReturn k
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Blow up popup-menu
; --------------------------------------------------------------------------------------- ;
Procedure.b capi_bar_item_popup(gadget_id.l,*items.struct_capi_items)
Define x.l = WindowMouseX(0)
Define y.l = WindowMouseY(0)
Define gx.l = DesktopMouseX()-WindowX(0)-WindowMouseX(0)+GadgetX(gadget_id)
Define gy.l = DesktopMouseY()-WindowY(0)-WindowMouseY(0)+GadgetHeight(gadget_id)
Define n.l = -1
If x >= GadgetX(gadget_id) And x <= GadgetX(gadget_id)+GadgetWidth(gadget_id) And y >= GadgetY(gadget_id) And y <= GadgetY(gadget_id)+GadgetHeight(gadget_id)
ForEach *items\cursor()
If *items\popup_visible = #False
If x >= GadgetX(gadget_id)+ *items\cursor()\x And x <= GadgetX(gadget_id)+ *items\cursor()\x + *items\cursor()\w And y >= GadgetY(gadget_id) + *items\cursor()\y And y <= GadgetY(gadget_id) + *items\cursor()\y + *items\cursor()\h
SelectElement(*items\disabled(),ListIndex(*items\cursor()))
SelectElement(*items\invisible(),ListIndex(*items\cursor()))
If *items\disabled() = #False Or *items\invisible() = #True : n = ListIndex(*items\cursor()) : EndIf
Break
EndIf
Else
If x >= GadgetX(gadget_id)+WindowWidth(*items\parent)-12 And x <= GadgetX(gadget_id)+WindowWidth(*items\parent) And y >= GadgetY(gadget_id) And y <= GadgetY(gadget_id) + WindowHeight(*items\parent)
n = -2 ; Popup Button
Break
Else
If x >= GadgetX(gadget_id)+ *items\cursor()\x And x <= GadgetX(gadget_id)+ *items\cursor()\x + *items\cursor()\w And y >= GadgetY(gadget_id) + *items\cursor()\y And y <= GadgetY(gadget_id) + *items\cursor()\y + *items\cursor()\h
SelectElement(*items\disabled(),ListIndex(*items\cursor()))
SelectElement(*items\invisible(),ListIndex(*items\cursor()))
If *items\disabled() = #False Or *items\invisible() = #True : n = ListIndex(*items\cursor()) : EndIf
Break
EndIf
EndIf
EndIf
Next
If n = -2
DisplayPopupMenu(gadget_id,WindowID(*items\parent),gx+WindowX(*items\parent)+ WindowWidth(*items\parent),gy+WindowY(*items\parent)-GadgetHeight(gadget_id))
ProcedureReturn #True
Else
If n >= 0
SelectElement(*items\popupid(),n)
If *items\popupid() > -1
If IsMenu(*items\popupid()) > 0
DisplayPopupMenu(*items\popupid(),WindowID(*items\parent),gx+WindowX(*items\parent)+ *items\cursor()\x-4,gy+WindowY(*items\parent))
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndIf
EndIf
ProcedureReturn #False
EndIf
Else
ProcedureReturn #False
EndIf
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Image Grabber Procedure
; --------------------------------------------------------------------------------------- ;
Procedure.b capi_pict_rect( *source.struct_capi_pict_rect, *pict.struct_capi_matrix, *target.struct_capi_image )
Define temp_icon.l = 0
temp_icon = GrabImage( *source\image_id, #PB_Any, *pict\col * *source\size, *pict\row * *source\size, *source\size, *source\size )
If DrawAlphaImage( ImageID(temp_icon), *target\x, *target\y )
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure.l capi_pict_rect_id( *source.struct_capi_pict_rect, *pict.struct_capi_matrix, *target.struct_capi_image )
Define temp_icon.l = 0
temp_icon = GrabImage( *source\image_id, #PB_Any, *pict\col * *source\size, *pict\row * *source\size, *source\size, *source\size )
ProcedureReturn temp_icon
EndProcedure
; --------------------------------------------------------------------------------------- ;
; Horizontal Bar Gadget
; --------------------------------------------------------------------------------------- ;
Procedure.b capi_gadget_bar( gadget_id.l, x.l, y.l, w.l, h.l, *c.struct_capi_con_bkg, *resource.struct_capi_resource, *items.struct_capi_items )
Define nr.l = 0 : Define lp.l = 0 : Define di.l = 0 : Define lx.l = 0 : Define ly.l = 0
Define ip.struct_capi_matrix
Define it.struct_capi_image
Define tp.l = 0
Define smi.l
Define spm.b
Define pid.l
Define nid.l
Define new_mid.l
ForEach *items\popups()
CreatePopupImageMenu( *items\popups()\id )
pid = *items\popups()\id
ForEach *items\popups()\node()
nid = ListIndex(*items\popups()\node())
SelectElement(*items\popups()\icon(),nid)
SelectElement(*items\popups()\text(),nid)
SelectElement(*items\popups()\key(),nid)
SelectElement(*items\popups()\usage(),nid)
Select *items\popups()\node()
Case 0 ; MenuTtitle
MenuTitle(*items\popups()\text())
Case 1 ; SubMenu
OpenSubMenu(*items\popups()\text())
Case 2 ; MenuItem
AddElement(*items\popups()\pba())
*items\popups()\pba()\key = *items\popups()\key()
new_mid = newMID()
*items\popups()\pba()\nbr = new_mid
If *items\popups()\icon() = -1
MenuItem( new_mid, *items\popups()\text() )
Else
MenuItem( new_mid, *items\popups()\text(), ImageID( *items\popups()\icon() ) )
EndIf
If *items\popups()\usage() = #False
DisableMenuItem( pid, *items\popups()\pba()\nbr, 1 )
EndIf
Case 3 ; Separator
MenuBar()
Case 4 ; Close SubMenu
CloseSubMenu()
EndSelect
Next
Next
CreatePopupImageMenu( gadget_id )
If CreateImage(gadget_id,w, h)
StartDrawing(ImageOutput(gadget_id))
Box(0,0,w,h,*c\bkg_color)
Line(0,0,1,h,*c\light_color)
Line(0,0,w,1,*c\light_color)
Line(w-1,0,1,h,*c\dark_color)
Line(0,h-1,w,1,*c\dark_color)
If *c\use_picture = #True
tp = GrabImage(*c\bkg_picture,#PB_Any,0,0,h,h)
ResizeImage(tp,w,h)
DrawImage(ImageID(tp),0,0,w,h)
FreeImage(tp)
tp = GrabImage(*c\bkg_picture,#PB_Any,0,h,4,h)
DrawImage(ImageID(tp),0,0,4,h)
FreeImage(tp)
tp = GrabImage(*c\bkg_picture,#PB_Any,4,h,4,h)
DrawImage(ImageID(tp),w-4,0,4,h)
EndIf
ForEach *items\icon()
nr = ListIndex(*items\icon())
SelectElement(*items\key(),nr)
SelectElement(*items\text(),nr)
SelectElement(*items\type(),nr)
SelectElement(*items\check(),nr)
SelectElement(*items\cstate(),nr)
SelectElement(*items\disabled(),nr)
SelectElement(*items\popupid(),nr)
lx = ip\col
ly = ip\row
ip\col = *items\icon()\col
ip\row = *items\icon()\row
it\image_id = gadget_id
If ip\col > -1 And ip\row > -1
If nr = 0
lp = 8;(h - *resource\source\size) / 2
di = *resource\source\size/2;(h - *resource\source\size) / 2
EndIf
it\x = (nr * *resource\source\size) + lp
it\y = (h - *resource\source\size) / 2
FreeImage(tp)
If *items\type() = 0
If *items\check() = 0
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,0,h,h)
Else
If *items\cstate() = #False
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,0,h,h)
Else
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,h,h,h)
EndIf
EndIf
DrawImage(ImageID(tp),it\x-((h-*resource\source\size)/2),0,h,h)
capi_pict_rect( *resource\source, ip, it )
lp + di
SelectElement(*items\cursor(),nr)
*items\cursor()\x = it\x
*items\cursor()\y = it\y
*items\cursor()\w = *resource\source\size
*items\cursor()\h = *resource\source\size
*c\length = *c\length + h
Else
tp = GrabImage(*c\bkg_picture,#PB_Any,0,48,h+8,h)
DrawImage(ImageID(tp),it\x-((h-*resource\source\size)/2),0,h+8,h)
capi_pict_rect( *resource\source, ip, it )
lp + di + 8
SelectElement(*items\cursor(),nr)
*items\cursor()\x = it\x
*items\cursor()\y = it\y
*items\cursor()\w = *resource\source\size + 8
*items\cursor()\h = *resource\source\size
*c\length = *c\length + h + 8
EndIf
AddElement(*items\itempop())
If *items\popupid() > -1
*items\itempop() = -1
OpenSubMenu(*items\text());,ImageID(capi_pict_rect_id(*resource\source, ip, it)))
ForEach *items\popups()
pid = *items\popups()\id
spm = #False
If *items\popupid() = *items\popups()\id
ForEach *items\popups()\node()
nid = ListIndex(*items\popups()\node())
SelectElement(*items\popups()\icon(),nid)
SelectElement(*items\popups()\text(),nid)
SelectElement(*items\popups()\key(),nid)
SelectElement(*items\popups()\usage(),nid)
Select *items\popups()\node()
Case 0 ; MenuTtitle
If spm = #True : CloseSubMenu() : spm = #False : EndIf
smi = OpenSubMenu(*items\popups()\text())
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
;SetMenuItemBitmaps_(MenuID(gadget_id),smi,#MF_BYCOMMAND,ImageID(*items\popups()\icon()),ImageID(*items\popups()\icon()))
CompilerEndSelect
spm = #True
Case 1 ; SubMenu
OpenSubMenu(*items\popups()\text())
Case 2 ; MenuItem
AddElement(*items\popups()\pba())
*items\popups()\pba()\key = *items\popups()\key()
new_mid = newMID()
*items\popups()\pba()\nbr = new_mid
If *items\popups()\icon() = -1
MenuItem( new_mid, *items\popups()\text() )
Else
MenuItem( new_mid, *items\popups()\text(), ImageID( *items\popups()\icon() ) )
EndIf
If *items\popups()\usage() = #False
DisableMenuItem( pid, *items\popups()\pba()\nbr, 1 )
EndIf
Case 3 ; Separator
MenuBar()
Case 4 ; Close SubMenu
CloseSubMenu()
EndSelect
Next
Break
EndIf
Next
CloseSubMenu()
CloseSubMenu()
Else
new_mid = newMID()
*items\itempop() = new_mid
MenuItem(new_mid,*items\text(),ImageID(capi_pict_rect_id(*resource\source, ip, it)))
EndIf
Else
Line( (nr * *resource\source\size) + lp - (*resource\source\size/2)-1+8, 2, 1, h - 4, *c\dark_color )
Line( (nr * *resource\source\size) + lp - (*resource\source\size/2)+8, 2, 1, h - 4, *c\light_color )
lp - di
*c\length = *c\length + 8
MenuBar()
EndIf
Next
StopDrawing()
ImageGadget(gadget_id,x,y,w,h,ImageID(gadget_id))
*c\length = *c\length + 2
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure.b capi_redraw_bar_item( gadget_id.l, index.l, pic_id.l, *c.struct_capi_con_bkg, *resource.struct_capi_resource, *items.struct_capi_items )
Define nr.l = 0 : Define lp.l = 0 : Define di.l = 0 : Define lx.l = 0 : Define ly.l = 0
Define ip.struct_capi_matrix
Define it.struct_capi_image
Define tp.l = 0 : Define zz.l = 0
Define x.l = GadgetX(gadget_id)
Define y.l = *c\bkg_pos; GadgetY(gadget_id)
Define w.l = *c\bkg_size; GadgetWidth(gadget_id)
Define h.l = GadgetHeight(gadget_id)
Define ddd.l = 0 : Define pop.l
;ForEach *items\itempop()
; DisableMenuItem(gadget_id,*items\itempop(),1)
;Next
FreeImage(gadget_id)
If CreateImage(gadget_id,w, h)
StartDrawing(ImageOutput(gadget_id))
Box(0,0,w,h,*c\bkg_color)
Line(0,0,1,h,*c\light_color)
Line(0,0,w,1,*c\light_color)
Line(w-1,0,1,h,*c\dark_color)
Line(0,h-1,w,1,*c\dark_color)
If *c\use_picture = #True
tp = GrabImage(*c\bkg_picture,#PB_Any,0,0,h,h)
ResizeImage(tp,w,h)
DrawImage(ImageID(tp),0,0,w,h)
EndIf
ForEach *items\icon()
nr = ListIndex(*items\icon())
SelectElement(*items\key(),nr)
SelectElement(*items\text(),nr)
SelectElement(*items\type(),nr)
SelectElement(*items\check(),nr)
SelectElement(*items\cstate(),nr)
SelectElement(*items\disabled(),nr)
lx = ip\col
ly = ip\row
ip\col = *items\icon()\col
ip\row = *items\icon()\row
it\image_id = gadget_id
If ip\col > -1 And ip\row > -1
If nr = 0
lp = 8;(h - *resource\source\size) / 2
di = *resource\source\size/2;(h - *resource\source\size) / 2
EndIf
it\x = nr * *resource\source\size + lp
it\y = (h - *resource\source\size) / 2
FreeImage(tp)
If *items\type() = 0
If nr = index
If *items\check() = 0
If *items\disabled() = #False
tp = GrabImage(*c\bkg_picture,#PB_Any,h*pic_id,0,h,h)
Else
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,0,h,h)
EndIf
Else
If *items\disabled() = #False
If *items\cstate() = #True
tp = GrabImage(*c\bkg_picture,#PB_Any,h*pic_id,h,h,h)
ElseIf *items\cstate() = #False
tp = GrabImage(*c\bkg_picture,#PB_Any,h*pic_id,0,h,h)
EndIf
Else
If *items\cstate() = #True
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,h,h,h)
ElseIf *items\cstate() = #False
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,0,h,h)
EndIf
EndIf
EndIf
Else
If *items\check() = 0
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,0,h,h)
Else
If *items\cstate() = #True
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,h,h,h)
ElseIf *items\cstate() = #False
tp = GrabImage(*c\bkg_picture,#PB_Any,h*1,0,h,h)
EndIf
EndIf
EndIf
DrawImage(ImageID(tp),it\x-((h-*resource\source\size)/2),0,h,h)
capi_pict_rect( *resource\source, ip, it )
If *items\disabled() = #True
FreeImage(tp)
GrabImage(*c\bkg_picture,#PB_Any,0,h*3,h,h)
DrawAlphaImage(ImageID(tp),it\x-((h-*resource\source\size)/2),0)
EndIf
lp + di
Else
ddd = pic_id - 1
If ddd < 0 : ddd = 0 : EndIf
If nr = index
tp = GrabImage(*c\bkg_picture,#PB_Any,32*ddd,48,h+8,h)
Else
tp = GrabImage(*c\bkg_picture,#PB_Any,0,48,h+8,h)
EndIf
DrawImage(ImageID(tp),it\x-((h-*resource\source\size)/2),0,h+8,h)
capi_pict_rect( *resource\source, ip, it )
If *items\disabled() = #True
FreeImage(tp)
GrabImage(*c\bkg_picture,#PB_Any,h,h*3,h+8,h)
DrawAlphaImage(ImageID(tp),it\x-((h-*resource\source\size)/2),0)
EndIf
lp + di + 8
EndIf
;If w <= *c\length
; If it\x > w - *resource\source\size
; FreeImage(tp)
; tp = GrabImage(*resource\source\image_id, #PB_Any, ip\col * *resource\source\size, ip\row * *resource\source\size, *resource\source\size, *resource\source\size)
; MenuItem( #PB_Any, *items\text(), ImageID(tp) )
; EndIf
;EndIf
Else
Line( (nr * *resource\source\size) + lp - (*resource\source\size/2)-1+8, 2, 1, h - 4, *c\dark_color )
Line( (nr * *resource\source\size) + lp - (*resource\source\size/2)+8, 2, 1, h - 4, *c\light_color )
lp - di
;If w <= *c\length
; If it\x > w - *resource\source\size
; MenuBar()
; EndIf
;EndIf
EndIf
Next
If *c\use_picture = #True
FreeImage(tp)
tp = GrabImage(*c\bkg_picture,#PB_Any,0,h,4,h)
DrawImage(ImageID(tp),0,0,4,h)
FreeImage(tp)
tp = GrabImage(*c\bkg_picture,#PB_Any,4,h,4,h)
DrawImage(ImageID(tp),w-4,0,4,h)
EndIf
If w <= *c\length
*items\popup_visible = #True
FreeImage(tp)
tp = GrabImage(*c\bkg_picture,#PB_Any,8,h,12,h)
DrawImage(ImageID(tp),w-12,0,12,h)
Else
*items\popup_visible = #False
EndIf
StopDrawing()
FreeGadget(gadget_id)
ImageGadget(gadget_id,x,y,w,h,ImageID(gadget_id))
EndIf
EndProcedure
Procedure capi_add_item( x.l, y.l, k.s, t.s, *source.struct_capi_items, item_type.l = 0, check_state.l = 0, check_group.l = -1, disable.b = #False, popupid.l = -1 )
AddElement(*source\icon())
AddElement(*source\key())
AddElement(*source\text())
AddElement(*source\cursor())
AddElement(*source\check())
AddElement(*source\cstate())
AddElement(*source\group())
AddElement(*source\type())
AddElement(*source\disabled())
AddElement(*source\invisible())
AddElement(*source\popupid())
*source\icon()\col = x
*source\icon()\row = y
*source\key() = k
*source\text() = t
*source\group() = check_group
*source\type() = item_type
*source\disabled() = disable
*source\invisible() = #False
*source\popupid() = popupid
Select check_state
Case 0
*source\check() = 0
Default
*source\check() = 1
Select check_state
Case 1
*source\cstate() = #True
Case 2
*source\cstate() = #False
EndSelect
EndSelect
*source\popup_visible = #False
EndProcedure
Procedure capi_check_item( gadget_id.l, item_ptr.l, *items.struct_capi_items )
If EventGadget() = gadget_id
SelectElement(*items\cstate(),item_ptr)
If *items\cstate() = #True
*items\cstate() = #False
ElseIf *items\cstate() = #False
*items\cstate() = #True
EndIf
EndIf
EndProcedure
Procedure capi_check_item_group( gadget_id.l, item_ptr.l, *items.struct_capi_items )
If EventGadget() = gadget_id
Define grp.l = 0
SelectElement(*items\cstate(),item_ptr)
SelectElement(*items\group(),item_ptr)
grp = *items\group()
If *items\cstate() = #True
;*items\cstate() = #False
ElseIf *items\cstate() = #False
*items\cstate() = #True
If grp > -1
ForEach *items\group()
If ListIndex(*items\group()) <> item_ptr
If *items\group() = grp
SelectElement(*items\cstate(),ListIndex(*items\group()))
*items\cstate() = #False
EndIf
EndIf
Next
EndIf
EndIf
EndIf
EndProcedure
UsePNGImageDecoder()
If LoadImage( 0, "group.png")
;OpenWindow( 0, 50, 50, 400, 300, "Test")
;Define isrc.struct_capi_pict_rect
;Define ipic.struct_capi_matrix
;Define itar.struct_capi_image
;isrc\image_id = 0
;isrc\size = 16
;itar\image_id = 1
;If CreateImage(1,400, 500)
; StartDrawing(ImageOutput(1))
; Box(0,0,400,500,RGB(250,250,250))
; itar\x = 10
; itar\y = 10
; ipic\col = 0
; ipic\row = 2
; capi_pict_rect( isrc, ipic, itar )
; itar\x = 40
; itar\y = 10
; ipic\col = 1
; ipic\row = 2
; capi_pict_rect( isrc, ipic, itar )
; StopDrawing()
; ImageGadget(1,0,0,400,500,ImageID(1))
;EndIf
;Repeat
; Event = WaitWindowEvent()
;Until Event = #PB_Event_CloseWindow
;EndIf
Define res.struct_capi_resource
Define itm.struct_capi_items
Define isrc.struct_capi_pict_rect
Define bar.struct_capi_con_bkg
Define cur.struct_bar_flag
isrc\image_id = 0
isrc\size = 16
res\source = isrc
res\target = 1
bar\bkg_color = RGB(240,240,245)
bar\light_color =RGB(255,255,255)
bar\dark_color = RGB(140,150,160)
If LoadImage( 2, "bar.png")
bar\use_picture = #True
bar\bkg_picture = 2
Else
bar\use_picture = #False
EndIf
itm\parent = 0
capi_add_popup_menu( itm, 100 )
capi_add_popup_item( itm, 100, "subm", "Apple Inc.", "apple_inc" )
capi_add_popup_item( itm, 100, "subm", "Betriebsysteme", "apple_os" )
capi_add_popup_item( itm, 100, "item", "Mac OS Classic", "apple_mac_c" )
capi_add_popup_item( itm, 100, "sepr" )
capi_add_popup_item( itm, 100, "item", "Mac OS X (PPC)", "apple_mac_x_ppc" )
capi_add_popup_item( itm, 100, "item", "Mac OS X (x86)", "apple_mac_x_x86" )
capi_add_popup_item( itm, 100, "ends" )
capi_add_popup_item( itm, 100, "subm", "Produkte", "apple_products" )
capi_add_popup_item( itm, 100, "item", "Software", "apple_software" )
capi_add_popup_item( itm, 100, "sepr" )
capi_add_popup_item( itm, 100, "item", "iMac", "apple_i_mac" )
capi_add_popup_item( itm, 100, "item", "iBook", "apple_i_book" )
capi_add_popup_item( itm, 100, "item", "iPhone", "apple_i_ph" )
capi_add_popup_item( itm, 100, "item", "iPad", "apple_mac_i_pad" )
capi_add_popup_item( itm, 100, "item", "iPod", "apple_mac_i_pod" )
capi_add_popup_item( itm, 100, "item", "MacBook", "apple_mac_book" )
capi_add_popup_item( itm, 100, "ends" )
capi_add_popup_item( itm, 100, "ends" )
capi_add_popup_item( itm, 100, "subm", "Microsoft Corp.", "microsoft" )
capi_add_popup_item( itm, 100, "item", "Windows 3x", "microsoft_win_3x" )
capi_add_popup_item( itm, 100, "item", "Windows 9x", "microsoft_win_9x" )
capi_add_popup_item( itm, 100, "item", "Windows XP", "microsoft_win_xp" )
capi_add_popup_item( itm, 100, "item", "Windows Vista", "microsoft_win_v" )
capi_add_popup_item( itm, 100, "item", "Windows 7", "microsoft_win_7" )
capi_add_popup_menu( itm, 101 )
capi_add_popup_item( itm, 101, "item", "English", "en" )
capi_add_popup_item( itm, 101, "item", "German", "de" )
capi_add_popup_item( itm, 101, "item", "Turkish", "tr" )
capi_add_item( 0, 0, "a", "", itm ) : itm\text() = "Zeile 1"
capi_add_item( 1, 0, "b", "", itm, 1,0,-1,#False,100 ) : itm\text() = "Zeile 2"
capi_add_item( 2, 0, "c", "", itm,0,0,-1,#True ) : itm\text() = "Zeile 3"
capi_add_item( -1, -1, "", "", itm) : itm\text() = "Zeile 4"
capi_add_item( 3, 0, "d", "", itm,0,1, 6 ) : itm\text() = "Zeile 5"
capi_add_item( 0, 1, "e", "", itm,0,2, 6 ) : itm\text() = "Zeile 6"
capi_add_item( -1, -1, "", "", itm )
capi_add_item( 1, 1, "f", "", itm, 1,0,-1,#True ) : itm\text() = "Zeile 7"
capi_add_item( 2, 1, "g", "", itm,0,0,-1,#False,101 ) : itm\text() = "Zeile 8"
cur\OverBar = 0
cur\ItemGot = 0
cur\ItemPtr = -1
cur\ItemClk = 0
OpenWindow( 0, 50, 50, 400, 300, "Test",#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)
bar\bkg_size = WindowWidth(0)
bar\bkg_pos = 0;WindowHeight(0)-24
capi_gadget_bar( 1, 0, 0, WindowWidth(0), 24, bar, res, itm )
AddWindowTimer(0, 1, 250)
If CreateStatusBar(0,WindowID(0))
AddStatusBarField(400)
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_SizeWindow
bar\bkg_size = WindowWidth(0)
bar\bkg_pos = 0;WindowHeight(0)-24
capi_redraw_bar_item( 1, cur\ItemPtr, 1, bar, res, itm )
EndIf
cur\ItemPtr = capi_cursor_over_item(1,itm)
If cur\ItemPtr > -1
If cur\ItemGot = 0
cur\ItemGot = 1
capi_redraw_bar_item( 1, cur\ItemPtr, 2, bar, res, itm )
If cur\OverBar = 0 : cur\OverBar = 1 : EndIf
EndIf
Else
If cur\OverBar = 1
cur\OverBar = 0
cur\ItemPtr = -1
cur\ItemGot = 0
capi_redraw_bar_item( 1, cur\ItemPtr, 0, bar, res, itm )
EndIf
EndIf
If Event = #PB_Event_Menu
Select capi_get_menu_key(itm,EventMenu())
Case "a" : StatusBarText(0,0,"Folder")
Case "b" : StatusBarText(0,0,"Settings")
Case "c" : StatusBarText(0,0,"Code")
Case "d" : StatusBarText(0,0,"Partial")
Case "e" : StatusBarText(0,0,"Category")
Case "f" : StatusBarText(0,0,"Save")
Case "g" : StatusBarText(0,0,"Copy")
Default
StatusBarText(0,0, capi_get_menu_key(itm,EventMenu()))
EndSelect
EndIf
If Event = #PB_Event_Gadget
If EventGadget() = 1
Select capi_get_item_key(1,itm)
Case "a" : StatusBarText(0,0,"Folder")
Case "b" : StatusBarText(0,0,"Settings")
Case "c" : StatusBarText(0,0,"Code")
Case "d" : StatusBarText(0,0,"Partial")
Case "e" : StatusBarText(0,0,"Category")
Case "f" : StatusBarText(0,0,"Save")
Case "g" : StatusBarText(0,0,"Copy")
EndSelect
If cur\ItemPtr > -1
Select cur\ItemClk
Case 0
capi_redraw_bar_item( 1, cur\ItemPtr, 3, bar, res, itm )
ItemClk = 1
Case 1
capi_redraw_bar_item( 1, cur\ItemPtr, 2, bar, res, itm )
ItemClk = 0
EndSelect
capi_check_item_group( 1, cur\ItemPtr, itm )
ElseIf cur\ItemPtr = -2
;SetWindowTitle(0,Str(IsMenu(1)))
;DisplayPopupMenu(1,WindowID(0))
;DisplayPopupMenu(1,WindowID(0), WindowX(0)+WindowWidth(0),WindowY(0)+GadgetY(1));-WindowMouseY(0)+GadgetY(1) )
EndIf
capi_bar_item_popup(1,itm)
EndIf
EndIf
If Event = #PB_Event_Timer And EventTimer() = 1
If ItemClk = 1
ItemClk = 0
capi_redraw_bar_item( 1, cur\ItemPtr, 2, bar, res, itm )
EndIf
EndIf
;Define ax.l = DesktopMouseX()-WindowX(0)-WindowMouseX(0)
;Define ay.l = DesktopMouseY()-WindowY(0)-WindowMouseY(0)
;SetWindowTitle(0,Str(ax)+"x"+Str(ay))
;SetWindowTitle(0,"Item: = "+Str(cur\ItemPtr)+", IsItem: = "+Str(cur\ItemGot)+", Bar = "+Str(cur\OverBar)+", W = "+Str(bar\bkg_size))
Until Event = #PB_Event_CloseWindow
EndIf
http://www.gonuldefterim.de/pb/pics
die bilder müssen im selben verzeichnis liegen, wie die test-datei.
es handelt sich hierbei um einen ersten versuch, eine toolbar zu basteln, das unter mac, win und lin gleichermaßen funktioniert.
die darstellung lässt sich per bilder steuern. ich dachte mir, das man unter win die uxtheme verwendet könnte, unter mac die mac theme oder eine eigene png-datei und unter linux kann man es auch entweder mit bildern oder dynamischen zeichnen oder so regeln.
allerdings funktioniert der code bei mir unter ubuntu 9 nicht korrekt. es ladet zwar. sobald ich mit dem mauszeiger auf ein element draufgehe, crasht das programm.
wäre echt sehr dankbar für eine gute lösung.
da wäre noch ne frage, wie kann ich auf einem imagegadget die keyboard-tasten abfragen. danke erstmal.
mfg
kurt
- ts-soft
- Beiträge: 22292
- Registriert: 08.09.2004 00:57
- Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel - Wohnort: Berlin
Re: flackernder imagegadget
Diesen sehr unübersichtlichen Code werde ich mir nicht antun, aber wenn es ums Neuzeichnen geht,
der Punkt, wo dies geschehen sollte, wird in Deinem Eventloop überhaupt nicht abgefragt
#PB_Event_Repaint
der Punkt, wo dies geschehen sollte, wird in Deinem Eventloop überhaupt nicht abgefragt

#PB_Event_Repaint
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

-
- Beiträge: 173
- Registriert: 30.11.2010 02:34
Re: flackernder imagegadget
#pb_event_repaint sorgt dafür, das ich gar nichts mehr machen kann. das ganze programm hängt dann. deshalb habe ich auf ihn verzichten müssen.