Gleitend nach unten scrollen - Strecke?

Übersicht BlitzBasic BlitzPlus

Neue Antwort erstellen

KnorxThieus

Betreff: Gleitend nach unten scrollen - Strecke?

BeitragMo, März 03, 2014 10:34
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo,

Ich habe in BlitzPlus eine ScrollBoxuser posted image erstellt und möchte nun gleitend hinabscrollen.
Also verwende ich Sinus. Das sähe ja dann in etwa so aus: BlitzBasic: [AUSKLAPPEN]
win = CreateWindow("Test", 200, 200, 400, 400, Desktop(), 1)

sb = CreateScrollBox(0, 0, ClientWidth(win), ClientHeight(win), ClientWidth(win) - 15, 800, win)

Stop
;Scrolle ein bisschen am Balken... wird nachher aktualisiert
;Drück auf die grüne Ampel!
UpdateScrollBox sb

s = GetScrollBoxScrolled(sb) ;wie weit schon gescrollt ist
y# = s

t = CreateTimer(200)
For a = 0 To 180
y# = y# + ((800 / 2 - s) / 90.) * Sin(a)
SetScrollBoxScrolled sb, 0, y
WaitTimer t
Next
FreeTimer t

Stop

End



;ScrollBox by KnorxThieus
;°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
;Functions:
;CreateScrollBox(x, y, visible_width, visible_height, total_width, total_height, group[, style])
; creates a scrollbox
; PARAMETERS:
; x, y, visible_width, visible_height --> coordinates
; total_width, total_height --> total size
; group --> parent
; style = 1 --> border
; RETURN:
; ScrollBox' panel, which is parent for its gadgets
;UpdateScrollBox(box)
; actualizes visible field of box with values of sliders, actualizes sliders' positions for mousewheel
; PARAMETERS:
; box --> gadget returned by CreateScrollBox
; RETURN:
; /
;SetScrollBoxWheel(box[, direction][, value])
; sets whats happens if mouse is wheeled
; PARAMETERS:
; box --> gadget returned by CreateScrollBox
; direction:
; +1 --> horizontal scrolling activated
; +2 --> vertical scrolling activated
; value --> value pro 1 wheel
; RETURN:
; /
;GetScrollBoxWheel(box)
; return set scrollbox wheel
; PARAMETERS:
; box --> gadget returned by CreateScrollBox
; RETURN:
; if value for vertical wheel exists, that value.
; else, if value for horizontal wheel exists, that horizontal value.
;SetScrollBoxRange(box, total_width, total_height, [visible_width, visible_height])
; set visible and total size of scrollbox
; PARAMETERS:
; box --> gadget returned by CreateScrollBox
; total_width, total_height --> total size
; visible_width, visible_height --> coordinates
; RETURN:
; /
;GetScrollBoxRange(box, coordinate)
; returns total size of scrollbox
; PARAMETERS:
; box --> gadget returned by CreateScrollBox
; coordinate = 0 --> selects direction width for return
; coordinate = 1 --> selects direction height for return
; RETURN:
; size of selected direction
;ScrollBoxGadget(box)
; returns visible gadget of scrollbox
; gadgets should be created into scrollbox BOX; gadget actions like hiding the scrollbox should be employed on scrollbox GADGET which's returned here
; PARAMETERS:
; box --> gadget returned by CreateScrollBox
; RETURN:
; explaned on the top
;SetScrollBoxScrolled(box, x, y[, style])
; scrolls the scrollbox on position x, y
; PARAMETERS:
; box --> gadget returned by CreateScrollBox
; x, y --> scroll coordinates
; style = 1 --> x and y are added to actual scroll coordinates.
; RETURN:
; /
;GetScrollBoxScrolled(box, coordinate = 0)
; returns scrolled position of scrollbox
; PARAMETERS:
; box --> I think now we all know what means the parameter box :-)
; coordinate = 0 --> selects x-axis for return
; coordinate = 1 --> selects y-axis for return
; RETURN:
; scroll value of selected axis
;####################################################################
;Don't forget writing type ScrollBox_data into your code!
;It's recommendable copying ScrollBox.decls to your userlibs!

Type ScrollBox_data
Field box, panel, ppanel
Field x, y, visible_width, visible_height, total_width, total_height, group, style
Field slider_h, slider_v
Field wheelx, wheely
End Type

Function CreateScrollBox(x, y, visible_width, visible_height, total_width, total_height, group, style = 0)
ScrollBox.ScrollBox_data = New ScrollBox_data
ScrollBox\x = x
ScrollBox\y = y
ScrollBox\visible_width = visible_width
ScrollBox\visible_height = visible_height
ScrollBox\total_width = total_width + 15
ScrollBox\total_height = total_height + 15
ScrollBox\group = group
ScrollBox\style = style
ScrollBox\box = CreatePanel(ScrollBox\x, ScrollBox\y, ScrollBox\visible_width, ScrollBox\visible_height, ScrollBox\group, ScrollBox\style) ;-15 removed
ScrollBox\ppanel = CreatePanel(0, 0, ClientWidth(ScrollBox\box) - 15, ClientHeight(ScrollBox\box) - 15, ScrollBox\box)
ScrollBox\panel = CreatePanel(0, 0, ScrollBox\total_width - 15, ScrollBox\total_height - 15, ScrollBox\ppanel) ;added -15
ScrollBox\slider_h = CreateSlider(0, ClientHeight(ScrollBox\box) - 15, ClientWidth(ScrollBox\box) - 15, 15, ScrollBox\box, 1)
ScrollBox\slider_v = CreateSlider(ClientWidth(ScrollBox\box) - 15, 0, 15, ClientHeight(ScrollBox\box) - 15, ScrollBox\box, 2)
SetSliderRange ScrollBox\slider_h, ScrollBox\visible_width, ScrollBox\total_width
SetSliderRange ScrollBox\slider_v, ScrollBox\visible_height, ScrollBox\total_height
If ScrollBox\total_width <= ScrollBox\visible_width
HideGadget ScrollBox\slider_h
EndIf
If ScrollBox\total_height <= ScrollBox\visible_height
HideGadget ScrollBox\slider_v
EndIf
Return ScrollBox\panel
End Function

Function UpdateScrollBox(box)
Local sb_wx, sb_wy
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
If EventID() = $204
sb_wx = EventData() * ScrollBox\wheelx
sb_wy = EventData() * ScrollBox\wheely
EndIf
SetSliderValue ScrollBox\slider_v, SliderValue(ScrollBox\slider_v) - sb_wy
SetSliderValue ScrollBox\slider_h, SliderValue(ScrollBox\slider_h) - sb_wx
SetGadgetShape ScrollBox\panel, 0 - SliderValue(ScrollBox\slider_h), 0 - SliderValue(ScrollBox\slider_v), GadgetWidth(ScrollBox\panel), GadgetHeight(ScrollBox\panel)
End Function

Function SetScrollBoxWheel(box, direction = 0, value = 0)
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
If value = 0 Then value = ScrollBox\wheely
; Select direction
; Case 0
; ScrollBox\wheelx = 0
; ScrollBox\wheely = 0
; Case 1
; ScrollBox\wheelx = value
; ScrollBox\wheely = 0
; Case 2
; ScrollBox\wheelx = 0
; ScrollBox\wheely = value
; Case 3
; ScrollBox\wheelx = value
; ScrollBox\wheely = value
; End Select
ScrollBox\wheelx = GetBit(direction, 0) * value
ScrollBox\wheely = GetBit(direction, 1) * value
End Function

Function GetScrollBoxWheel(box)
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
If ScrollBox\wheely
Return ScrollBox\wheely
ElseIf ScrollBox\wheelx
Return ScrollBox\wheelx
EndIf
End Function

Function SetScrollBoxRange(box, total_width, total_height, visible_width = 0, visible_height = 0)
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
If visible_width <> 0 Then ScrollBox\visible_width = visible_width
If visible_height <> 0 Then ScrollBox\visible_height = visible_width
If group <> 0 Then ScrollBox\group = group
ScrollBox\total_width = total_width + 15
ScrollBox\total_height = total_height + 15
SetGadgetShape ScrollBox\box, ScrollBox\x, ScrollBox\y, ScrollBox\visible_width, ScrollBox\visible_height
SetGadgetShape ScrollBox\ppanel, 0, 0, ClientWidth(ScrollBox\box) - 15, ClientHeight(ScrollBox\box) - 15
SetGadgetShape ScrollBox\panel, 0, 0, ScrollBox\total_width, ScrollBox\total_height
SetSliderRange ScrollBox\slider_h, ClientWidth(ScrollBox\box), ScrollBox\total_width
SetSliderRange ScrollBox\slider_v, ClientHeight(ScrollBox\box), ScrollBox\total_height
If ScrollBox\total_width <= ScrollBox\visible_width
HideGadget ScrollBox\slider_h
Else
ShowGadget ScrollBox\slider_h
EndIf
If ScrollBox\total_height <= ScrollBox\visible_height
HideGadget ScrollBox\slider_v
Else
ShowGadget ScrollBox\slider_v
EndIf
End Function

Function GetScrollBoxRange(box, coordinate)
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
If coordinate = 0 Then Return ScrollBox\total_width
If coordinate = 1 Then Return ScrollBox\total_height
End Function

Function ScrollBoxGadget(box)
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
Return ScrollBox\box
End Function

Function SetScrollBoxScrolled(box, x, y, style = 0)
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
If style
x = SliderValue(ScrollBox\slider_h) + x
y = SliderValue(ScrollBox\slider_v) + y
EndIf
SetSliderValue ScrollBox\slider_h, x
SetSliderValue ScrollBox\slider_v, y
SetGadgetShape ScrollBox\panel, 0 - SliderValue(ScrollBox\slider_h), 0 - SliderValue(ScrollBox\slider_v), GadgetWidth(ScrollBox\panel), GadgetHeight(ScrollBox\panel)
End Function

Function GetScrollBoxScrolled(box, coordinate = 0)
For ScrollBox.ScrollBox_data = Each ScrollBox_data
If ScrollBox\panel = box
ScrollBox = ScrollBox.ScrollBox_data
Exit
EndIf
Next
If coordinate = 0 Then Return SliderValue(ScrollBox\slider_v)
If coordinate = 1 Then Return SliderValue(ScrollBox\slider_h)
End Function

;Unterfunktion
Function GetBit(byte, bitnumber)
Local gb_ret
gb_ret = byte And 2 ^ bitnumber
If gb_ret <> 0 Then gb_ret = 1
Return gb_ret
End Function

(unten sind bloß die Funktionen. Zitat:
Die Funktion CreateScrollBox erstellt ein ScrollBox-Objekt. [...] Eine ScrollBox verhält sich wie ein Panel, das mit Überlauf-Schutz ausgestattet ist: Durch die Scrollbalken kann eine größere Gesamtfläche genutzt werden. [...] Benutze SetScrollBoxScrolled und GetScrollBoxScrolled, um per Hand die Scrollbalken einzustellen. [...] Verwende UpdateScrollBox nach EventID $401 bei unbekannter (d.h. sei EventSource() = Default) und bei Nutzung des Mausrads $204.
)

Aber mein Ziel ist es, genau bis zum Ende unten zu scrollen, jetzt weiß ich aber nicht, wie ich auf den Faktor vor Sin komme! Die anfängliche Höhe ist unbekannt. Insgesamt werden ja 181 "Scrollungen" vorgenommen (For...next), durchschnittswert von sin ist dabei 0,5? Müsste doch. Also komme ich auf 91px nach unten (0,5 * 181), bei Faktor 1. Um jetzt 400 zu schaffen muss der Faktor doch 400 / 91 sein.

Das sind meine Überlegungen, aber irgendwie funktioniert der Code oben nicht: Wenn ich z.B. eine Scrollbalkenlänge den Balken nach unten ziehe und den Debug-Modus beende, wird nicht bis nach unten gescrollt!

Woran liegt das, ich habe schon sehr viel darüber gesonnen?

MFG,
KnorxThieus
Version: BlitzPlus / Blitz+
  • Zuletzt bearbeitet von KnorxThieus am Di, März 04, 2014 19:28, insgesamt einmal bearbeitet

Xeres

Moderator

BeitragMo, März 03, 2014 20:17
Antworten mit Zitat
Benutzer-Profile anzeigen
~VERSCHOBEN~

Da BlitzPlus.

Viel Code und nicht direkt ausführbar -> keine Lust mir das an zu schauen.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

KnorxThieus

BeitragDi, März 04, 2014 19:27
Antworten mit Zitat
Benutzer-Profile anzeigen
Xeres hat Folgendes geschrieben:
~VERSCHOBEN~

Da BlitzPlus.

OK, ich hätte das ja genauso gut mit 2D-Objekten machen können, denn es geht ja eher um die Scrollbewegung... egal.

Xeres hat Folgendes geschrieben:
Viel Code und nicht direkt ausführbar -> keine Lust mir das an zu schauen.

Zwei Dutzend Zeilen Code, der Rest ist die Funktion, damit keiner erst dem Link oben folgen muss.
Und zum nicht direkt ausführbar - Ups, das Include habe ich eben erst gesehen, die Zeile kann aber weg. Embarassed
Version: BlitzPlus / Blitz+

Neue Antwort erstellen


Übersicht BlitzBasic BlitzPlus

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group