iPXE
Data Structures | Macros | Functions
jumpscroll.h File Reference

Jump scrolling. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  jump_scroller
 A jump scroller. More...
 

Macros

#define SCROLL(delta)   ( ( unsigned int ) ( uint16_t ) ( int16_t ) (delta) )
 Construct scroll movement. More...
 
#define SCROLL_DELTA(scroll)   ( ( int16_t ) ( (scroll) & 0x0000ffffUL ) )
 Extract change in scroller position. More...
 
#define SCROLL_FLAGS   0xffff0000UL
 Scroll movement flags. More...
 
#define SCROLL_WRAP   0x80000000UL
 Wrap around scrolling. More...
 
#define SCROLL_NONE   SCROLL ( 0 )
 Do not scroll. More...
 
#define SCROLL_UP   SCROLL ( -1 )
 Scroll up by one line. More...
 
#define SCROLL_DOWN   SCROLL ( +1 )
 Scroll down by one line. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int jump_scroll_is_first (struct jump_scroller *scroll)
 Check if jump scroller is currently on first page. More...
 
static int jump_scroll_is_last (struct jump_scroller *scroll)
 Check if jump scroller is currently on last page. More...
 
unsigned int jump_scroll_key (struct jump_scroller *scroll, int key)
 Jump scrolling. More...
 
unsigned int jump_scroll_move (struct jump_scroller *scroll, unsigned int move)
 Move scroller. More...
 
int jump_scroll (struct jump_scroller *scroll)
 Jump scroll to new page (if applicable) More...
 

Detailed Description

Jump scrolling.

Definition in file jumpscroll.h.

Macro Definition Documentation

◆ SCROLL

#define SCROLL (   delta)    ( ( unsigned int ) ( uint16_t ) ( int16_t ) (delta) )

Construct scroll movement.

Parameters
deltaChange in scroller position
Return values
moveScroll movement

Definition at line 32 of file jumpscroll.h.

◆ SCROLL_DELTA

#define SCROLL_DELTA (   scroll)    ( ( int16_t ) ( (scroll) & 0x0000ffffUL ) )

Extract change in scroller position.

Parameters
moveScroll movement
Return values
deltaChange in scroller position

Definition at line 40 of file jumpscroll.h.

◆ SCROLL_FLAGS

#define SCROLL_FLAGS   0xffff0000UL

Scroll movement flags.

Definition at line 43 of file jumpscroll.h.

◆ SCROLL_WRAP

#define SCROLL_WRAP   0x80000000UL

Wrap around scrolling.

Definition at line 44 of file jumpscroll.h.

◆ SCROLL_NONE

#define SCROLL_NONE   SCROLL ( 0 )

Do not scroll.

Definition at line 47 of file jumpscroll.h.

◆ SCROLL_UP

#define SCROLL_UP   SCROLL ( -1 )

Scroll up by one line.

Definition at line 50 of file jumpscroll.h.

◆ SCROLL_DOWN

#define SCROLL_DOWN   SCROLL ( +1 )

Scroll down by one line.

Definition at line 53 of file jumpscroll.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ jump_scroll_is_first()

static int jump_scroll_is_first ( struct jump_scroller scroll)
inlinestatic

Check if jump scroller is currently on first page.

Parameters
scrollJump scroller
Return values
is_firstScroller is currently on first page

Definition at line 61 of file jumpscroll.h.

61  {
62 
63  return ( scroll->first == 0 );
64 }
unsigned int first
First visible item.
Definition: jumpscroll.h:23

References jump_scroller::first.

Referenced by draw_menu_items(), and draw_setting_rows().

◆ jump_scroll_is_last()

static int jump_scroll_is_last ( struct jump_scroller scroll)
inlinestatic

Check if jump scroller is currently on last page.

Parameters
scrollJump scroller
Return values
is_lastScroller is currently on last page

Definition at line 72 of file jumpscroll.h.

72  {
73 
74  return ( ( scroll->first + scroll->rows ) >= scroll->count );
75 }
unsigned int first
First visible item.
Definition: jumpscroll.h:23
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:17

References jump_scroller::count, jump_scroller::first, and jump_scroller::rows.

Referenced by draw_menu_items(), and draw_setting_rows().

◆ jump_scroll_key()

unsigned int jump_scroll_key ( struct jump_scroller scroll,
int  key 
)

Jump scrolling.

Handle keypress

Parameters
scrollJump scroller
keyKey pressed by user
Return values
moveScroller movement, or zero

Definition at line 42 of file jumpscroll.c.

42  {
43  unsigned int flags = 0;
44  int16_t delta;
45 
46  /* Sanity checks */
47  assert ( scroll->rows != 0 );
48  assert ( scroll->count != 0 );
49  assert ( scroll->current < scroll->count );
50  assert ( scroll->first < scroll->count );
51  assert ( scroll->first <= scroll->current );
52  assert ( scroll->current < ( scroll->first + scroll->rows ) );
53 
54  /* Handle key, if applicable */
55  switch ( key ) {
56  case KEY_UP:
57  delta = -1;
58  break;
59  case TAB:
61  /* fall through */
62  case KEY_DOWN:
63  delta = +1;
64  break;
65  case KEY_PPAGE:
66  delta = ( scroll->first - scroll->current - 1 );
67  break;
68  case KEY_NPAGE:
69  delta = ( scroll->first - scroll->current + scroll->rows );
70  break;
71  case KEY_HOME:
72  delta = -( scroll->count );
73  break;
74  case KEY_END:
75  delta = +( scroll->count );
76  break;
77  default:
78  delta = 0;
79  break;
80  }
81 
82  return ( SCROLL ( delta ) | flags );
83 }
#define SCROLL(delta)
Construct scroll movement.
Definition: jumpscroll.h:32
#define KEY_NPAGE
Page down.
Definition: keys.h:113
#define KEY_HOME
Home.
Definition: keys.h:109
#define KEY_DOWN
Down arrow.
Definition: keys.h:105
#define KEY_UP
Up arrow.
Definition: keys.h:104
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int first
First visible item.
Definition: jumpscroll.h:23
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
#define TAB
Definition: keys.h:46
#define KEY_PPAGE
Page up.
Definition: keys.h:112
#define KEY_END
End.
Definition: keys.h:108
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:17
signed short int16_t
Definition: stdint.h:16
#define SCROLL_WRAP
Wrap around scrolling.
Definition: jumpscroll.h:44
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21
union @383 key
Sense key.
Definition: crypto.h:284
uint8_t flags
Flags.
Definition: ena.h:18

References assert(), jump_scroller::count, jump_scroller::current, jump_scroller::first, flags, key, KEY_DOWN, KEY_END, KEY_HOME, KEY_NPAGE, KEY_PPAGE, KEY_UP, jump_scroller::rows, SCROLL, SCROLL_WRAP, and TAB.

Referenced by form_loop(), main_loop(), and menu_loop().

◆ jump_scroll_move()

unsigned int jump_scroll_move ( struct jump_scroller scroll,
unsigned int  move 
)

Move scroller.

Parameters
scrollJump scroller
moveScroller movement
Return values
moveContinuing scroller movement (if applicable)

Definition at line 92 of file jumpscroll.c.

93  {
94  int16_t delta = SCROLL_DELTA ( move );
95  int current = scroll->current;
96  int last = ( scroll->count - 1 );
97 
98  /* Sanity checks */
99  assert ( move != 0 );
100  assert ( scroll->count != 0 );
101 
102  /* Move to the new current item */
103  current += delta;
104 
105  /* Default to continuing movement in the same direction */
106  delta = ( ( delta >= 0 ) ? +1 : -1 );
107 
108  /* Check for start/end of list */
109  if ( ( current >= 0 ) && ( current <= last ) ) {
110  /* We are still within the list. Update the current
111  * item and continue moving in the same direction (if
112  * applicable).
113  */
114  scroll->current = current;
115  } else {
116  /* We have attempted to move outside the list. If we
117  * are wrapping around, then continue in the same
118  * direction (if applicable), otherwise reverse.
119  */
120  if ( ! ( move & SCROLL_WRAP ) )
121  delta = -delta;
122 
123  /* Move to start or end of list as appropriate */
124  if ( delta >= 0 ) {
125  scroll->current = 0;
126  } else {
127  scroll->current = last;
128  }
129  }
130 
131  return ( SCROLL ( delta ) | ( move & SCROLL_FLAGS ) );
132 }
#define SCROLL(delta)
Construct scroll movement.
Definition: jumpscroll.h:32
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define SCROLL_DELTA(scroll)
Extract change in scroller position.
Definition: jumpscroll.h:40
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
uint32_t last
Length to read in last segment, or zero.
Definition: pccrc.h:30
#define SCROLL_FLAGS
Scroll movement flags.
Definition: jumpscroll.h:43
static int move(int y, int x)
Definition: curses.h:593
signed short int16_t
Definition: stdint.h:16
#define SCROLL_WRAP
Wrap around scrolling.
Definition: jumpscroll.h:44
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21

References assert(), jump_scroller::count, jump_scroller::current, last, move(), SCROLL, SCROLL_DELTA, SCROLL_FLAGS, and SCROLL_WRAP.

Referenced by form_loop(), main_loop(), and menu_loop().

◆ jump_scroll()

int jump_scroll ( struct jump_scroller scroll)

Jump scroll to new page (if applicable)

Parameters
scrollJump scroller
Return values
jumpedJumped to a new page

Definition at line 140 of file jumpscroll.c.

140  {
141  unsigned int index;
142 
143  /* Sanity checks */
144  assert ( scroll->rows != 0 );
145  assert ( scroll->count != 0 );
146  assert ( scroll->current < scroll->count );
147  assert ( scroll->first < scroll->count );
148 
149  /* Do nothing if we are already on the correct page */
150  index = ( scroll->current - scroll->first );
151  if ( index < scroll->rows )
152  return 0;
153 
154  /* Move to required page */
155  while ( scroll->first < scroll->current )
156  scroll->first += scroll->rows;
157  while ( scroll->first > scroll->current )
158  scroll->first -= scroll->rows;
159 
160  return 1;
161 }
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int first
First visible item.
Definition: jumpscroll.h:23
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:17
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21

References assert(), jump_scroller::count, jump_scroller::current, jump_scroller::first, index, and jump_scroller::rows.

Referenced by main_loop(), menu_loop(), and show_menu().