2 * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL
);
32 #include <ipxe/keys.h>
33 #include <ipxe/jumpscroll.h>
38 * @v scroll Jump scroller
39 * @v key Key pressed by user
40 * @ret move Scroller movement, or zero
42 int jump_scroll_key ( struct jump_scroller
*scroll
, int key
) {
45 assert ( scroll
->rows
!= 0 );
46 assert ( scroll
->count
!= 0 );
47 assert ( scroll
->current
< scroll
->count
);
48 assert ( scroll
->first
< scroll
->count
);
49 assert ( scroll
->first
<= scroll
->current
);
50 assert ( scroll
->current
< ( scroll
->first
+ scroll
->rows
) );
52 /* Handle key, if applicable */
59 return ( scroll
->first
- scroll
->current
- 1 );
61 return ( scroll
->first
- scroll
->current
+ scroll
->rows
);
63 return -( scroll
->count
);
65 return +( scroll
->count
);
74 * @v scroll Jump scroller
75 * @v move Scroller movement
76 * @ret move Continuing scroller movement (if applicable)
78 int jump_scroll_move ( struct jump_scroller
*scroll
, int move
) {
79 int current
= scroll
->current
;
80 int last
= ( scroll
->count
- 1 );
84 assert ( scroll
->count
!= 0 );
86 /* Move to the new current item */
89 /* Check for start/end of list */
91 /* We have attempted to move before the start of the
92 * list. Move to the start of the list and continue
93 * moving forwards (if applicable).
97 } else if ( current
> last
) {
98 /* We have attempted to move after the end of the
99 * list. Move to the end of the list and continue
100 * moving backwards (if applicable).
102 scroll
->current
= last
;
105 /* Update the current item and continue moving in the
106 * same direction (if applicable).
108 scroll
->current
= current
;
109 return ( ( move
> 0 ) ?
+1 : -1 );
114 * Jump scroll to new page (if applicable)
116 * @v scroll Jump scroller
117 * @ret jumped Jumped to a new page
119 int jump_scroll ( struct jump_scroller
*scroll
) {
123 assert ( scroll
->rows
!= 0 );
124 assert ( scroll
->count
!= 0 );
125 assert ( scroll
->current
< scroll
->count
);
126 assert ( scroll
->first
< scroll
->count
);
128 /* Do nothing if we are already on the correct page */
129 index
= ( scroll
->current
- scroll
->first
);
130 if ( index
< scroll
->rows
)
133 /* Move to required page */
134 while ( scroll
->first
< scroll
->current
)
135 scroll
->first
+= scroll
->rows
;
136 while ( scroll
->first
> scroll
->current
)
137 scroll
->first
-= scroll
->rows
;