note description: "[ Position cursor for a HD44780 display controller. Note: Manipulating a cursor position does not literally move cursor on the associated controller. ]" legal : "See notice at end of class." status : "See notice at end of class."; author : "Paul Bates (paul.a.bates@gmail.com)" date : "$Date$" revision: "$Revision$" class HD44780_CURSOR create make feature {NONE} -- initialization make (a_controller: like controller) -- Initializes a caret cursor for a HD44780 controller. -- -- `a_controller': The controller to initialize a cursor for. require a_controller_attached: attached a_controller a_controller_is_interface_usable: a_controller.is_interface_usable do controller := a_controller line := 1 column := 1 ensure controller_set: controller = a_controller end feature -- Access controller: HD44780_CONTROLLER -- Controller cursor is manipulated by. line: NATURAL_8 assign set_line -- Cursor's line position. column: NATURAL_8 assign set_column -- Cursor's column position. feature {HD44780_CONTROLLER} -- Element change set_line (a_line: like line) -- Sets `line' with `a_line' require a_line_big_enough: a_line > 0 a_line_small_enough: a_line <= controller.lines do line := a_line ensure line_set: line = a_line end set_column (a_col: like column) -- Sets `a_col' with `column' require a_col_big_enough: a_col > 0 a_col_small_enough: a_col <= controller.columns do column := a_col ensure column_set: column = a_col end feature -- Status report is_off: BOOLEAN -- Is cursor position off display? do Result := is_before_column or is_after_column or is_before_line or is_after_line ensure not_off: Result implies not (is_before_column or is_after_column or is_before_line or is_after_line) end feature {HD44780_CONTROLLER} -- Status report is_before_line: BOOLEAN -- Is cursor position before a valid line number? do Result := line < 1 ensure line_before: Result = (line < 1) end is_after_line: BOOLEAN -- Is cursor position after a valid line number? do Result := line > controller.lines ensure line_after: Result = (line > controller.lines) end is_before_column: BOOLEAN -- Is cursor position before a valid line number? do Result := column < 1 ensure column_before: Result = (column < 1) end is_after_column: BOOLEAN -- Is cursor position after a valid line number? do Result := column > controller.columns ensure column_after: Result = (column > controller.columns) end feature {HD44780_CONTROLLER} -- Movement line_forth -- Moves to the next line. require not_is_after_line: not is_after_line do line := line + 1 ensure line_incremented: line = old line + 1 end line_back -- Moves to the previous line. require not_is_before_line : not is_before_line do line := line - 1 ensure line_decremented: line = old line - 1 end column_forth -- -- Moves to the next column. require not_is_after_column: not is_after_column do column := column + 1 ensure column_incremented: column = old column + 1 end column_back -- -- Moves to the previous column. require not_is_before_column: not is_before_column do column := column - 1 ensure column_decremented: column = old column - 1 end invariant controller_attached: attached controller controller_is_interface_usable: controller.is_interface_usable line_big_enough: not is_before_line implies line > 0 line_small_enough: not is_after_line implies line <= controller.lines column_big_enough: not is_before_column implies column > 0 column_small_enough: not is_after_column implies column <= controller.columns end