graph_gui.c
changeset 1079 95a0d4edb544
parent 983 4765bf636f6b
child 1085 56facccb1f3d
equal deleted inserted replaced
1078:1b9163f2e7eb 1079:95a0d4edb544
     5 #include "gui.h"
     5 #include "gui.h"
     6 #include "gfx.h"
     6 #include "gfx.h"
     7 #include "player.h"
     7 #include "player.h"
     8 #include "economy.h"
     8 #include "economy.h"
     9 
     9 
    10 static uint _legend_showbits;
    10 static uint _legend_excludebits;
    11 static uint _legend_cargobits;
    11 static uint _legend_cargobits;
    12 
    12 
    13 /************************/
    13 /************************/
    14 /* GENERIC GRAPH DRAWER */
    14 /* GENERIC GRAPH DRAWER */
    15 /************************/
    15 /************************/
    16 
    16 
    17 enum {GRAPH_NUM = 16};
    17 enum {GRAPH_NUM = 16};
    18 
    18 
    19 typedef struct GraphDrawer {
    19 typedef struct GraphDrawer {
    20 	uint sel;
    20 	uint sel; // bitmask of the players *excluded* (e.g. 11111111 means that no players are shown)
    21 	byte num_dataset;
    21 	byte num_dataset;
    22 	byte num_on_x_axis;
    22 	byte num_on_x_axis;
    23 	byte month;
    23 	byte month;
    24 	byte year;
    24 	byte year;
    25 	bool include_neg;
    25 	bool include_neg;
   171 	}
   171 	}
   172 
   172 
   173 	/* draw lines and dots */
   173 	/* draw lines and dots */
   174 	i = 0;
   174 	i = 0;
   175 	row_ptr = gw->cost[0];
   175 	row_ptr = gw->cost[0];
   176 	sel = gw->sel; // show only selected lines. GraphDrawer qw->sel set in Graph-Legend (_legend_showbits)
   176 	sel = gw->sel; // show only selected lines. GraphDrawer qw->sel set in Graph-Legend (_legend_excludebits)
   177 	do {
   177 	do {
   178 		if (!(sel & 1)) {
   178 		if (!(sel & 1)) {
   179 			x = gw->left + 55;
   179 			x = gw->left + 55;
   180 			j = gw->num_on_x_axis;assert(j>0);
   180 			j = gw->num_on_x_axis;assert(j>0);
   181 			col_ptr = row_ptr;
   181 			col_ptr = row_ptr;
   215 
   215 
   216 	switch(e->event) {
   216 	switch(e->event) {
   217 	case WE_PAINT:
   217 	case WE_PAINT:
   218 		FOR_ALL_PLAYERS(p) {
   218 		FOR_ALL_PLAYERS(p) {
   219 			if (!p->is_active)
   219 			if (!p->is_active)
   220 				SETBIT(_legend_showbits, p->index);
   220 				SETBIT(_legend_excludebits, p->index);
   221 		}
   221 		}
   222 		w->click_state = ((~_legend_showbits) << 3);
   222 		w->click_state = ((~_legend_excludebits) << 3);
   223 		DrawWindowWidgets(w);
   223 		DrawWindowWidgets(w);
   224 
   224 
   225 		FOR_ALL_PLAYERS(p) {
   225 		FOR_ALL_PLAYERS(p) {
   226 			if (!p->is_active)
   226 			if (!p->is_active)
   227 				continue;
   227 				continue;
   229 			DrawPlayerIcon(p->index, 4, 18+p->index*12);
   229 			DrawPlayerIcon(p->index, 4, 18+p->index*12);
   230 
   230 
   231 			SetDParam(0, p->name_1);
   231 			SetDParam(0, p->name_1);
   232 			SetDParam(1, p->name_2);
   232 			SetDParam(1, p->name_2);
   233 			SetDParam(2, GetPlayerNameString(p->index, 3));
   233 			SetDParam(2, GetPlayerNameString(p->index, 3));
   234 			DrawString(21,17+p->index*12,STR_7021,HASBIT(_legend_showbits, p->index) ? 0x10 : 0xC);
   234 			DrawString(21,17+p->index*12,STR_7021,HASBIT(_legend_excludebits, p->index) ? 0x10 : 0xC);
   235 		}
   235 		}
   236 		break;
   236 		break;
   237 
   237 
   238 	case WE_CLICK:
   238 	case WE_CLICK:
   239 		if (IS_INT_INSIDE(e->click.widget, 3, 11)) {
   239 		if (IS_INT_INSIDE(e->click.widget, 3, 11)) {
   240 			_legend_showbits ^= (1 << (e->click.widget-3));
   240 			_legend_excludebits ^= (1 << (e->click.widget-3));
   241 			SetWindowDirty(w);
   241 			SetWindowDirty(w);
   242 			InvalidateWindow(WC_INCOME_GRAPH, 0);
   242 			InvalidateWindow(WC_INCOME_GRAPH, 0);
   243 			InvalidateWindow(WC_OPERATING_PROFIT, 0);
   243 			InvalidateWindow(WC_OPERATING_PROFIT, 0);
   244 			InvalidateWindow(WC_DELIVERED_CARGO, 0);
   244 			InvalidateWindow(WC_DELIVERED_CARGO, 0);
   245 			InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
   245 			InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
   282 /********************/
   282 /********************/
   283 
   283 
   284 static void SetupGraphDrawerForPlayers(GraphDrawer *gd)
   284 static void SetupGraphDrawerForPlayers(GraphDrawer *gd)
   285 {
   285 {
   286 	Player *p;
   286 	Player *p;
   287 	uint showbits = _legend_showbits;
   287 	uint excludebits = _legend_excludebits;
   288 	int nums;
   288 	int nums;
   289 	int mo,yr;
   289 	int mo,yr;
   290 
   290 
   291 	// Exclude the players which aren't valid
   291 	// Exclude the players which aren't valid
   292 	FOR_ALL_PLAYERS(p) {
   292 	FOR_ALL_PLAYERS(p) {
   293 		if (!p->is_active) CLRBIT(showbits,p->index);
   293 		if (!p->is_active) SETBIT(excludebits,p->index);
   294 	}
   294 	}
   295 	gd->sel = showbits;
   295 	gd->sel = excludebits;
   296 	gd->num_vert_lines = 24;
   296 	gd->num_vert_lines = 24;
   297 
   297 
   298 	nums = 0;
   298 	nums = 0;
   299 	FOR_ALL_PLAYERS(p) {
   299 	FOR_ALL_PLAYERS(p) {
   300 		if (p->is_active) nums = max(nums,p->num_valid_stat_ent);
   300 		if (p->is_active) nums = max(nums,p->num_valid_stat_ent);
   332 		gd.color_2 = 0xD7;
   332 		gd.color_2 = 0xD7;
   333 		gd.bg_line_color = 0xE;
   333 		gd.bg_line_color = 0xE;
   334 
   334 
   335 		SetupGraphDrawerForPlayers(&gd);
   335 		SetupGraphDrawerForPlayers(&gd);
   336 
   336 
   337 		numd = 0;
   337 		numd = -1;
   338 		FOR_ALL_PLAYERS(p) {
   338 		FOR_ALL_PLAYERS(p) {
       
   339 			numd++;
   339 			if (!p->is_active)
   340 			if (!p->is_active)
   340 				continue;
   341 				continue;
   341 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   342 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   342 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   343 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   343 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses);
   344 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses);
   344 				i++;
   345 				i++;
   345 			}
   346 			}
   346 			numd++;
       
   347 		}
   347 		}
   348 		gd.num_dataset=numd;
   348 		gd.num_dataset=numd;
   349 
   349 
   350 		DrawGraph(&gd);
   350 		DrawGraph(&gd);
   351 	}	break;
   351 	}	break;
   375 
   375 
   376 void ShowOperatingProfitGraph()
   376 void ShowOperatingProfitGraph()
   377 {
   377 {
   378 	if (AllocateWindowDescFront(&_operating_profit_desc, 0)) {
   378 	if (AllocateWindowDescFront(&_operating_profit_desc, 0)) {
   379 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   379 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   380 		_legend_showbits = 0;
       
   381 	}
   380 	}
   382 }
   381 }
   383 
   382 
   384 
   383 
   385 /****************/
   384 /****************/
   405 		gd.color_3 = 0x10;
   404 		gd.color_3 = 0x10;
   406 		gd.color_2 = 0xD7;
   405 		gd.color_2 = 0xD7;
   407 		gd.bg_line_color = 0xE;
   406 		gd.bg_line_color = 0xE;
   408 		SetupGraphDrawerForPlayers(&gd);
   407 		SetupGraphDrawerForPlayers(&gd);
   409 
   408 
   410 		numd = 0;
   409 		numd = -1;
   411 		FOR_ALL_PLAYERS(p) {
   410 		FOR_ALL_PLAYERS(p) {
       
   411 			numd++;
   412 			if (!p->is_active)
   412 			if (!p->is_active)
   413 				continue;
   413 				continue;
   414 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   414 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   415 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   415 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   416 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income;
   416 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income;
   417 				i++;
   417 				i++;
   418 			}
   418 			}
   419 			numd++;
       
   420 		}
   419 		}
   421 
   420 
   422 		gd.num_dataset = numd;
   421 		gd.num_dataset = numd;
   423 
   422 
   424 		DrawGraph(&gd);
   423 		DrawGraph(&gd);
   450 
   449 
   451 void ShowIncomeGraph()
   450 void ShowIncomeGraph()
   452 {
   451 {
   453 	if (AllocateWindowDescFront(&_income_graph_desc, 0)) {
   452 	if (AllocateWindowDescFront(&_income_graph_desc, 0)) {
   454 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   453 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   455 		_legend_showbits = 0;
       
   456 	}
   454 	}
   457 }
   455 }
   458 
   456 
   459 /*******************/
   457 /*******************/
   460 /* DELIVERED CARGO */
   458 /* DELIVERED CARGO */
   479 		gd.color_3 = 0x10;
   477 		gd.color_3 = 0x10;
   480 		gd.color_2 = 0xD7;
   478 		gd.color_2 = 0xD7;
   481 		gd.bg_line_color = 0xE;
   479 		gd.bg_line_color = 0xE;
   482 		SetupGraphDrawerForPlayers(&gd);
   480 		SetupGraphDrawerForPlayers(&gd);
   483 
   481 
   484 		numd = 0;
   482 		numd = -1;
   485 		FOR_ALL_PLAYERS(p) {
   483 		FOR_ALL_PLAYERS(p) {
       
   484 			numd++;
   486 			if (!p->is_active)
   485 			if (!p->is_active)
   487 				continue;
   486 				continue;
   488 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   487 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   489 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   488 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   490 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo;
   489 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo;
   491 				i++;
   490 				i++;
   492 			}
   491 			}
   493 			numd++;
       
   494 		}
   492 		}
   495 
   493 
   496 		gd.num_dataset = numd;
   494 		gd.num_dataset = numd;
   497 
   495 
   498 		DrawGraph(&gd);
   496 		DrawGraph(&gd);
   524 
   522 
   525 void ShowDeliveredCargoGraph()
   523 void ShowDeliveredCargoGraph()
   526 {
   524 {
   527 	if (AllocateWindowDescFront(&_delivered_cargo_graph_desc, 0)) {
   525 	if (AllocateWindowDescFront(&_delivered_cargo_graph_desc, 0)) {
   528 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   526 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   529 		_legend_showbits = 0;
       
   530 	}
   527 	}
   531 }
   528 }
   532 
   529 
   533 /*****************************/
   530 /*****************************/
   534 /* PERFORMANCE RATING DETAIL */
   531 /* PERFORMANCE RATING DETAIL */
   773 		gd.color_3 = 0x10;
   770 		gd.color_3 = 0x10;
   774 		gd.color_2 = 0xD7;
   771 		gd.color_2 = 0xD7;
   775 		gd.bg_line_color = 0xE;
   772 		gd.bg_line_color = 0xE;
   776 		SetupGraphDrawerForPlayers(&gd);
   773 		SetupGraphDrawerForPlayers(&gd);
   777 
   774 
   778 		numd = 0;
   775 		numd = -1;
   779 		FOR_ALL_PLAYERS(p) {
   776 		FOR_ALL_PLAYERS(p) {
       
   777 			numd++;
   780 			if (!p->is_active)
   778 			if (!p->is_active)
   781 				continue;
   779 				continue;
   782 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   780 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   783 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   781 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   784 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history;
   782 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history;
   785 				i++;
   783 				i++;
   786 			}
   784 			}
   787 			numd++;
       
   788 		}
   785 		}
   789 		gd.num_dataset = numd;
   786 		gd.num_dataset = numd;
   790 
   787 
   791 		DrawGraph(&gd);
   788 		DrawGraph(&gd);
   792 		break;
   789 		break;
   820 
   817 
   821 void ShowPerformanceHistoryGraph()
   818 void ShowPerformanceHistoryGraph()
   822 {
   819 {
   823 	if (AllocateWindowDescFront(&_performance_history_desc, 0)) {
   820 	if (AllocateWindowDescFront(&_performance_history_desc, 0)) {
   824 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   821 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   825 		_legend_showbits = 0;
       
   826 	}
   822 	}
   827 }
   823 }
   828 
   824 
   829 /*****************/
   825 /*****************/
   830 /* COMPANY VALUE */
   826 /* COMPANY VALUE */
   849 		gd.color_3 = 0x10;
   845 		gd.color_3 = 0x10;
   850 		gd.color_2 = 0xD7;
   846 		gd.color_2 = 0xD7;
   851 		gd.bg_line_color = 0xE;
   847 		gd.bg_line_color = 0xE;
   852 		SetupGraphDrawerForPlayers(&gd);
   848 		SetupGraphDrawerForPlayers(&gd);
   853 
   849 
   854 		numd = 0;
   850 		numd = -1;
   855 		FOR_ALL_PLAYERS(p) {
   851 		FOR_ALL_PLAYERS(p) {
       
   852 			numd++;
   856 			if (!p->is_active)
   853 			if (!p->is_active)
   857 				continue;
   854 				continue;
   858 
   855 
   859 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   856 			gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   860 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   857 			for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   861 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value;
   858 				gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value;
   862 				i++;
   859 				i++;
   863 			}
   860 			}
   864 			numd++;
       
   865 		}
   861 		}
   866 		gd.num_dataset = numd;
   862 		gd.num_dataset = numd;
   867 
   863 
   868 
   864 
   869 		DrawGraph(&gd);
   865 		DrawGraph(&gd);
   895 
   891 
   896 void ShowCompanyValueGraph()
   892 void ShowCompanyValueGraph()
   897 {
   893 {
   898 	if (AllocateWindowDescFront(&_company_value_graph_desc, 0)) {
   894 	if (AllocateWindowDescFront(&_company_value_graph_desc, 0)) {
   899 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   895 		InvalidateWindow(WC_GRAPH_LEGEND, 0);
   900 		_legend_showbits = 0;
       
   901 	}
   896 	}
   902 }
   897 }
   903 
   898 
   904 /*****************/
   899 /*****************/
   905 /* PAYMENT RATES */
   900 /* PAYMENT RATES */