1. Trammell Hudson
  2. Magic Lantern

Commits

hud...@kremvax  committed 25409ac

Started moving menus into separate files

  • Participants
  • Parent commits 9b13198
  • Branches default

Comments (0)

Files changed (3)

File menu.c

View file
 #include "property.h"
 #include "lens.h"
 #include "font.h"
-
-#define MENU_FONT	FONT(FONT_LARGE,COLOR_WHITE,COLOR_BG)
+#include "menu.h"
 
 static void
 draw_version( void )
 static struct gui_task * menu_task_ptr;
 
 
-struct menu_entry
-{
-	int			selected;
-	void *			priv;
-	void			(*select)( void * priv );
-	void			(*display)(
-		void *			priv,
-		int			x,
-		int			y,
-		int			selected
-	);
-};
-
-
 void
 menu_print(
 	void *			priv,
 	int			x,
 	int			y,
-	int			selected
+	int			highlighted
 )
 {
 	bmp_printf( MENU_FONT, x, y, "%s%s",
-		selected ? "->" : "  ",
+		highlighted ? "->" : "  ",
 		(const char*) priv
 	);
 }
 
 
-unsigned zebra_level = 0xF000;
-void zebra_toggle( void * priv )
+void
+menu_add(
+	struct menu_entry *	head,
+	struct menu_entry *	new_entry
+)
 {
-	unsigned * ptr = priv;
-	*ptr = (*ptr + 0x4000) & 0xF000;
+#if 1
+	new_entry->selected	= 0;
+	new_entry->next		= head->next;
+	new_entry->prev		= head;
+	head->next		= new_entry;
+#else
+	// Maybe later...
+	struct menu_entry * child = head->child;
+	if( !child )
+	{
+		// No other child entries; add this one
+		// and select it
+		new_entry->highlighted	= 1;
+		new_entry->prev		= NULL;
+		new_entry->next		= NULL;
+		head->child		= new_entry;
+		return;
+	}
+
+	// Walk the child list to find the end
+	while( child->next )
+		child = child->next;
+
+	// Push the new entry onto the end of the list
+	new_entry->selected	= 0;
+	new_entry->prev		= child;
+	new_entry->next		= NULL;
+	child->next		= new_entry;
+#endif
 }
 
-void zebra_display( void * priv, int x, int y, int selected )
-{
-	bmp_printf( MENU_FONT, x, y, "%sZebra level: %04x",
-		selected ? "->" : "  ",
-		*(unsigned*) priv
-	);
-}
-
-unsigned zebra_draw = 1;
-void zebra_draw_toggle( void * priv )
-{
-	unsigned * ptr = priv;
-	*ptr = !*ptr;
-}
-
-void zebra_draw_display( void * priv, int x, int y, int selected )
-{
-	bmp_printf( MENU_FONT, x, y, "%sZebras %s",
-		selected ? "->" : "  ",
-		*(unsigned*) priv ? "on" : "off"
-	);
-}
 
 unsigned audio_mgain = 0;
 void audio_mgain_toggle( void * priv )
 
 
 
-struct menu_entry main_menu[] = {
-	{
-		.selected	= 1,
-		.priv		= &zebra_draw,
-		.select		= zebra_draw_toggle,
-		.display	= zebra_draw_display,
-	},
-	{
-		.priv		= &zebra_level,
-		.select		= zebra_toggle,
-		.display	= zebra_display,
-	},
+struct menu_entry main_menu = {
+	.priv		= "Magic Lantern",
+	.selected	= 1,
+	.select		= 0,
+	.display	= menu_print,
+};
+
+
+/*
 	{
 		.priv		= "HDMI FullHD",
 		.select		= enable_full_hd,
 		.selected	= -1,
 	},
 };
+*/
 
 
 void
 	int			selected
 )
 {
-	for( ; menu->selected >= 0 ; menu++, y += font_large.height )
+	while( menu )
 	{
 		menu->display(
 			menu->priv,
 			y,
 			menu->selected
 		);
+
+		y += font_large.height;
+		menu = menu->next;
 	}
 }
 
 	struct menu_entry *	menu
 )
 {
-	for( ; menu->selected >= 0 ; menu++ )
+	for( ; menu ; menu = menu->next )
 	{
 		if( !menu->selected )
 			continue;
 {
 	struct menu_entry *	menu = menu_top;
 
-	for( ; menu->selected >= 0 ; menu++ )
+	for( ; menu ; menu = menu->next )
 	{
 		if( !menu->selected )
 			continue;
 		if( ev == PRESS_JOY_UP )
 		{
 			// First and moving up?
-			if( menu == menu_top )
+			if( !menu->prev )
 				break;
-			menu[-1].selected = 1;
-			menu[ 0].selected = 0;
+			menu->selected = 0;
+			menu->prev->selected = 1;
 			break;
 		}
 
 		if( ev == PRESS_JOY_DOWN )
 		{
 			// Last and moving down?
-			if( menu[1].selected < 0 )
+			if( !menu->next )
 				break;
-			menu[+1].selected = 1;
-			menu[ 0].selected = 0;
+			menu->selected = 0;
+			menu->next->selected = 1;
 			break;
 		}
 	}
 	events[ last_menu_event ][2] = arg3;
 	last_menu_event = (last_menu_event + 1) % MAX_GUI_EVENTS;
 
-	menu_display( main_menu, 0, 100, 1 );
+	bmp_printf( MENU_FONT, 0, 100-font_large.height,
+		"%s",
+		main_menu.priv
+	);
+
+	menu_display( &main_menu, 0, 100, 1 );
 
 	switch( event )
 	{
 
 	case PRESS_JOY_UP:
 	case PRESS_JOY_DOWN:
-		menu_move( main_menu, event );
+		menu_move( &main_menu, event );
 		break;
 
 	case PRESS_SET_BUTTON:
-		menu_select( main_menu );
+		menu_select( &main_menu );
 		break;
 
 	default:

File menu.h

View file
+/** \file
+ * Menu structures and functions.
+ */
+#ifndef _menu_h_
+#define _menu_h_
+
+
+#define MENU_FONT	FONT(FONT_LARGE,COLOR_WHITE,COLOR_BG)
+
+struct menu_entry
+{
+	struct menu_entry *	next;
+	struct menu_entry *	prev;
+	int			selected;
+	void *			priv;
+	void			(*select)(
+		void *			priv
+	);
+	void			(*display)(
+		void *			priv,
+		int			x,
+		int			y,
+		int			selected
+	);
+};
+
+extern struct menu_entry main_menu;
+
+
+extern void
+menu_print(
+	void *			priv,
+	int			x,
+	int			y,
+	int			selected
+);
+
+
+extern void
+menu_select(
+	struct menu_entry *	entry
+);
+
+
+extern void
+menu_add(
+	struct menu_entry *	menu,
+	struct menu_entry *	new_entry
+);
+
+
+#endif

File zebra.c

View file
 #include "bmp.h"
 #include "version.h"
 #include "config.h"
+#include "menu.h"
 
-extern unsigned zebra_level;
-extern unsigned zebra_draw;
+
+unsigned zebra_level = 0xF000;
+unsigned zebra_draw = 1;
+unsigned crop_draw = 1;
 
 /** Draw white thin crop marks
  *  And draw the 16:9 crop marks for full time
 	void *			bmp_row
 )
 {
+	if( !crop_draw )
+		return 0;
+
 	if( y != 50 && y != 380 )
 		return 0;
 
 		if( draw_matte(y, b_row) )
 			continue;
 
+		if( !zebra_draw )
+			continue;
+
 		for( x=1 ; x < vram->width-1 ; x++ )
 		{
 
 }
 
 
+void zebra_toggle( void * priv )
+{
+	unsigned * ptr = priv;
+	*ptr = (*ptr + 0x4000) & 0xF000;
+}
 
+void zebra_display( void * priv, int x, int y, int selected )
+{
+	bmp_printf( MENU_FONT, x, y, "%sZebra level: %04x",
+		selected ? "->" : "  ",
+		*(unsigned*) priv
+	);
+}
+
+void zebra_draw_toggle( void * priv )
+{
+	unsigned * ptr = priv;
+	*ptr = !*ptr;
+}
+
+void zebra_draw_display( void * priv, int x, int y, int selected )
+{
+	bmp_printf( MENU_FONT, x, y, "%sZebras %s",
+		selected ? "->" : "  ",
+		*(unsigned*) priv ? " on" : "off"
+	);
+}
+
+void crop_toggle( void * priv )
+{
+	unsigned * ptr = priv;
+	*ptr = !*ptr;
+}
+
+void crop_display( void * priv, int x, int y, int selected )
+{
+	bmp_printf( MENU_FONT, x, y, "%sCrop %s",
+		selected ? "->" : "  ",
+		*(unsigned*) priv ? " on" : "off"
+	);
+}
+
+struct menu_entry zebra_draw_menu =
+{
+	.priv		= &zebra_draw,
+	.select		= zebra_draw_toggle,
+	.display	= zebra_draw_display,
+};
+
+struct menu_entry zebra_level_menu =
+{
+	.priv		= &zebra_level,
+	.select		= zebra_toggle,
+	.display	= zebra_display,
+};
+
+struct menu_entry crop_draw_menu =
+{
+	.priv		= &crop_draw,
+	.select		= crop_toggle,
+	.display	= crop_display,
+};
 
 int
 zebra_task( void )
 {
-	msleep( 5000 );
+	msleep( 3000 );
 
 	zebra_draw = config_int( global_config, "zebra.draw", 1 );
 	zebra_level = config_int( global_config, "zebra.level", 0xF000 );
+	crop_draw = config_int( global_config, "crop.draw", 1 );
+
+	menu_add( &main_menu, &crop_draw_menu );
+	menu_add( &main_menu, &zebra_draw_menu );
+	menu_add( &main_menu, &zebra_level_menu );
 
 	DebugMsg( DM_MAGIC, 3, "Zebras %s, threshold %x",
 		zebra_draw ? "on" : "off",
 
 	while(1)
 	{
-		if( !gui_show_menu && zebra_draw )
+		if( !gui_show_menu )
 		{
 			draw_zebra();
 			msleep( 100 );