Opened 9 years ago

Closed 9 years ago

#815 closed enhancement/feature request (fixed)

Possibility to change background image of OSDs runtime

Reported by: tegzed Owned by: Singesang
Priority: minor Milestone:
Component: osd/core Version: git master
Severity: Keywords:
Cc:

Description

The following patch adds a mechanism that makes it possible for osd items being notified about some navit events. Also a new command is added to send notifications from the command system to the OSDs. The attached modification uses this to change button osds' background image runtime. This can also be used (but not yet included) to create a new osd type that accepts and displays a string from the command system making infos currently only accessible from the command system (like routing engine status) displayable in OSD too.

To change the button osd background image from command one needs to set a unique name for the osd and use a command like this in the osd:

<osd name="my_osd" enabled="yes" type="button" x="200"  y="175" command='osd_set_attr("my_osd","src","zoom_out.xpm");' src="zoom_in.xpm"  />

The parameters of osd_set_attr are the following in order:

  • osd name
  • type of the attribute sent by the notification
  • value of the attribute sent by the notification

Attachments (1)

osd.diff (11.4 KB) - added by tegzed 9 years ago.
added command interface osd to display command system accessible attributes

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by korrosa

  • Component changed from core to osd/core
  • Owner changed from KaZeR to Singesang
  • Priority changed from major to minor
  • Type changed from defect/bug to enhancement/feature request

The example works for me.

Using set_int_var and get_int_var I wonder if this feature would allow toggling between different button backgrounds. Something to try...

comment:2 Changed 9 years ago by tegzed

yes it should work. I have not committed this change since i need some discussion with cp15 if he agrees the introduced programming interface additions. you will need a conditional statement in your command like this:

get_int_var("button_state") ? 
  osd_set_attr("my_osd","src","zoom_out.xpm") :  
  osd_set_attr("my_osd","src","zoom_in.xpm");

Of course "button_state" int variable should be set appropriately before this.

comment:3 Changed 9 years ago by korrosa

Dammit, you got there before me! Yeah, that's how I'd envisaged doing it whilst cycling to work (fresh air helps me think!).

This is already very useful, but once the ability is added to accept and displays a string from the command system then this would become a killer feature! Good stuff!

comment:4 Changed 9 years ago by korrosa

I tried the following line, but it doesn't quite work as expected:

<osd name="button_3d" enabled="yes" type="button" x="-140" y="-105" src="/home/netbook/.navit/displays/3D.png" use_overlay="1" accesskey="&#32;" command='
pitch=pitch==0?20:0;
orientation=pitch==0?0:-1;
pitch==0?osd_set_attr("button_3d","src","/home/netbook/.navit/displays/3D.png"):osd_set_attr("button_3d","src","/home/netbook/.navit/displays/2D.png");
zoom=pitch==0?200:15;
' 
/>

Upon startup, the icon is 3D.png.
After first click, the icon changes to 2D.png
After the second click, the icon briefly changes to 3D.png, but switches back to 2D.png. I would expect it to stay on 3D.png until my next click.

Is it something I'm doing wrong?

comment:5 Changed 9 years ago by tegzed

yep, maybe the command system evaluates both branches in the conditional expr in the order you wrote them and after this uses the return value of the appropriate branch for the evauated conditinal expression. You may try something like this instead:

'osd_set_attr("button_3d","src",
pitch==0 ? "/home/netbook/.navit/displays/3D.png" : "/home/netbook/.navit/displays/3D.png" )'


I guess both setting to 2d and 3d are called for each click and the 2d remained valid since it was executed last time.

comment:6 Changed 9 years ago by korrosa

Your method works a treat! Toggleable button backgrounds are now a reality! Brilliant!

comment:7 follow-up: Changed 9 years ago by tegzed

Hello,

in the latest attached version of the patch i added a new osd type to display command system accessible attributes either as text or as image. The below examples show how to use it for displaying route_status as text or image.

<osd name="my_osd_cmdif"  update_period="1"  enabled="yes" type="cmd_interface" w="200" h="20" x="350"  y="175" command='osd_set_attr("my_osd_cmdif","status_text",
route.route_status==1     ? "Dst set" : 
(route.route_status==0     ? "No dst set" :  
(route.route_status==3     ? "Not found" : 
(route.route_status==5     ? "building path" : 
(route.route_status==13    ? "building path" : 
(route.route_status==17    ? "path done new" : 
(route.route_status==33    ? "path done incremental" : "unhandled"
)))))))

'  />
<osd name="my_osd_cmdif2" update_period="1" enabled="yes" type="cmd_interface" w="50" h="50" x="350"  y="200" command='osd_set_attr("my_osd_cmdif2","src",
route.route_status==1     ? "gui_display_48_48.png" : 
(route.route_status==0     ? "gui_display_48_48.png" :  
(route.route_status==3     ? "gui_display_48_48.png" : 
(route.route_status==5     ? "zoom_out.xpm" : 
(route.route_status==13    ? "zoom_out.xpm" : 
(route.route_status==17    ? "zoom_out.xpm" : 
(route.route_status==33    ? "zoom_out.xpm" : "zoom_out.xpm"
)))))))

'  />

The new osd type periodically executes a command with update_period periodicity. The osd_set_attr() command system function can be used to set an image for the osd (src attribute) or a text (status_text attribute) ;

Changed 9 years ago by tegzed

added command interface osd to display command system accessible attributes

comment:8 Changed 9 years ago by korrosa

If I ever meet you I'm not gonna buy you just one drink - I'm getting you absolutely legless! This is feature is literally so versatile, it's amazing! Nothing else to say really, except good work!

comment:9 in reply to: ↑ 7 Changed 9 years ago by hape

Replying to https://wiki.navit-project.org/index.php/user:tegzed:

Hello,

in the latest attached version of the patch i added a new osd type to display command system accessible attributes either as text or as image. The below examples show how to use it for displaying route_status as text or image.

Thanks for making this possible and reaction that quick on a chat question ;-). It will make a lot of Pre users happy.

HaPe?

comment:10 Changed 9 years ago by korrosa

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.