Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_saui 4 #ifndef tools_saui 5 #define tools_saui 5 #define tools_saui 6 6 7 #include "args" 7 #include "args" 8 8 9 namespace tools { 9 namespace tools { 10 10 11 inline std::string gui_toolkit(args& a_args,bo 11 inline std::string gui_toolkit(args& a_args,bool a_rm_in_args){ 12 std::string driver; 12 std::string driver; 13 a_args.find("-toolkit",driver); 13 a_args.find("-toolkit",driver); 14 if(a_rm_in_args) a_args.remove("-toolkit"); 14 if(a_rm_in_args) a_args.remove("-toolkit"); 15 if(driver.empty()) { 15 if(driver.empty()) { 16 if(a_args.is_arg("-Xt")|| 16 if(a_args.is_arg("-Xt")|| 17 a_args.is_arg("-xt")|| 17 a_args.is_arg("-xt")|| 18 a_args.is_arg("-Xm")|| 18 a_args.is_arg("-Xm")|| 19 a_args.is_arg("-xm")|| 19 a_args.is_arg("-xm")|| 20 a_args.is_arg("-Motif")|| 20 a_args.is_arg("-Motif")|| 21 a_args.is_arg("-motif")) { 21 a_args.is_arg("-motif")) { 22 driver = "Xt"; 22 driver = "Xt"; 23 if(a_rm_in_args) { 23 if(a_rm_in_args) { 24 a_args.remove("-Xt"); 24 a_args.remove("-Xt"); 25 a_args.remove("-xt"); 25 a_args.remove("-xt"); 26 a_args.remove("-Xm"); 26 a_args.remove("-Xm"); 27 a_args.remove("-xm"); 27 a_args.remove("-xm"); 28 a_args.remove("-Motif"); 28 a_args.remove("-Motif"); 29 a_args.remove("-motif"); 29 a_args.remove("-motif"); 30 } 30 } 31 } else if(a_args.is_arg("-Win")|| 31 } else if(a_args.is_arg("-Win")|| 32 a_args.is_arg("-win")|| 32 a_args.is_arg("-win")|| 33 a_args.is_arg("-Win32")|| 33 a_args.is_arg("-Win32")|| 34 a_args.is_arg("-win32")) { 34 a_args.is_arg("-win32")) { 35 driver = "Win"; 35 driver = "Win"; 36 if(a_rm_in_args) { 36 if(a_rm_in_args) { 37 a_args.remove("-Win"); 37 a_args.remove("-Win"); 38 a_args.remove("-win"); 38 a_args.remove("-win"); 39 a_args.remove("-Win32"); 39 a_args.remove("-Win32"); 40 a_args.remove("-win32"); 40 a_args.remove("-win32"); 41 } 41 } 42 } else if(a_args.is_arg("-NextStep")|| 42 } else if(a_args.is_arg("-NextStep")|| 43 a_args.is_arg("-nextstep")) { 43 a_args.is_arg("-nextstep")) { 44 driver = "NextStep"; 44 driver = "NextStep"; 45 if(a_rm_in_args) { 45 if(a_rm_in_args) { 46 a_args.remove("-NextStep"); 46 a_args.remove("-NextStep"); 47 a_args.remove("-nextstep"); 47 a_args.remove("-nextstep"); 48 } 48 } 49 } else if(a_args.is_arg("-Gtk")|| 49 } else if(a_args.is_arg("-Gtk")|| 50 a_args.is_arg("-gtk")) { 50 a_args.is_arg("-gtk")) { 51 driver = "Gtk"; 51 driver = "Gtk"; 52 if(a_rm_in_args) { 52 if(a_rm_in_args) { 53 a_args.remove("-Gtk"); 53 a_args.remove("-Gtk"); 54 a_args.remove("-gtk"); 54 a_args.remove("-gtk"); 55 } 55 } 56 } else if(a_args.is_arg("-Qt")|| 56 } else if(a_args.is_arg("-Qt")|| 57 a_args.is_arg("-qt")) { 57 a_args.is_arg("-qt")) { 58 driver = "Qt"; 58 driver = "Qt"; 59 if(a_rm_in_args) { 59 if(a_rm_in_args) { 60 a_args.remove("-Qt"); 60 a_args.remove("-Qt"); 61 a_args.remove("-qt"); 61 a_args.remove("-qt"); 62 } 62 } 63 } else if(a_args.is_arg("-SDL")|| 63 } else if(a_args.is_arg("-SDL")|| 64 a_args.is_arg("-sdl")) { 64 a_args.is_arg("-sdl")) { 65 driver = "SDL"; 65 driver = "SDL"; 66 if(a_rm_in_args) { 66 if(a_rm_in_args) { 67 a_args.remove("-SDL"); 67 a_args.remove("-SDL"); 68 a_args.remove("-sdl"); 68 a_args.remove("-sdl"); 69 } 69 } 70 } else if(a_args.is_arg("-Net")|| 70 } else if(a_args.is_arg("-Net")|| 71 a_args.is_arg("-net")) { 71 a_args.is_arg("-net")) { 72 driver = "Net"; 72 driver = "Net"; 73 if(a_rm_in_args) { 73 if(a_rm_in_args) { 74 a_args.remove("-Net"); 74 a_args.remove("-Net"); 75 a_args.remove("-net"); 75 a_args.remove("-net"); 76 } 76 } 77 } else if(a_args.is_arg("-inex")) { 77 } else if(a_args.is_arg("-inex")) { 78 driver = "inex"; 78 driver = "inex"; 79 if(a_rm_in_args) { 79 if(a_rm_in_args) { 80 a_args.remove("-inex"); 80 a_args.remove("-inex"); 81 } 81 } 82 } 82 } 83 } 83 } 84 84 85 return driver; 85 return driver; 86 } 86 } 87 87 88 inline bool window_size_from_args(const args& 88 inline bool window_size_from_args(const args& a_args,unsigned int& a_ww,unsigned int& a_wh) { 89 // set a_ww,a_wh to some common window size 89 // set a_ww,a_wh to some common window size (in pixels). 90 // return true if a_ww,a_wh set from a_args, 90 // return true if a_ww,a_wh set from a_args, false if not. 91 bool status = true; 91 bool status = true; 92 if(a_args.is_arg("-iPod")||a_args.is_arg("-i 92 if(a_args.is_arg("-iPod")||a_args.is_arg("-iPhone")) { 93 a_ww = 320; 93 a_ww = 320; 94 a_wh = 480; 94 a_wh = 480; 95 } else if(a_args.is_arg("-iPad")) { 95 } else if(a_args.is_arg("-iPad")) { 96 a_ww = 768; 96 a_ww = 768; 97 a_wh = 1024; 97 a_wh = 1024; 98 } else if(a_args.is_arg("-iPhone4")) { 98 } else if(a_args.is_arg("-iPhone4")) { 99 a_ww = 640; 99 a_ww = 640; 100 a_wh = 960; 100 a_wh = 960; 101 } else if(a_args.is_arg("-wallino")) { //emu 101 } else if(a_args.is_arg("-wallino")) { //emulate LAL/wallino aspect ratio. 102 a_ww = 1024; 102 a_ww = 1024; 103 a_wh = 512; 103 a_wh = 512; 104 } else if(a_args.is_arg("-SGS")) { //Samsung 104 } else if(a_args.is_arg("-SGS")) { //Samsung Galaxy S 105 //a_ww = 320; 105 //a_ww = 320; 106 //a_wh = 533; 106 //a_wh = 533; 107 a_ww = 480; 107 a_ww = 480; 108 a_wh = 800; 108 a_wh = 800; 109 } else { 109 } else { 110 if(a_args.find<unsigned int>("-ww",a_ww)) 110 if(a_args.find<unsigned int>("-ww",a_ww)) { 111 if(a_args.find<unsigned int>("-wh",a_wh) 111 if(a_args.find<unsigned int>("-wh",a_wh)) return true; 112 //A4 : we have ww but not wh. Have wh in 112 //A4 : we have ww but not wh. Have wh in order to have A4 landscape : 113 a_wh = (unsigned int)(a_ww*(21.0f/29.7f) 113 a_wh = (unsigned int)(a_ww*(21.0f/29.7f)); //29.7/21 = 0.707 114 } else { //we don't have ww. 114 } else { //we don't have ww. 115 if(a_args.find<unsigned int>("-wh",a_wh) 115 if(a_args.find<unsigned int>("-wh",a_wh)) { 116 //A4 : we have wh but not ww. Have ww 116 //A4 : we have wh but not ww. Have ww in order to have A4 landscape : 117 a_ww = (unsigned int)(a_wh*(29.7f/21.0 117 a_ww = (unsigned int)(a_wh*(29.7f/21.0f)); 118 } else { 118 } else { 119 //we have nothing. Take a ww of 1000 a 119 //we have nothing. Take a ww of 1000 and wh (707) so that to have A4 landscape : 120 a_ww = 1000; 120 a_ww = 1000; 121 a_wh = (unsigned int)(a_ww*(21.0f/29.7 121 a_wh = (unsigned int)(a_ww*(21.0f/29.7f)); // have A4 landscape. 122 status = false; 122 status = false; 123 } 123 } 124 } 124 } 125 } 125 } 126 if(a_args.is_arg("-land")){ 126 if(a_args.is_arg("-land")){ 127 unsigned int _ww = a_ww; 127 unsigned int _ww = a_ww; 128 unsigned int _wh = a_wh; 128 unsigned int _wh = a_wh; 129 a_ww = mx(_ww,_wh); 129 a_ww = mx(_ww,_wh); 130 a_wh = mn(_ww,_wh); 130 a_wh = mn(_ww,_wh); 131 } 131 } 132 if(a_args.is_arg("-portrait")){ 132 if(a_args.is_arg("-portrait")){ 133 unsigned int _ww = a_ww; 133 unsigned int _ww = a_ww; 134 unsigned int _wh = a_wh; 134 unsigned int _wh = a_wh; 135 a_ww = mn(_ww,_wh); 135 a_ww = mn(_ww,_wh); 136 a_wh = mx(_ww,_wh); 136 a_wh = mx(_ww,_wh); 137 } 137 } 138 return status; 138 return status; 139 } 139 } 140 140 141 inline void remove_window_size_args(args& a_ar 141 inline void remove_window_size_args(args& a_args) { 142 //use with Wt apps. 142 //use with Wt apps. 143 a_args.remove("-iPod"); 143 a_args.remove("-iPod"); 144 a_args.remove("-iPhone"); 144 a_args.remove("-iPhone"); 145 a_args.remove("-iPad"); 145 a_args.remove("-iPad"); 146 a_args.remove("-iPhone4"); 146 a_args.remove("-iPhone4"); 147 a_args.remove("-SGS"); 147 a_args.remove("-SGS"); 148 a_args.remove("-ww"); 148 a_args.remove("-ww"); 149 a_args.remove("-wh"); 149 a_args.remove("-wh"); 150 a_args.remove("-land"); 150 a_args.remove("-land"); 151 } 151 } 152 152 153 } 153 } 154 154 155 #endif 155 #endif