-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrolling.go
139 lines (120 loc) · 3.96 KB
/
scrolling.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright (c) 2013-2021 Utkan Güngördü <utkan@freeconsole.org>
* Copyright (c) 2021-2023 Piotr Grabowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gomicsv
import (
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/gtk"
"github.com/fauu/gomicsv/util"
)
type DragScroll struct {
InProgress bool
StartX float64
StartY float64
StartHAdjustmentVal float64
StartVAdjustmentVal float64
}
func (app *App) scroll(dx, dy float64) {
if !app.archiveIsLoaded() {
return
}
imgw, imgh := app.getImageAreaInnerSize()
vadj := app.W.ScrolledWindow.GetVAdjustment()
hadj := app.W.ScrolledWindow.GetHAdjustment()
vIncrement := vadj.GetMinimumIncrement()
vVal := vadj.GetValue()
vMin := vadj.GetLower()
vMax := vadj.GetUpper() - float64(imgh) - 2
hIncrement := hadj.GetMinimumIncrement()
hVal := hadj.GetValue()
hMin := hadj.GetLower()
hMax := hadj.GetUpper() - float64(imgw) - 2
if dy > 0 {
if vVal >= vMax {
if app.Config.SmartScroll {
if app.S.SmartScrollInProgress {
app.nextPage()
app.S.SmartScrollInProgress = false
} else {
app.S.SmartScrollInProgress = true
}
}
} else {
vadj.SetValue(util.Clamp(vVal+vIncrement, vMin, vMax))
app.W.ScrolledWindow.SetVAdjustment(vadj)
app.S.SmartScrollInProgress = false
}
} else if dy < 0 {
if vVal <= vMin {
if app.Config.SmartScroll {
if app.S.SmartScrollInProgress {
app.previousPage()
app.S.SmartScrollInProgress = false
} else {
app.S.SmartScrollInProgress = true
}
}
} else {
vadj.SetValue(util.Clamp(vVal-vIncrement, vMin, vMax))
app.W.ScrolledWindow.SetVAdjustment(vadj)
app.S.SmartScrollInProgress = false
}
}
if dx > 0 && hVal < hMax {
hadj.SetValue(util.Clamp(hVal+hIncrement, hMin, hMax))
app.W.ScrolledWindow.SetHAdjustment(hadj)
} else if dx < 0 && hVal > hMin {
hadj.SetValue(util.Clamp(hVal-hIncrement, hMin, hMax))
app.W.ScrolledWindow.SetHAdjustment(hadj)
}
}
func (app *App) scrollToStart() {
app.W.ScrolledWindow.GetVAdjustment().SetValue(0) // Vertical: top
var newHadj float64 = 0
if app.Config.MangaMode {
imgw, _ := app.getImageAreaInnerSize()
newHadj = float64(imgw)
}
app.W.ScrolledWindow.GetHAdjustment().SetValue(newHadj) // Horizontal: left (non-manga) or right (manga) edge
}
func (app *App) scrollToEnd() {
imgw, imgh := app.getImageAreaInnerSize()
app.W.ScrolledWindow.GetVAdjustment().SetValue(float64(imgh)) // Vertical: bottom
var newHadj float64 = 0
if !app.Config.MangaMode {
newHadj = float64(imgw)
}
app.W.ScrolledWindow.GetHAdjustment().SetValue(newHadj) // Horizontal: left (manga) or right (non-manga) edge
}
func (app *App) dragScrollStart(x, y, vAdjustmentVal, hAdjustmentVal float64) {
app.S.DragScroll.InProgress = true
app.S.DragScroll.StartX = x
app.S.DragScroll.StartY = y
app.S.DragScroll.StartVAdjustmentVal = vAdjustmentVal
app.S.DragScroll.StartHAdjustmentVal = hAdjustmentVal
app.setCursor(cursorGrabbing)
}
func (app *App) dragScrollUpdate(sw *gtk.ScrolledWindow, event *gdk.EventButton) {
deltaX := app.S.DragScroll.StartX - event.X()
sw.GetHAdjustment().SetValue(app.S.DragScroll.StartHAdjustmentVal + deltaX)
deltaY := app.S.DragScroll.StartY - event.Y()
sw.GetVAdjustment().SetValue(app.S.DragScroll.StartVAdjustmentVal + deltaY)
}
func (app *App) dragScrollEnd() {
app.S.DragScroll.InProgress = false
app.setCursor(cursorDefault)
}