@@ -12,7 +12,11 @@ struct HexViewerStartscreen {
12
12
13
13
14
14
typedef struct {
15
- int some_value ;
15
+ uint8_t file_bytes [HEX_VIEWER_LINES_ON_SCREEN ][HEX_VIEWER_BYTES_PER_LINE ];
16
+ uint32_t file_offset ;
17
+ uint32_t file_read_bytes ;
18
+ uint32_t file_size ;
19
+ bool mode ; // Print address or content
16
20
} HexViewerStartscreenModel ;
17
21
18
22
void hex_viewer_startscreen_set_callback (
@@ -29,7 +33,7 @@ void hex_viewer_startscreen_draw(Canvas* canvas, HexViewerStartscreenModel* mode
29
33
UNUSED (model );
30
34
canvas_clear (canvas );
31
35
32
- if (!app -> model -> file_size ) {
36
+ if (!model -> file_size ) {
33
37
canvas_set_color (canvas , ColorBlack );
34
38
canvas_set_font (canvas , FontPrimary );
35
39
canvas_draw_str_aligned (canvas , 64 , 10 , AlignCenter , AlignTop , "HexViewer v2.0" );
@@ -40,17 +44,17 @@ void hex_viewer_startscreen_draw(Canvas* canvas, HexViewerStartscreenModel* mode
40
44
} else {
41
45
canvas_set_color (canvas , ColorBlack );
42
46
43
- elements_button_left (canvas , app -> model -> mode ? "Addr" : "Text" );
47
+ elements_button_left (canvas , model -> mode ? "Addr" : "Text" );
44
48
elements_button_right (canvas , "Info" );
45
49
elements_button_center (canvas , "Menu" );
46
50
47
51
int ROW_HEIGHT = 12 ;
48
52
int TOP_OFFSET = 10 ;
49
53
int LEFT_OFFSET = 3 ;
50
54
51
- uint32_t line_count = app -> model -> file_size / HEX_VIEWER_BYTES_PER_LINE ;
52
- if (app -> model -> file_size % HEX_VIEWER_BYTES_PER_LINE != 0 ) line_count += 1 ;
53
- uint32_t first_line_on_screen = app -> model -> file_offset / HEX_VIEWER_BYTES_PER_LINE ;
55
+ uint32_t line_count = model -> file_size / HEX_VIEWER_BYTES_PER_LINE ;
56
+ if (model -> file_size % HEX_VIEWER_BYTES_PER_LINE != 0 ) line_count += 1 ;
57
+ uint32_t first_line_on_screen = model -> file_offset / HEX_VIEWER_BYTES_PER_LINE ;
54
58
if (line_count > HEX_VIEWER_LINES_ON_SCREEN ) {
55
59
uint8_t width = canvas_width (canvas );
56
60
elements_scrollbar_pos (
@@ -63,24 +67,24 @@ void hex_viewer_startscreen_draw(Canvas* canvas, HexViewerStartscreenModel* mode
63
67
}
64
68
65
69
char temp_buf [32 ];
66
- uint32_t row_iters = app -> model -> file_read_bytes / HEX_VIEWER_BYTES_PER_LINE ;
67
- if (app -> model -> file_read_bytes % HEX_VIEWER_BYTES_PER_LINE != 0 ) row_iters += 1 ;
70
+ uint32_t row_iters = model -> file_read_bytes / HEX_VIEWER_BYTES_PER_LINE ;
71
+ if (model -> file_read_bytes % HEX_VIEWER_BYTES_PER_LINE != 0 ) row_iters += 1 ;
68
72
69
73
for (uint32_t i = 0 ; i < row_iters ; ++ i ) {
70
74
uint32_t bytes_left_per_row =
71
- app -> model -> file_read_bytes - i * HEX_VIEWER_BYTES_PER_LINE ;
75
+ model -> file_read_bytes - i * HEX_VIEWER_BYTES_PER_LINE ;
72
76
bytes_left_per_row = MIN (bytes_left_per_row , HEX_VIEWER_BYTES_PER_LINE );
73
77
74
- if (app -> model -> mode ) {
75
- memcpy (temp_buf , app -> model -> file_bytes [i ], bytes_left_per_row );
78
+ if (model -> mode ) {
79
+ memcpy (temp_buf , model -> file_bytes [i ], bytes_left_per_row );
76
80
temp_buf [bytes_left_per_row ] = '\0' ;
77
81
for (uint32_t j = 0 ; j < bytes_left_per_row ; ++ j )
78
82
if (!isprint ((int )temp_buf [j ])) temp_buf [j ] = '.' ;
79
83
80
84
canvas_set_font (canvas , FontKeyboard );
81
85
canvas_draw_str (canvas , LEFT_OFFSET , TOP_OFFSET + i * ROW_HEIGHT , temp_buf );
82
86
} else {
83
- uint32_t addr = app -> model -> file_offset + i * HEX_VIEWER_BYTES_PER_LINE ;
87
+ uint32_t addr = model -> file_offset + i * HEX_VIEWER_BYTES_PER_LINE ;
84
88
snprintf (temp_buf , 32 , "%04lX" , addr );
85
89
86
90
canvas_set_font (canvas , FontKeyboard );
@@ -89,7 +93,7 @@ void hex_viewer_startscreen_draw(Canvas* canvas, HexViewerStartscreenModel* mode
89
93
90
94
char * p = temp_buf ;
91
95
for (uint32_t j = 0 ; j < bytes_left_per_row ; ++ j )
92
- p += snprintf (p , 32 , "%02X " , app -> model -> file_bytes [i ][j ]);
96
+ p += snprintf (p , 32 , "%02X " , model -> file_bytes [i ][j ]);
93
97
94
98
canvas_set_font (canvas , FontKeyboard );
95
99
canvas_draw_str (canvas , LEFT_OFFSET + 41 , TOP_OFFSET + i * ROW_HEIGHT , temp_buf );
@@ -99,7 +103,20 @@ void hex_viewer_startscreen_draw(Canvas* canvas, HexViewerStartscreenModel* mode
99
103
}
100
104
101
105
static void hex_viewer_startscreen_model_init (HexViewerStartscreenModel * const model ) {
102
- model -> some_value = 1 ;
106
+ memset (model -> file_bytes , 0 , sizeof (model -> file_bytes ));
107
+ model -> file_offset = 0 ;
108
+ model -> file_read_bytes = 0 ;
109
+ model -> file_size = 0 ;
110
+ model -> mode = false;
111
+ }
112
+
113
+ static void update_local_model_from_app (HexViewer * const app , HexViewerStartscreenModel * const model )
114
+ {
115
+ memcpy (model -> file_bytes , app -> model -> file_bytes , sizeof (model -> file_bytes ));
116
+ model -> file_offset = app -> model -> file_offset ;
117
+ model -> file_read_bytes = app -> model -> file_read_bytes ;
118
+ model -> file_size = app -> model -> file_size ;
119
+ model -> mode = app -> model -> mode ;
103
120
}
104
121
105
122
bool hex_viewer_startscreen_input (InputEvent * event , void * context ) {
@@ -112,20 +129,21 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
112
129
instance -> view ,
113
130
HexViewerStartscreenModel * model ,
114
131
{
115
- UNUSED (model );
116
132
instance -> callback (HexViewerCustomEventStartscreenBack , instance -> context );
133
+ update_local_model_from_app (instance -> context , model );
117
134
},
118
135
true);
119
136
break ;
120
137
case InputKeyLeft :
121
138
with_view_model (
122
- instance -> view ,
123
- HexViewerStartscreenModel * model ,
124
- {
125
- UNUSED (model );
126
- instance -> callback (HexViewerCustomEventStartscreenLeft , instance -> context );
127
- },
128
- true);
139
+ instance -> view ,
140
+ HexViewerStartscreenModel * model ,
141
+ {
142
+ UNUSED (model );
143
+ instance -> callback (HexViewerCustomEventStartscreenLeft , instance -> context );
144
+ update_local_model_from_app (instance -> context , model );
145
+ },
146
+ true);
129
147
break ;
130
148
case InputKeyRight :
131
149
with_view_model (
@@ -134,6 +152,7 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
134
152
{
135
153
UNUSED (model );
136
154
instance -> callback (HexViewerCustomEventStartscreenRight , instance -> context );
155
+ update_local_model_from_app (instance -> context , model );
137
156
},
138
157
true);
139
158
break ;
@@ -144,6 +163,7 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
144
163
{
145
164
UNUSED (model );
146
165
instance -> callback (HexViewerCustomEventStartscreenUp , instance -> context );
166
+ update_local_model_from_app (instance -> context , model );
147
167
},
148
168
true);
149
169
break ;
@@ -154,6 +174,7 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
154
174
{
155
175
UNUSED (model );
156
176
instance -> callback (HexViewerCustomEventStartscreenDown , instance -> context );
177
+ update_local_model_from_app (instance -> context , model );
157
178
},
158
179
true);
159
180
break ;
@@ -164,6 +185,7 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
164
185
{
165
186
UNUSED (model );
166
187
instance -> callback (HexViewerCustomEventStartscreenOk , instance -> context );
188
+ update_local_model_from_app (instance -> context , model );
167
189
},
168
190
true);
169
191
break ;
@@ -185,7 +207,8 @@ void hex_viewer_startscreen_enter(void* context) {
185
207
instance -> view ,
186
208
HexViewerStartscreenModel * model ,
187
209
{
188
- hex_viewer_startscreen_model_init (model );
210
+ hex_viewer_startscreen_model_init (model );
211
+ // TODO update_local_model_from_app(instance->context, model);
189
212
},
190
213
true
191
214
);
0 commit comments