mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 23:11:38 +00:00
[qwaq] Fix various scrollbar related issues
The editor now uses the vertical scrollbar for handling mouse wheel scrolling, thus keeping the scrollbar in sync. Scrollbar index can now cover the full range (not sure why I had that -1), and the potential divide by zero is avoided properly. Thumb-tab now positioned properly when the range is 0.
This commit is contained in:
parent
f09810b595
commit
2572011a4b
4 changed files with 16 additions and 44 deletions
|
@ -37,8 +37,6 @@
|
|||
-(string)filepath;
|
||||
-(Point)cursor;
|
||||
-setStatusView:(EditStatus *)status;
|
||||
-scrollUp:(unsigned) count;
|
||||
-scrollDown:(unsigned) count;
|
||||
-scrollLeft:(unsigned) count;
|
||||
-scrollRight:(unsigned) count;
|
||||
-pageUp;
|
||||
|
|
|
@ -154,11 +154,11 @@ handleEvent (Editor *self, qwaq_event_t *event)
|
|||
if (event.what & qe_mouse) {
|
||||
if (event.what == qe_mouseclick) {
|
||||
if (event.mouse.buttons & (1 << 3)) {
|
||||
[self scrollUp: 1];
|
||||
[self.vScrollBar page:1 dir:0];
|
||||
return 1;
|
||||
}
|
||||
if (event.mouse.buttons & (1 << 4)) {
|
||||
[self scrollDown: 1];
|
||||
[self.vScrollBar page:1 dir:1];
|
||||
return 1;
|
||||
}
|
||||
if (event.mouse.buttons & (1 << 5)) {
|
||||
|
@ -243,40 +243,6 @@ handleEvent (Editor *self, qwaq_event_t *event)
|
|||
return self;
|
||||
}
|
||||
|
||||
-scrollUp:(unsigned) count
|
||||
{
|
||||
unsigned index;
|
||||
unsigned lines;
|
||||
if (count == 1) {
|
||||
index = [buffer prevLine: base_index];
|
||||
} else {
|
||||
index = [buffer prevLine: base_index :count];
|
||||
}
|
||||
lines = [buffer countLines: {index, base_index - index}];
|
||||
base.y -= lines;
|
||||
base_index = index;
|
||||
[self redraw];
|
||||
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||
return self;
|
||||
}
|
||||
|
||||
-scrollDown:(unsigned) count
|
||||
{
|
||||
unsigned index;
|
||||
unsigned lines;
|
||||
if (count == 1) {
|
||||
index = [buffer nextLine: base_index];
|
||||
} else {
|
||||
index = [buffer nextLine: base_index :count];
|
||||
}
|
||||
lines = [buffer countLines: {base_index, index - base_index}];
|
||||
base.y += lines;
|
||||
base_index = index;
|
||||
[self redraw];
|
||||
[self moveCursor: {cursor.x - base.x, cursor.y - base.y}];
|
||||
return self;
|
||||
}
|
||||
|
||||
-scrollLeft:(unsigned) count
|
||||
{
|
||||
if (base.x > count) {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
-setSingleStep:(unsigned)singleStep;
|
||||
-setIndex:(unsigned)index;
|
||||
-(unsigned)index;
|
||||
-page:(unsigned)step dir:(unsigned) dir;
|
||||
@end
|
||||
|
||||
#endif//__qwaq_ui_scrollbar_h
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
thumbTab = [Button withPos:thumbPos
|
||||
releasedIcon:icons[2] pressedIcon:icons[2]];
|
||||
|
||||
[forwardButton setGrowMode:gfGrowAll];
|
||||
|
||||
[[backButton onClick] addListener:self :@selector(scrollBack:)];
|
||||
[[forwardButton onClick] addListener:self :@selector(scrollForward:)];
|
||||
[[thumbTab onPress] addListener:self :thumbSel];
|
||||
|
@ -110,15 +112,20 @@ static void
|
|||
position_tab (ScrollBar *self)
|
||||
{
|
||||
Point p = {0, 0};
|
||||
Point o = [self.thumbTab origin];
|
||||
if (self.range > 0) {
|
||||
if (self.vertical) {
|
||||
p.y = 1 + self.index * (self.ylen - 3) / (self.range - 1);
|
||||
p.y = 1 + self.index * (self.ylen - 3) / self.range;
|
||||
} else {
|
||||
p.x = 1 + self.index * (self.xlen - 3) / (self.range - 1);
|
||||
p.x = 1 + self.index * (self.xlen - 3) / self.range;
|
||||
}
|
||||
} else {
|
||||
if (self.vertical) {
|
||||
p.y = 1;
|
||||
} else {
|
||||
p.x = 1;
|
||||
}
|
||||
}
|
||||
[self.thumbTab move:{p.x - o.x, p.y - o.y}];
|
||||
[self.thumbTab moveTo:p];
|
||||
[self redraw];
|
||||
}
|
||||
|
||||
|
@ -138,8 +145,8 @@ position_tab (ScrollBar *self)
|
|||
unsigned oind = index;
|
||||
|
||||
if (dir) {
|
||||
if (range - 1 - index < step) {
|
||||
step = range - 1 - index;
|
||||
if (range - index < step) {
|
||||
step = range - index;
|
||||
}
|
||||
index += step;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue