PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/IronHells/src/client/scene/video.c

#
C | 627 lines | 408 code | 120 blank | 99 comment | 24 complexity | 57efadad80796c94c068fb07e95a0237 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, Apache-2.0
  1. /* $Id: video.c 163 2003-11-05 06:15:01Z cipher $ */
  2. /*
  3. * Copyright (c) 2003 Paul A. Schifferer
  4. *
  5. * This software may be copied and distributed for educational, research,
  6. * and not for profit purposes provided that this copyright and statement
  7. * are included in all such copies. Other copyrights may also apply.
  8. */
  9. /* SDL headers */
  10. #include "SDL.h"
  11. /* Internal headers */
  12. #include "ironhells.h"
  13. #include "ipc.h"
  14. #include "strings.h"
  15. #include "scene/video.h"
  16. enum
  17. {
  18. IH_BUTTON_VIDEO_MODE,
  19. IH_BUTTON_VIDEO_HWACCEL,
  20. IH_BUTTON_VIDEO_FULLSCREEN,
  21. IH_BUTTON_VIDEO_DEPTH_LIST,
  22. IH_BUTTON_VIDEO_DEPTH_LIST_1,
  23. IH_BUTTON_VIDEO_DEPTH_LIST_2,
  24. IH_BUTTON_VIDEO_DEPTH_LIST_3,
  25. IH_BUTTON_VIDEO_DEPTH_LIST_4,
  26. IH_BUTTON_VIDEO_MODES_LIST,
  27. IH_BUTTON_VIDEO_MODES_LIST_1,
  28. IH_BUTTON_VIDEO_MODES_LIST_2,
  29. IH_BUTTON_VIDEO_MODES_LIST_3,
  30. IH_BUTTON_VIDEO_MODES_LIST_4,
  31. IH_BUTTON_VIDEO_MODES_LIST_5,
  32. IH_BUTTON_VIDEO_MODES_LIST_6,
  33. IH_BUTTON_VIDEO_MODES_LIST_7,
  34. IH_BUTTON_VIDEO_MODES_LIST_8,
  35. IH_BUTTON_VIDEO_MODES_LIST_9,
  36. IH_BUTTON_VIDEO_ACCEPT,
  37. IH_BUTTON_VIDEO_CANCEL,
  38. IH_BUTTON_VIDEO_END
  39. };
  40. #define IH_VIDEO_RESOLUTION_LIST_LINES 10
  41. #define IH_VIDEO_DEPTH_LIST_LINES 5
  42. static struct
  43. {
  44. struct
  45. {
  46. SDL_Rect dimensions;
  47. int depth;
  48. int engine;
  49. unsigned is_hw_accel:1;
  50. unsigned is_fullscreen:1;
  51. }
  52. selected;
  53. int selected_depth, selected_res;
  54. SceneButton buttons[IH_BUTTON_VIDEO_END];
  55. }
  56. scene_info;
  57. static char hw_accel_text[50];
  58. static char fullscreen_text[50];
  59. static char res_text[IH_VIDEO_RESOLUTION_LIST_LINES][20];
  60. static SDL_Rect mode_rect[IH_VIDEO_RESOLUTION_LIST_LINES];
  61. static char depth_text[IH_VIDEO_DEPTH_LIST_LINES][20];
  62. static char mode_text[35];
  63. static int depths[IH_VIDEO_DEPTH_LIST_LINES] = {
  64. 8,
  65. 15,
  66. 16,
  67. 24,
  68. 32
  69. };
  70. static int
  71. video_toggle_hwaccel(SceneButton * button)
  72. {
  73. int rc = 0;
  74. scene_info.selected.is_hw_accel = !scene_info.selected.is_hw_accel;
  75. return rc;
  76. }
  77. static int
  78. video_toggle_fullscreen(SceneButton * button)
  79. {
  80. int rc = 0;
  81. scene_info.selected.is_fullscreen =
  82. !scene_info.selected.is_fullscreen;
  83. return rc;
  84. }
  85. static int
  86. video_select_depth(SceneButton * button)
  87. {
  88. int rc = 0;
  89. int i;
  90. i = button->id - IH_BUTTON_VIDEO_DEPTH_LIST;
  91. scene_info.selected.depth = depths[i];
  92. scene_info.selected_depth = i;
  93. return rc;
  94. }
  95. static int
  96. video_select_resolution(SceneButton * button)
  97. {
  98. int rc = 0;
  99. int i;
  100. i = button->id - IH_BUTTON_VIDEO_MODES_LIST;
  101. memcpy(&scene_info.selected.dimensions, &mode_rect[i],
  102. sizeof(SDL_Rect));
  103. scene_info.selected_res = i;
  104. return rc;
  105. }
  106. static int
  107. video_accept(SceneButton * button)
  108. {
  109. int rc = 0;
  110. /* FIXME: Save the settings to disk.
  111. */
  112. /* Handle video mode changes, etc.
  113. */
  114. ih.display.desired_width = scene_info.selected.dimensions.w;
  115. ih.display.desired_height = scene_info.selected.dimensions.h;
  116. ih.display.depth = scene_info.selected.depth;
  117. ih.display.is_fullscreen = scene_info.selected.is_fullscreen;
  118. ih.display.is_hw_accel = scene_info.selected.is_hw_accel;
  119. // FIXME: modify screen
  120. /* Change the scene.
  121. */
  122. IH_SetScene(SCENE_SELECT_CHARACTER);
  123. return rc;
  124. }
  125. static int
  126. video_cancel(SceneButton * button)
  127. {
  128. int rc = 0;
  129. /* Change the scene.
  130. */
  131. IH_SetScene(SCENE_SELECT_CHARACTER);
  132. return rc;
  133. }
  134. void
  135. IH_InitScene_Video(void)
  136. {
  137. memset(&scene_info, 0, sizeof(scene_info));
  138. scene_info.selected.dimensions.w = ih.display.desired_width;
  139. scene_info.selected.dimensions.h = ih.display.desired_height;
  140. scene_info.selected.depth = ih.display.depth;
  141. scene_info.selected.is_fullscreen = ih.display.is_fullscreen;
  142. scene_info.selected.is_hw_accel = ih.display.is_hw_accel;
  143. }
  144. void
  145. IH_ProcessScene_Video(SDL_Event * event)
  146. {
  147. int i;
  148. for(i = 0; i < IH_BUTTON_VIDEO_END; i++)
  149. {
  150. SceneButton *button;
  151. button = &scene_info.buttons[i];
  152. button->hilite =
  153. button->selected ? IH_HILITE_SELECT : IH_HILITE_NORMAL;
  154. if(IH_IsPointerInRect
  155. (ih.display.mouse_x, ih.display.mouse_y, &button->rect))
  156. {
  157. /* Mark it as "hovered."
  158. */
  159. button->hilite = IH_HILITE_HOVER;
  160. /* Check for activation.
  161. */
  162. if(event->type == SDL_MOUSEBUTTONDOWN)
  163. {
  164. button->hilite = IH_HILITE_SELECT;
  165. /* Process its activation callback.
  166. */
  167. if(button->activate_func)
  168. (*button->activate_func) (&scene_info.buttons[i]);
  169. }
  170. }
  171. }
  172. }
  173. void
  174. IH_RenderScene_Video(void)
  175. {
  176. SDL_Rect res_rect, depth_rect;
  177. ihColor color;
  178. ihFontPos pos;
  179. SDL_Rect **modes;
  180. Uint32 flags = 0;
  181. int i, j, res_list_height, depth_list_height;
  182. /* Set up flags based on requested modes.
  183. */
  184. if(scene_info.selected.is_hw_accel)
  185. flags |= SDL_HWSURFACE;
  186. if(scene_info.selected.is_fullscreen)
  187. flags |= SDL_FULLSCREEN;
  188. switch (scene_info.selected.engine)
  189. {
  190. #ifdef BUILD_ISO_ENGINE
  191. case IH_DISPLAY_ENGINE_ISO:
  192. break;
  193. #endif
  194. #ifdef BUILD_3D_ENGINE
  195. case IH_DISPLAY_ENGINE_3D:
  196. flags |= SDL_OPENGL;
  197. break;
  198. #endif
  199. }
  200. /* Get available modes.
  201. */
  202. modes = SDL_ListModes(NULL, flags);
  203. for(i = 0; i < IH_VIDEO_RESOLUTION_LIST_LINES; i++)
  204. {
  205. res_text[i][0] = 0;
  206. memset(&mode_rect[i], 0, sizeof(SDL_Rect));
  207. }
  208. if(modes == (SDL_Rect **) 0)
  209. {
  210. /* No modes available.
  211. */
  212. }
  213. else if(modes == (SDL_Rect **) - 1)
  214. {
  215. i = 0;
  216. /* All modes available, so populate list with standard modes.
  217. */
  218. sprintf(res_text[i], "%dx%d", 800, 600);
  219. mode_rect[i].w = 800;
  220. mode_rect[i].h = 600;
  221. i++;
  222. sprintf(res_text[i], "%dx%d", 1024, 768);
  223. mode_rect[i].w = 1024;
  224. mode_rect[i].h = 768;
  225. i++;
  226. sprintf(res_text[i], "%dx%d", 1280, 1024);
  227. mode_rect[i].w = 1280;
  228. mode_rect[i].h = 1024;
  229. i++;
  230. sprintf(res_text[i], "%dx%d", 1600, 1200);
  231. mode_rect[i].w = 1600;
  232. mode_rect[i].h = 1200;
  233. i++;
  234. }
  235. else
  236. {
  237. for(i = 0, j = 0; modes[i]; i++)
  238. {
  239. if(i >= IH_VIDEO_RESOLUTION_LIST_LINES)
  240. break;
  241. if(modes[i]->w < 800 || modes[i]->h < 600)
  242. continue;
  243. sprintf(res_text[j], "%dx%d", modes[i]->w, modes[i]->h);
  244. memcpy(&mode_rect[j], modes[i], sizeof(SDL_Rect));
  245. }
  246. }
  247. for(i = 0; i < IH_VIDEO_DEPTH_LIST_LINES; i++)
  248. {
  249. sprintf(depth_text[i], "%d", depths[i]);
  250. }
  251. /* Draw the background.
  252. */
  253. IH_RenderBackground();
  254. /* Print the scene title.
  255. */
  256. pos.x.type = IH_POSITION_TYPE_PERCENT;
  257. pos.x.perc = .65;
  258. pos.y.type = IH_POSITION_TYPE_PERCENT;
  259. pos.y.perc = .2;
  260. IH_AttrToColor(COLOR_WHITE, &color);
  261. IH_RenderText(IH_FONT_LARGE,
  262. IH_TEXT_VIDEO_SETDISPLAY, &pos, &color, 0, NULL);
  263. /* Create a box for the screen dimensions.
  264. */
  265. pos.x.type = IH_POSITION_TYPE_PERCENT;
  266. pos.x.perc = .1;
  267. pos.y.type = IH_POSITION_TYPE_PERCENT;
  268. pos.y.perc = .1;
  269. IH_AttrToColor(COLOR_WHITE, &color);
  270. IH_RenderText(IH_FONT_LARGE,
  271. IH_TEXT_VIDEO_RESOLUTION, &pos, &color, 0, &res_rect);
  272. res_list_height = IH_GetFontHeight(IH_FONT_NORMAL) *
  273. IH_VIDEO_RESOLUTION_LIST_LINES + 6;
  274. IH_ShadeArea(res_rect.x, res_rect.y + res_rect.h + 5, 300,
  275. res_list_height, NULL);
  276. IH_FrameArea(res_rect.x, res_rect.y + res_rect.h + 5, 300,
  277. res_list_height, NULL);
  278. /* Create a box for the screen depths.
  279. */
  280. pos.x.type = IH_POSITION_TYPE_PERCENT;
  281. pos.x.perc = .1;
  282. pos.y.type = IH_POSITION_TYPE_PERCENT;
  283. pos.y.perc = .5;
  284. IH_AttrToColor(COLOR_WHITE, &color);
  285. IH_RenderText(IH_FONT_LARGE,
  286. IH_TEXT_VIDEO_DEPTH, &pos, &color, 0, &depth_rect);
  287. depth_list_height = IH_GetFontHeight(IH_FONT_NORMAL) *
  288. IH_VIDEO_DEPTH_LIST_LINES + 6;
  289. IH_ShadeArea(depth_rect.x, depth_rect.y + IH_FONT_LARGE_SIZE + 5, 300,
  290. depth_list_height, NULL);
  291. IH_FrameArea(depth_rect.x, depth_rect.y + IH_FONT_LARGE_SIZE + 5, 300,
  292. depth_list_height, NULL);
  293. /* Display the buttons and list items.
  294. */
  295. for(i = 0; i < IH_BUTTON_VIDEO_END; i++)
  296. {
  297. SceneButton *button;
  298. button = &scene_info.buttons[i];
  299. /* Check if the button needs to be initialized.
  300. */
  301. if(!button->init)
  302. {
  303. int init = FALSE;
  304. button->id = i;
  305. switch (i)
  306. {
  307. case IH_BUTTON_VIDEO_HWACCEL:
  308. /* Set position.
  309. */
  310. button->pos.x.type = IH_POSITION_TYPE_PERCENT;
  311. button->pos.x.perc = .1;
  312. button->pos.y.type = IH_POSITION_TYPE_PERCENT;
  313. button->pos.y.perc = .87;
  314. /* Set color.
  315. */
  316. IH_GetButtonColor(IH_HILITE_NORMAL,
  317. &button->color);
  318. /* Set the text.
  319. */
  320. sprintf(hw_accel_text, IH_TEXT_VIDEO_HWACCEL_FMT,
  321. scene_info.selected.
  322. is_hw_accel ? IH_TEXT_VIDEO_HWACCEL_ON :
  323. IH_TEXT_VIDEO_HWACCEL_OFF);
  324. button->font = IH_FONT_LARGE;
  325. button->text = hw_accel_text;
  326. /* Set the activation callback.
  327. */
  328. button->activate_func = video_toggle_hwaccel;
  329. init = TRUE;
  330. break;
  331. case IH_BUTTON_VIDEO_FULLSCREEN:
  332. /* Set position.
  333. */
  334. button->pos.x.type = IH_POSITION_TYPE_PERCENT;
  335. button->pos.x.perc = .1;
  336. button->pos.y.type = IH_POSITION_TYPE_PERCENT;
  337. button->pos.y.perc = .92;
  338. /* Set color.
  339. */
  340. IH_GetButtonColor(IH_HILITE_NORMAL,
  341. &button->color);
  342. /* Set the text.
  343. */
  344. sprintf(fullscreen_text,
  345. IH_TEXT_VIDEO_FULLSCREEN_FMT,
  346. scene_info.selected.
  347. is_fullscreen ?
  348. IH_TEXT_VIDEO_FULLSCREEN_ON :
  349. IH_TEXT_VIDEO_FULLSCREEN_OFF);
  350. button->font = IH_FONT_LARGE;
  351. button->text = fullscreen_text;
  352. /* Set the activation callback.
  353. */
  354. button->activate_func = video_toggle_fullscreen;
  355. init = TRUE;
  356. break;
  357. case IH_BUTTON_VIDEO_MODE:
  358. /* Set position.
  359. */
  360. button->pos.x.type = IH_POSITION_TYPE_PERCENT;
  361. button->pos.x.perc = .1;
  362. button->pos.y.type = IH_POSITION_TYPE_PERCENT;
  363. button->pos.y.perc = .82;
  364. /* Set the text.
  365. */
  366. button->font = IH_FONT_LARGE;
  367. button->text = mode_text;
  368. /* Set the activation callback.
  369. */
  370. button->activate_func = NULL;
  371. init = TRUE;
  372. break;
  373. case IH_BUTTON_VIDEO_ACCEPT:
  374. /* Set position.
  375. */
  376. button->pos.x.type = IH_POSITION_TYPE_PERCENT;
  377. button->pos.x.perc = .65;
  378. button->pos.y.type = IH_POSITION_TYPE_PERCENT;
  379. button->pos.y.perc = .9;
  380. /* Set color.
  381. */
  382. IH_GetButtonColor(IH_HILITE_NORMAL,
  383. &button->color);
  384. /* Set the text.
  385. */
  386. button->font = IH_FONT_LARGE;
  387. button->text = IH_TEXT_VIDEO_ACCEPT;
  388. /* Set the activation callback.
  389. */
  390. button->activate_func = video_accept;
  391. init = TRUE;
  392. break;
  393. case IH_BUTTON_VIDEO_CANCEL:
  394. /* Set position.
  395. */
  396. button->pos.x.type = IH_POSITION_TYPE_PERCENT;
  397. button->pos.x.perc = .65;
  398. button->pos.y.type = IH_POSITION_TYPE_PERCENT;
  399. button->pos.y.perc = .95;
  400. /* Set color.
  401. */
  402. IH_GetButtonColor(IH_HILITE_NORMAL,
  403. &button->color);
  404. /* Set the text.
  405. */
  406. button->font = IH_FONT_LARGE;
  407. button->text = IH_TEXT_VIDEO_CANCEL;
  408. /* Set the activation callback.
  409. */
  410. button->activate_func = video_cancel;
  411. init = TRUE;
  412. break;
  413. case IH_BUTTON_VIDEO_DEPTH_LIST:
  414. case IH_BUTTON_VIDEO_DEPTH_LIST_1:
  415. case IH_BUTTON_VIDEO_DEPTH_LIST_2:
  416. case IH_BUTTON_VIDEO_DEPTH_LIST_3:
  417. case IH_BUTTON_VIDEO_DEPTH_LIST_4:
  418. /* Set position.
  419. */
  420. button->pos.x.type = IH_POSITION_TYPE_PERCENT;
  421. button->pos.x.perc = .11;
  422. button->pos.y.type = IH_POSITION_TYPE_PIXEL;
  423. button->pos.y.pixel =
  424. depth_rect.y + depth_rect.h + 5 +
  425. ((i -
  426. IH_BUTTON_VIDEO_DEPTH_LIST) *
  427. IH_GetFontHeight(IH_FONT_NORMAL));
  428. IH_GetButtonColor(IH_HILITE_NORMAL,
  429. &button->color);
  430. /* Set the text.
  431. */
  432. button->font = IH_FONT_NORMAL;
  433. button->text =
  434. depth_text[i - IH_BUTTON_VIDEO_DEPTH_LIST];
  435. /* Set the activation callback.
  436. */
  437. button->activate_func = video_select_depth;
  438. init = TRUE;
  439. break;
  440. case IH_BUTTON_VIDEO_MODES_LIST:
  441. case IH_BUTTON_VIDEO_MODES_LIST_1:
  442. case IH_BUTTON_VIDEO_MODES_LIST_2:
  443. case IH_BUTTON_VIDEO_MODES_LIST_3:
  444. case IH_BUTTON_VIDEO_MODES_LIST_4:
  445. case IH_BUTTON_VIDEO_MODES_LIST_5:
  446. case IH_BUTTON_VIDEO_MODES_LIST_6:
  447. case IH_BUTTON_VIDEO_MODES_LIST_7:
  448. case IH_BUTTON_VIDEO_MODES_LIST_8:
  449. case IH_BUTTON_VIDEO_MODES_LIST_9:
  450. /* Set position.
  451. */
  452. button->pos.x.type = IH_POSITION_TYPE_PERCENT;
  453. button->pos.x.perc = .11;
  454. button->pos.y.type = IH_POSITION_TYPE_PIXEL;
  455. button->pos.y.pixel =
  456. res_rect.y + res_rect.h + 5 +
  457. ((i -
  458. IH_BUTTON_VIDEO_MODES_LIST) *
  459. IH_GetFontHeight(IH_FONT_NORMAL));
  460. IH_GetButtonColor(IH_HILITE_NORMAL,
  461. &button->color);
  462. /* Set the text.
  463. */
  464. button->font = IH_FONT_NORMAL;
  465. button->text =
  466. res_text[i - IH_BUTTON_VIDEO_MODES_LIST];
  467. /* Set the activation callback.
  468. */
  469. button->activate_func = video_select_resolution;
  470. init = TRUE;
  471. break;
  472. }
  473. /* Mark it initialized.
  474. */
  475. button->init = init;
  476. }
  477. if(!button->init)
  478. continue;
  479. /* Process any modifications to the button's visuals.
  480. */
  481. IH_GetButtonColor(IH_HILITE_NORMAL,
  482. &scene_info.buttons[IH_BUTTON_VIDEO_MODE].
  483. color);
  484. sprintf(mode_text, IH_TEXT_VIDEO_MODE_FMT,
  485. scene_info.selected.dimensions.w,
  486. scene_info.selected.dimensions.h,
  487. scene_info.selected.depth);
  488. sprintf(hw_accel_text, IH_TEXT_VIDEO_HWACCEL_FMT,
  489. scene_info.selected.
  490. is_hw_accel ? IH_TEXT_VIDEO_HWACCEL_ON :
  491. IH_TEXT_VIDEO_HWACCEL_OFF);
  492. sprintf(fullscreen_text, IH_TEXT_VIDEO_FULLSCREEN_FMT,
  493. scene_info.selected.
  494. is_fullscreen ? IH_TEXT_VIDEO_FULLSCREEN_ON :
  495. IH_TEXT_VIDEO_FULLSCREEN_OFF);
  496. IH_GetButtonColor(button->hilite, &button->color);
  497. if(button->selected)
  498. IH_AttrToColor(COLOR_YELLOW, &button->color);
  499. IH_RenderText(button->font,
  500. button->text,
  501. &button->pos, &button->color, 0, &button->rect);
  502. }
  503. }
  504. void
  505. IH_CleanupScene_Video(void)
  506. {
  507. }