PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/RELEASE-1_0A4/IronHells/src/client/displays/iso/scene/video.c

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