| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-09 16:05:06 -05:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 14:03:56 -05:00
										 |  |  | #include <hexagram/cluster.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  | hexagram_cluster *hexagram_cluster_new(double width, double height) { | 
					
						
							|  |  |  |     hexagram_cluster *cluster; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((cluster = malloc(sizeof(*cluster))) == NULL) { | 
					
						
							|  |  |  |         goto error_malloc_cluster; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hexagram_tacho_init(&cluster->tacho, | 
					
						
							|  |  |  |                         width  * 0.2, | 
					
						
							|  |  |  |                         height * 0.5, | 
					
						
							|  |  |  |                         height * 0.4, | 
					
						
							|  |  |  |                         6500.0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hexagram_speedo_init(&cluster->speedo, | 
					
						
							|  |  |  |                          width  * 0.8, | 
					
						
							|  |  |  |                          height * 0.5, | 
					
						
							|  |  |  |                          height * 0.4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hexagram_thermo_init(&cluster->thermo, | 
					
						
							|  |  |  |                          width  * 0.43, | 
					
						
							|  |  |  |                          height * 0.76, | 
					
						
							|  |  |  |                          height * 0.13, | 
					
						
							|  |  |  |                          240.0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hexagram_fuel_init(&cluster->fuel, | 
					
						
							|  |  |  |                        width  * 0.57, | 
					
						
							|  |  |  |                        height * 0.76, | 
					
						
							|  |  |  |                        height * 0.13, | 
					
						
							|  |  |  |                        0.125); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hexagram_mfd_init(&cluster->mfd, | 
					
						
							|  |  |  |                       width  * 0.42, | 
					
						
							|  |  |  |                       height * 0.10, | 
					
						
							|  |  |  |                       width  * 0.16, | 
					
						
							|  |  |  |                       height * 0.50); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cluster->width  = width; | 
					
						
							|  |  |  |     cluster->height = height; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 16:05:06 -05:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Initialize mutable state | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     memset(&cluster->state, '\0', sizeof(cluster->state)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  |     return cluster; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | error_malloc_cluster: | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void hexagram_cluster_draw_bg(hexagram_cluster *cluster, | 
					
						
							|  |  |  |                               cairo_t *cr) { | 
					
						
							| 
									
										
										
										
											2019-06-09 14:03:56 -05:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Paint canvas black | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     cairo_set_source_rgb(cr, 0, 0, 0); | 
					
						
							|  |  |  |     cairo_paint(cr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  |     hexagram_tacho_draw_face(&cluster->tacho, cr); | 
					
						
							|  |  |  |     hexagram_speedo_draw_face(&cluster->speedo, cr); | 
					
						
							|  |  |  |     hexagram_thermo_draw_face(&cluster->thermo, cr); | 
					
						
							|  |  |  |     hexagram_fuel_draw_face(&cluster->fuel, cr); | 
					
						
							|  |  |  |     hexagram_mfd_draw(&cluster->mfd, cr); | 
					
						
							| 
									
										
										
										
											2019-06-09 14:03:56 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  | void hexagram_cluster_draw_fg(hexagram_cluster *cluster, | 
					
						
							| 
									
										
										
										
											2019-06-09 16:05:06 -05:00
										 |  |  |                               cairo_t *cr) { | 
					
						
							|  |  |  |     hexagram_tacho_draw_needle(&cluster->tacho, cr, cluster->state.rpm); | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     hexagram_speedo_draw_needle(&cluster->speedo, cr, | 
					
						
							| 
									
										
										
										
											2019-06-09 16:05:06 -05:00
										 |  |  |                                 (2.032 * cluster->state.rps * 3600) / 1000.0); | 
					
						
							| 
									
										
										
										
											2019-06-09 14:03:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  |     hexagram_thermo_draw_needle(&cluster->thermo, cr, | 
					
						
							| 
									
										
										
										
											2019-06-09 16:05:06 -05:00
										 |  |  |                                 cluster->state.temp); | 
					
						
							| 
									
										
										
										
											2019-06-09 14:03:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 15:46:41 -05:00
										 |  |  |     hexagram_fuel_draw_needle(&cluster->fuel, cr, | 
					
						
							| 
									
										
										
										
											2019-06-09 16:05:06 -05:00
										 |  |  |                               cluster->state.fuel); | 
					
						
							| 
									
										
										
										
											2019-06-09 14:03:56 -05:00
										 |  |  | } |