MPSetupArea.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. #define MPSETUP_CPP
  2. /*************************************************************************************************\
  3. MPSetupArea.cpp : Implementation of the MPSetupArea component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "MPSetupArea.h"
  9. #include "prefs.h"
  10. #include "IniFile.h"
  11. #include "../MCLib/UserInput.h"
  12. #include "..\resource.h"
  13. #ifndef GAMESOUND_H
  14. #include "gamesound.h"
  15. #endif
  16. #define CHECK_BUTTON 200
  17. static int connectionType = 0;
  18. static const int FIRST_BUTTON_ID = 1000010;
  19. static const int OK_BUTTON_ID = 1000001;
  20. static const int CANCEL_BUTTON_ID = 1000002;
  21. MPSetupXScreen::MPSetupXScreen()
  22. {
  23. bDone = 0;
  24. baseColor = 0xffff0000;
  25. stripeColor = 0xff00ff00;
  26. bPaintSchemeInitialized = false;
  27. ppConnectionScreen = 0;
  28. pLocalBrowserScreen = 0;
  29. pDirectTcpipScreen = 0;
  30. pModem2ModemScreen = 0;
  31. status = RUNNING;
  32. }
  33. MPSetupXScreen::~MPSetupXScreen()
  34. {
  35. }
  36. int MPSetupXScreen::indexOfButtonWithID(int id)
  37. {
  38. int i;
  39. for (i = 0; i < buttonCount; i++)
  40. {
  41. if (buttons[i].getID() == id)
  42. {
  43. return i;
  44. }
  45. }
  46. return -1;
  47. }
  48. void MPSetupXScreen::init(FitIniFile* file)
  49. {
  50. LogisticsScreen::init( *file, "Static", "Text", "Rect", "Button" );
  51. if ( buttonCount )
  52. {
  53. for ( int i = 0; i < buttonCount; i++ )
  54. {
  55. buttons[i].setMessageOnRelease();
  56. if (buttons[i].getID() == 0)
  57. {
  58. buttons[i].setID(FIRST_BUTTON_ID + i);
  59. }
  60. }
  61. }
  62. {
  63. char path[256];
  64. strcpy( path, artPath );
  65. strcat( path, "mcl_mp_setup_combobox0.fit" );
  66. FitIniFile PNfile;
  67. if ( NO_ERR != PNfile.open( path ) )
  68. {
  69. char error[256];
  70. sprintf( error, "couldn't open file %s", path );
  71. Assert( 0, 0, error );
  72. return;
  73. }
  74. playerNameComboBox.init(&PNfile, "PlayerNameComboBox");
  75. aStyle1TextListItem *pTmp2 = new aStyle1TextListItem;
  76. pTmp2->init(&PNfile, "Text0");
  77. playerNameComboBox.AddItem(pTmp2);
  78. pTmp2 = new aStyle1TextListItem;
  79. pTmp2->init(&PNfile, "Text1");
  80. playerNameComboBox.AddItem(pTmp2);
  81. }
  82. {
  83. char path[256];
  84. strcpy( path, artPath );
  85. strcat( path, "mcl_mp_setup_combobox1.fit" );
  86. FitIniFile PNfile;
  87. if ( NO_ERR != PNfile.open( path ) )
  88. {
  89. char error[256];
  90. sprintf( error, "couldn't open file %s", path );
  91. Assert( 0, 0, error );
  92. return;
  93. }
  94. unitNameComboBox.init(&PNfile, "UnitNameComboBox");
  95. }
  96. {
  97. char path[256];
  98. strcpy( path, artPath );
  99. strcat( path, "mcl_mp_setup_droplist0.fit" );
  100. FitIniFile PNfile;
  101. if ( NO_ERR != PNfile.open( path ) )
  102. {
  103. char error[256];
  104. sprintf( error, "couldn't open file %s", path );
  105. Assert( 0, 0, error );
  106. return;
  107. }
  108. insigniaDropList.init(&PNfile, "InsigniaDropList");
  109. PNfile.seekBlock( "ListItems" );
  110. long listItemCount = 0;
  111. PNfile.readIdLong( "ListItemCount", listItemCount );
  112. aInsigniaListItem *pTmp2;
  113. int i;
  114. for (i = 0; i < listItemCount; i += 1)
  115. {
  116. pTmp2 = new aInsigniaListItem;
  117. EString tmpStr;
  118. tmpStr.Format("ListItem%d", i);
  119. pTmp2->init(&PNfile, tmpStr.Data());
  120. insigniaDropList.AddItem(pTmp2);
  121. }
  122. insigniaDropList.SelectItem(0);
  123. }
  124. colorPicker.init(file, "ColorPicker");
  125. mechCamera.init(337, 297, 464, 512);
  126. /* these string are to be moved to the string table */
  127. if (1 <= textCount )
  128. {
  129. EString str = "MULTIPLAYER SETUP";
  130. textObjects[0].setText(str);
  131. }
  132. if (2 <= textCount )
  133. {
  134. EString str = "PLAYER NAME";
  135. textObjects[1].setText(str);
  136. }
  137. if (3 <= textCount )
  138. {
  139. EString str = "UNIT NAME";
  140. textObjects[2].setText(str);
  141. }
  142. if (4 <= textCount )
  143. {
  144. EString str = "UNIT INSIGNIA";
  145. textObjects[3].setText(str);
  146. }
  147. if (5 <= textCount )
  148. {
  149. EString str = "PLAYER COLORS";
  150. textObjects[4].setText(str);
  151. }
  152. if (6 <= textCount )
  153. {
  154. EString str = "HELP TEXT";
  155. textObjects[5].setText(str);
  156. }
  157. if (7 <= textCount )
  158. {
  159. EString str = "CONNECTION TYPE";
  160. textObjects[6].setText(str);
  161. }
  162. if (8 <= textCount )
  163. {
  164. EString str = "connection type info";
  165. textObjects[7].setText(str);
  166. }
  167. if (9 <= textCount )
  168. {
  169. EString str = "PLAYER NAME...";
  170. textObjects[8].setText(str);
  171. }
  172. if (10 <= textCount )
  173. {
  174. EString str = "UNIT NAME...";
  175. textObjects[9].setText(str);
  176. }
  177. if (11 <= textCount )
  178. {
  179. EString str = "INSIGNIA NAME...";
  180. textObjects[10].setText(str);
  181. }
  182. unitNameComboBox.setFocus( false );
  183. playerNameComboBox.setFocus( false );
  184. }
  185. void MPSetupXScreen::begin()
  186. {
  187. status = RUNNING;
  188. connectionType = 0;
  189. /* set button states */
  190. int buttonIndex;
  191. int buttonIndex2;
  192. int buttonIndex3;
  193. int buttonIndex4;
  194. buttonIndex = indexOfButtonWithID(FIRST_BUTTON_ID + 2);
  195. buttonIndex2 = indexOfButtonWithID(FIRST_BUTTON_ID + 3);
  196. buttonIndex3 = indexOfButtonWithID(FIRST_BUTTON_ID + 4);
  197. buttonIndex4 = indexOfButtonWithID(FIRST_BUTTON_ID + 5);
  198. if ((0 <= buttonIndex) && (0 <= buttonIndex2) && (0 <= buttonIndex3) && (0 <= buttonIndex4))
  199. {
  200. buttons[buttonIndex].press(!((1 == connectionType) || (2 == connectionType) || (3 == connectionType)));
  201. buttons[buttonIndex2].press(1 == connectionType);
  202. buttons[buttonIndex3].press(2 == connectionType);
  203. buttons[buttonIndex4].press(3 == connectionType);
  204. }
  205. colorPicker.setColor0(baseColor);
  206. colorPicker.setColor1(stripeColor);
  207. mechCamera.setMech("hunchback");
  208. bPaintSchemeInitialized = false;
  209. //mechCamera.getObjectAppearance()->resetPaintScheme(baseColor, stripeColor, 0xfff0f0f0);
  210. }
  211. void MPSetupXScreen::end()
  212. {
  213. mechCamera.setMech(NULL);
  214. }
  215. void MPSetupXScreen::render(int xOffset, int yOffset )
  216. {
  217. LogisticsScreen::render(xOffset, yOffset);
  218. if ((0 == xOffset) && (0 == yOffset))
  219. {
  220. colorPicker.render();
  221. mechCamera.render();
  222. if (!bPaintSchemeInitialized)
  223. {
  224. bPaintSchemeInitialized = true;
  225. mechCamera.getObjectAppearance()->resetPaintScheme(baseColor, stripeColor, 0xfff0f0f0);
  226. }
  227. /*combo boxes need to be rendered after anything they might obscure*/
  228. insigniaDropList.render();
  229. unitNameComboBox.render();
  230. playerNameComboBox.render();
  231. }
  232. }
  233. void MPSetupXScreen::render()
  234. {
  235. render(0, 0);
  236. }
  237. int MPSetupXScreen::handleMessage( unsigned long message, unsigned long who)
  238. {
  239. if ( RUNNING == status )
  240. {
  241. switch ( who )
  242. {
  243. case 50/*MB_MSG_NEXT*/:
  244. {
  245. switch (connectionType)
  246. {
  247. case 0/*internet*/:
  248. {
  249. (*ppConnectionScreen) = pLocalBrowserScreen;
  250. }
  251. break;
  252. case 1/*local browser*/:
  253. {
  254. (*ppConnectionScreen) = pLocalBrowserScreen;
  255. }
  256. break;
  257. case 2/*direct tcp/ip*/:
  258. {
  259. (*ppConnectionScreen) = pDirectTcpipScreen;
  260. }
  261. break;
  262. case 3/*modem2modem*/:
  263. {
  264. (*ppConnectionScreen) = pLocalBrowserScreen;
  265. }
  266. break;
  267. }
  268. getButton( 50/*MB_MSG_NEXT*/ )->press( 0 );
  269. status = NEXT;
  270. }
  271. break;
  272. case 57/*MB_MSG_MAINMENU*/:
  273. {
  274. getButton( 57/*MB_MSG_MAINMENU*/ )->press( 0 );
  275. status = MAINMENU;
  276. }
  277. break;
  278. case FIRST_BUTTON_ID+2:
  279. {
  280. getButton( FIRST_BUTTON_ID+2 )->press( 0 );
  281. connectionType = 0;
  282. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+2)].press(!((1 == connectionType) || (2 == connectionType) || (3 == connectionType)));
  283. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+3)].press(1 == connectionType);
  284. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+4)].press(2 == connectionType);
  285. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+5)].press(3 == connectionType);
  286. return 1;
  287. }
  288. break;
  289. case FIRST_BUTTON_ID+3:
  290. {
  291. connectionType = 1;
  292. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+2)].press(!((1 == connectionType) || (2 == connectionType) || (3 == connectionType)));
  293. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+3)].press(1 == connectionType);
  294. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+4)].press(2 == connectionType);
  295. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+5)].press(3 == connectionType);
  296. return 1;
  297. }
  298. break;
  299. case FIRST_BUTTON_ID+4:
  300. {
  301. connectionType = 2;
  302. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+2)].press(!((1 == connectionType) || (2 == connectionType) || (3 == connectionType)));
  303. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+3)].press(1 == connectionType);
  304. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+4)].press(2 == connectionType);
  305. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+5)].press(3 == connectionType);
  306. return 1;
  307. }
  308. break;
  309. case FIRST_BUTTON_ID+5:
  310. {
  311. connectionType = 3;
  312. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+2)].press(!((1 == connectionType) || (2 == connectionType) || (3 == connectionType)));
  313. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+3)].press(1 == connectionType);
  314. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+4)].press(2 == connectionType);
  315. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+5)].press(3 == connectionType);
  316. return 1;
  317. }
  318. break;
  319. }
  320. }
  321. return 0;
  322. }
  323. bool MPSetupXScreen::isDone()
  324. {
  325. return bDone;
  326. }
  327. void MPSetupXScreen::update()
  328. {
  329. LogisticsScreen::update();
  330. helpTextID = 0;
  331. helpTextHeaderID = 0;
  332. /*
  333. for ( int i = 0; i < buttonCount; i++ )
  334. {
  335. buttons[i].update();
  336. if ( buttons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() )
  337. && userInput->isLeftClick() )
  338. {
  339. handleMessage( buttons[i].getID(), buttons[i].getID() );
  340. }
  341. }
  342. */
  343. insigniaDropList.update();
  344. unitNameComboBox.update();
  345. playerNameComboBox.update();
  346. colorPicker.update();
  347. if ((colorPicker.getColor0() != baseColor) || (colorPicker.getColor1() != stripeColor)) {
  348. baseColor = colorPicker.getColor0();
  349. stripeColor = colorPicker.getColor1();
  350. mechCamera.getObjectAppearance()->resetPaintScheme(baseColor, stripeColor, 0xfff0f0f0);
  351. }
  352. mechCamera.update();
  353. if (userInput->isLeftClick()) {
  354. long mx = userInput->getMouseX();
  355. long my = userInput->getMouseY();
  356. if (playerNameComboBox.EditBox().pointInside(mx, my)) {
  357. playerNameComboBox.EditBox().setFocus(true);
  358. unitNameComboBox.EditBox().setFocus(false);
  359. } else if (unitNameComboBox.EditBox().pointInside(mx, my)) {
  360. playerNameComboBox.EditBox().setFocus(false);
  361. unitNameComboBox.EditBox().setFocus(true);
  362. }
  363. }
  364. }
  365. void MPSetupXScreen::updateMPSetup()
  366. {
  367. }
  368. aColorPicker::aColorPicker()
  369. {
  370. color0 = 0xffffffff;
  371. color1 = 0xff000000;
  372. activeTab = 0;
  373. }
  374. long aColorPicker::init(long xPos, long yPos,long w, long h )
  375. {
  376. long err;
  377. err = aObject::init(xPos,yPos,w,h);
  378. if (err)
  379. return err;
  380. addChild( &mainRect );
  381. addChild( &colorPlaneStatic );
  382. addChild( &intensityGradientRect );
  383. addChild( &intesitySliderScrollBar );
  384. addChild( &colorPlaneCursorStatic );
  385. addChild( &tab0Button );
  386. addChild( &tab0ColorRect );
  387. addChild( &tab0ColorOutlineRect );
  388. addChild( &tab0text );
  389. addChild( &tab1Button );
  390. addChild( &tab1ColorRect );
  391. addChild( &tab1ColorOutlineRect );
  392. addChild( &tab1text );
  393. return (NO_ERR);
  394. }
  395. void aColorPicker::init( FitIniFile* file, const char* blockName )
  396. {
  397. file->seekBlock(blockName);
  398. long x, y, width, height;
  399. file->readIdLong( "XLocation", x );
  400. file->readIdLong( "YLocation", y );
  401. file->readIdLong( "Width", width );
  402. file->readIdLong( "Height", height );
  403. init( x, y, width, height );
  404. EString blockname;
  405. blockname = "ColorPickerMainRect";
  406. mainRect.init( file, blockname.Data() );
  407. file->seekBlock( "ColorPickerTab0" );
  408. blockname = "Tab0Text";
  409. tab0text.init( file, blockname.Data() );
  410. {
  411. EString str = "BASE COLOR";
  412. tab0text.setText(str);
  413. }
  414. activeTab = 0;
  415. blockname = "Tab0ColorOutlineRect";
  416. tab0ColorOutlineRect.init( file, blockname.Data() );
  417. blockname = "Tab0ColorRect";
  418. tab0ColorRect.init( file, blockname.Data() );
  419. tab0ColorRect.setColor(color0);
  420. blockname = "Tab0Button";
  421. tab0Button.init( *file, blockname.Data() );
  422. tab0Button.press(true);
  423. file->seekBlock( "ColorPickerTab1" );
  424. blockname = "Tab1Text";
  425. tab1text.init( file, blockname.Data() );
  426. {
  427. EString str = "STRIPE COLOR";
  428. tab1text.setText(str);
  429. }
  430. blockname = "Tab1ColorOutlineRect";
  431. tab1ColorOutlineRect.init( file, blockname.Data() );
  432. blockname = "Tab1ColorRect";
  433. tab1ColorRect.init( file, blockname.Data() );
  434. tab1ColorRect.setColor(color1);
  435. blockname = "Tab1Button";
  436. tab1Button.init( *file, blockname.Data() );
  437. tab1Button.press(false);
  438. blockname = "ColorPickerCircleStatic";
  439. colorPlaneStatic.init( file, blockname.Data() );
  440. blockname = "ColorPickerValueGradient";
  441. intensityGradientRect.init( file, blockname.Data() );
  442. {
  443. blockname = "GradientSlider";
  444. long x, y, w, h;
  445. file->readIdLong("XLocation", x);
  446. file->readIdLong("YLocation", y);
  447. file->readIdLong("Width", w);
  448. file->readIdLong("Height", h);
  449. intesitySliderScrollBar.init( x, y, w, h );
  450. }
  451. blockname = "HueCirclePicker";
  452. colorPlaneCursorStatic.init( file, blockname.Data() );
  453. }
  454. void aColorPicker::destroy()
  455. {
  456. aObject::destroy();
  457. }
  458. static const float rhatx = 1.0; //cos(0/*degrees*/ * DEGREES_TO_RADS);
  459. static const float rhaty = 0.0; //sin(0/*degrees*/ * DEGREES_TO_RADS);
  460. static const float ghatx = -0.5; //cos(120/*degrees*/ * DEGREES_TO_RADS);
  461. static const float ghaty = 0.86602540378443864676372317075294f; //sin(120/*degrees*/ * DEGREES_TO_RADS);
  462. static const float bhatx = -0.5; //cos(240/*degrees*/ * DEGREES_TO_RADS);
  463. static const float bhaty = -0.86602540378443864676372317075294f; //sin(240/*degrees*/ * DEGREES_TO_RADS);
  464. static const float two_pi = 6.283185307179586476925286766559f;
  465. /* all params range from 0.0 to 1.0 */
  466. static void rgb2hsi(float r, float g, float b, float &hue, float &saturation, float &intensity)
  467. {
  468. intensity = (r + g + b) / 3.0;
  469. if (0.0 >= intensity) {
  470. saturation = 0.0;
  471. hue = 0.0;
  472. return;
  473. }
  474. float min = r;
  475. if (g < min) { min = g; }
  476. if (b < min) { min = b; }
  477. saturation = 1.0 - (min / intensity);
  478. float cx = r * rhatx + g * ghatx + b * bhatx;
  479. float cy = r * rhaty + g * ghaty + b * bhaty;
  480. hue = atan2(cy, cx);
  481. if (0.0 > hue) { hue += two_pi; }
  482. hue /= two_pi;
  483. }
  484. static void hsi2rgb(float hue, float saturation, float intensity, float &r, float &g, float &b)
  485. {
  486. float thue = hue;
  487. if ((1.0f / 3.0f) > hue) {
  488. } else if ((2.0f / 3.0f) > hue) {
  489. thue -= 1.0f / 3.0f;
  490. } else {
  491. thue -= 2.0f / 3.0f;
  492. }
  493. float chatx = cos(two_pi * thue);
  494. float chaty = sin(two_pi * thue);
  495. float ti = 3.0f * intensity;
  496. {
  497. b = (1.0f - saturation) * intensity;
  498. float tib = ti - b;
  499. float denominator = (chaty*(ghatx - rhatx) - chatx*(ghaty - rhaty));
  500. if (0.0f == denominator) {
  501. /* I suspect it's mathematically impossible to get here, but I'm too lazy to make sure. */
  502. denominator = 0.000001f;
  503. }
  504. g = ((b*bhaty + tib*rhaty)*chatx - (b*bhatx + tib*rhatx)*chaty) / denominator;
  505. r = tib - g;
  506. }
  507. if ((1.0f / 3.0f) > hue) {
  508. } else if ((2.0f / 3.0f) > hue) {
  509. float swap = b;
  510. b = g;
  511. g = r;
  512. r = swap;
  513. } else {
  514. float swap = b;
  515. b = r;
  516. r = g;
  517. g = swap;
  518. }
  519. }
  520. void aColorPicker::update()
  521. {
  522. aObject::update();
  523. if (userInput->isLeftClick() || userInput->isLeftDrag())
  524. {
  525. int cx = userInput->getMouseX();
  526. int cy = userInput->getMouseY();
  527. if (userInput->isLeftClick()) {
  528. if (tab0Button.pointInside(cx, cy)) {
  529. handleMessage(aMSG_BUTTONCLICKED, (unsigned long)(&tab0Button));
  530. } else if (tab1Button.pointInside(cx, cy)) {
  531. handleMessage(aMSG_BUTTONCLICKED, (unsigned long)(&tab1Button));
  532. }
  533. }
  534. if (colorPlaneStatic.pointInside(cx, cy)) {
  535. handleMessage(aMSG_LEFTMOUSEDOWN, (unsigned long)(&colorPlaneStatic));
  536. }
  537. }
  538. }
  539. int aColorPicker::handleMessage( unsigned long message, unsigned long who )
  540. {
  541. {
  542. if ((unsigned long)(&tab0Button) == who)
  543. {
  544. if (aMSG_BUTTONCLICKED == message)
  545. {
  546. tab0Button.press(true);
  547. tab1Button.press(false);
  548. activeTab = 0;
  549. return 1;
  550. }
  551. }
  552. else if ((unsigned long)(&tab1Button) == who)
  553. {
  554. if (aMSG_BUTTONCLICKED == message)
  555. {
  556. tab0Button.press(false);
  557. tab1Button.press(true);
  558. activeTab = 1;
  559. return 1;
  560. }
  561. }
  562. else if ((unsigned long)(&colorPlaneStatic) == who)
  563. {
  564. if ((aMSG_LEFTMOUSEDOWN == message)
  565. || ((aMSG_MOUSEMOVE == message) && (userInput->isLeftDrag())))
  566. {
  567. int cx = userInput->getMouseX();
  568. int cy = userInput->getMouseY();
  569. int colorPlaneRadius = 0.5 * colorPlaneStatic.width();
  570. int colorPlaneCenterX = colorPlaneStatic.x() + colorPlaneRadius;
  571. int colorPlaneCenterY = colorPlaneStatic.y() + colorPlaneRadius;
  572. float dx = cx - colorPlaneCenterX;
  573. float dy = cy - colorPlaneCenterY;
  574. int d2 = dx*dx + dy*dy;
  575. if ((colorPlaneRadius * colorPlaneRadius) > d2) {
  576. float saturation = sqrt((float)d2) / (float)colorPlaneRadius;
  577. float hue = (atan2(-dy, dx) / two_pi) + 0.5;
  578. float intensity = 0.99f;
  579. float R, G, B;
  580. hsi2rgb(hue, saturation, intensity, R, G, B);
  581. if (R > 0.99f) { R = 0.99f; }
  582. if (G > 0.99f) { G = 0.99f; }
  583. if (B > 0.99f) { B = 0.99f; }
  584. if (R < 0.0f) { R = 0.0f; }
  585. if (G < 0.0f) { G = 0.0f; }
  586. if (B < 0.0f) { B = 0.0f; }
  587. int newColor = 0xff000000 | (((int)(R * 255.0)) << 16) | (((int)(G * 255.0)) << 8)
  588. | (((int)(B * 255.0)) << 0);
  589. //if (tab0Button.isPressed()) {
  590. if (0 == activeTab) {
  591. setColor0(newColor);
  592. } else {
  593. setColor1(newColor);
  594. }
  595. }
  596. return 1;
  597. }
  598. }
  599. }
  600. return 0;
  601. }
  602. void aColorPicker::render()
  603. {
  604. aObject::render();
  605. }
  606. void aColorPicker::move( float offsetX, float offsetY )
  607. {
  608. aObject::move( offsetX, offsetY );
  609. }
  610. void aColorPicker::setColor0(int color)
  611. {
  612. color0 = color;
  613. tab0ColorRect.setColor(color);
  614. }
  615. void aColorPicker::setColor1(int color)
  616. {
  617. color1 = color;
  618. tab1ColorRect.setColor(color);
  619. }
  620. long aStyle1TextListItem::init( FitIniFile* file, const char* blockName )
  621. {
  622. file->seekBlock( blockName );
  623. long fontResID = 0;
  624. file->readIdLong( "Font", fontResID );
  625. long textID = 0;
  626. file->readIdLong( "TextID", textID );
  627. aTextListItem::init(fontResID);
  628. setText(textID);
  629. long color = 0xff808080;
  630. file->readIdLong( "Color", color );
  631. normalColor = color;
  632. setColor(color);
  633. char tmpStr[64];
  634. strcpy(tmpStr, "");
  635. file->readIdString( "Animation", tmpStr, 63 );
  636. if (0 == strcmp("", tmpStr))
  637. {
  638. hasAnimation = false;
  639. }
  640. else
  641. {
  642. hasAnimation = true;
  643. animGroup.init(file, tmpStr);
  644. }
  645. return 0;
  646. }
  647. void aStyle1TextListItem::render()
  648. {
  649. float color;
  650. if (aListItem::SELECTED == getState())
  651. {
  652. color = 0.33 * ((unsigned long)normalColor) + 0.67 * ((unsigned long)0xffffffff);
  653. }
  654. else if (aListItem::HIGHLITE == getState())
  655. {
  656. color = 0.67 * ((unsigned long)normalColor) + 0.33 * ((unsigned long)0xffffffff);
  657. }
  658. else
  659. {
  660. color = normalColor;
  661. }
  662. aTextListItem::setColor((unsigned long)color);
  663. aTextListItem::render();
  664. }
  665. long aInsigniaListItem::init( FitIniFile* file, const char* blockName )
  666. {
  667. file->seekBlock( blockName );
  668. long width, height;
  669. file->readIdLong( "Width", width );
  670. file->readIdLong( "Height", height );
  671. EString graphicBlockName = blockName;
  672. graphicBlockName += "Static";
  673. graphic.init(file, graphicBlockName.Data());
  674. if (graphic.height() > height)
  675. {
  676. height = graphic.height();
  677. }
  678. if (graphic.width() > width)
  679. {
  680. width = graphic.width();
  681. }
  682. EString textBlockName = blockName;
  683. textBlockName += "Text";
  684. text.init(file, textBlockName.Data());
  685. if (text.height() > height)
  686. {
  687. height = text.height();
  688. }
  689. if (graphic.width() + text.width() > width)
  690. {
  691. width = graphic.width() + text.width();
  692. }
  693. aObject::init(0, 0, width, height);
  694. addChild(&graphic);
  695. addChild(&text);
  696. text.move(graphic.width(), 0);
  697. return 0;
  698. }
  699. void aInsigniaListItem::update()
  700. {
  701. text.setState(getState());
  702. aListItem::update();
  703. }
  704. //////////////////////////////////////////////
  705. //*************************************************************************************************
  706. // end of file ( MPSetupArea.cpp )