Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Menu.h « Display « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec83c139f16862191d3757c1a1dbbd94f2da87ce (plain)
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
/*
 * Menu.h
 *
 *  Created on: 22 Jan 2018
 *      Author: David
 */

#ifndef SRC_DISPLAY_MENU_H_
#define SRC_DISPLAY_MENU_H_

#include "RepRapFirmware.h"

#if SUPPORT_12864_LCD

#include "MenuItem.h"

class MessageBox;

// Class to represent either a full page menu or a popup menu.
// For space reasons we store only a single instance of this class. Each nested menu is indented by a fixed margin from its parent.
class Menu
{
public:
	Menu(Lcd& refLcd) noexcept;
	~Menu();

	void Load(const char* filename) noexcept;							// load a menu file
	void Pop() noexcept;
	void EncoderAction(int action) noexcept;
	void Refresh() noexcept;
	void ClearHighlighting() noexcept;
	void DisplayMessageBox(const MessageBox& mbox) noexcept;
	void ClearMessageBox() noexcept;

private:
	void LoadFixedMenu() noexcept;
	void ResetCache() noexcept;
	void Reload() noexcept;
	void DrawAll() noexcept;
	const char *ParseMenuLine(char * s) noexcept;
	void LoadError(const char *msg, unsigned int line) noexcept;
	void AddItem(MenuItem *item, bool isSelectable) noexcept;
	const char *AppendString(const char *s) noexcept;

	void EncoderActionEnterItemHelper() noexcept;
	void EncoderActionScrollItemHelper(int action) noexcept;
	void EncoderAction_ExecuteHelper(const char *const cmd) noexcept;

	void AdvanceHighlightedItem(int n) noexcept;
	MenuItem *FindNextSelectableItem(MenuItem *p) const noexcept;
	MenuItem *FindPrevSelectableItem(MenuItem *p) const noexcept;

	static const char *SkipWhitespace(const char *s) noexcept;
	static char *SkipWhitespace(char *s) noexcept;
	static bool CheckVisibility(MenuItem::Visibility vis) noexcept;

#ifdef __LPC17xx__
    static const size_t CommandBufferSize = 1024;
#else
    static const size_t CommandBufferSize = 2500;
#endif
	static const size_t MaxMenuLineLength = 120;				// adjusts behaviour in Reload()
	static const size_t MaxMenuFilenameLength = 18;
	static const size_t MaxMenuNesting = 8;						// maximum number of nested menus
	static const PixelNumber InnerMargin = 2;					// how many pixels we keep clear inside the border
	static const PixelNumber OuterMargin = 8 + InnerMargin;		// how many pixels of the previous menu we leave on each side

	Lcd& lcd;

	uint32_t timeoutValue;										// how long to time out after 0 = no timeout
	uint32_t lastActionTime;

	MenuItem *selectableItems;									// selectable items at the innermost level
	MenuItem *unSelectableItems;								// unselectable items at the innermost level
	MenuItem *highlightedItem;									// which item is selected, or nullptr if nothing selected
	String<MaxMenuFilenameLength> filenames[MaxMenuNesting];
	size_t numNestedMenus;
	bool itemIsSelected;
	bool displayingFixedMenu;
	bool displayingErrorMessage;
	bool displayingMessageBox;

	// Variables used while parsing
	size_t commandBufferIndex;
	unsigned int errorColumn;									// column in the current line at which ParseMenuLine hit an error
	MenuItem::FontNumber fontNumber;
	PixelNumber currentMargin;
	PixelNumber row, column;
	PixelNumber rowOffset;

	// Buffer for commands to be executed when the user presses a selected item
	char commandBuffer[CommandBufferSize];
};

#endif

#endif /* SRC_DISPLAY_MENU_H_ */