gfx2.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*--------------------------------------------------------------------------
  2. DEPUI-GFX-TK 3.0 - GPL portable source code libraries
  3. http://www.deleveld.dds.nl/depui.htm
  4. See file docs/copying for copyright details
  5. ---------------------------------------------------------------------------*/
  6. #define MXMODULE_BITLINE
  7. #define MXMODULE_LOADTGA
  8. #include "degfx/degfx.c"
  9. #include <time.h>
  10. int x, y, dx, dy;
  11. static MX_BITMAP *bitmap;
  12. static void draw(const MX_RECT * r)
  13. {
  14. /* Draw a background */
  15. mx_rectfill(r->x1, r->y1, r->x2, r->y2, MXCOLOR_lightskyblue3);
  16. /* Draw the bitmap on the screen */
  17. mx_blit(bitmap, 0, 0, x, y, MXDEFAULT, MXDEFAULT);
  18. }
  19. int main(int argc, char *argv[])
  20. {
  21. (void) argc;
  22. (void) argv;
  23. /* Start the graphic system */
  24. if (!mx_gfx_start(0))
  25. return 1;
  26. /* Load in the bitmap */
  27. bitmap = mx_bitmap_tga("title.tga");
  28. if (!bitmap)
  29. return 2;
  30. /* Start it in the upper left */
  31. x = 0;
  32. y = 0;
  33. dx = 1;
  34. dy = 1;
  35. /* Tell what the redraw funtion is */
  36. mx_gfx_redraw(draw);
  37. /* Main loop */
  38. while (mx_gfx_poll()) {
  39. MX_RECT rect;
  40. /* Get some screen info */
  41. const MX_GFX_ARGS *info = mx_gfx_info();
  42. const MX_RECT *screen = &info->screen;
  43. /* Move the pointer */
  44. mx_gfx_pointer(0, 0, 0);
  45. /* Exit when key is hit */
  46. if (mx_gfx_key(0, 0))
  47. break;
  48. /* Update where the bitmap was */
  49. rect = *MXRECT(bitmap);
  50. rect.x1 += x;
  51. rect.y1 += y;
  52. rect.x2 += x;
  53. rect.y2 += y;
  54. mx_gfx_dirty(&rect);
  55. /* Move the bitmap */
  56. x += dx;
  57. y += dy;
  58. /* Keep the bitmap on the screen */
  59. if (x < screen->x1)
  60. dx *= -1;
  61. if (x + mx_w(bitmap) > screen->x2)
  62. dx *= -1;
  63. if (y < screen->y1)
  64. dy *= -1;
  65. if (y + mx_h(bitmap) > screen->y2)
  66. dy *= -1;
  67. /* Update where the bitmap is now */
  68. rect = *MXRECT(bitmap);
  69. rect.x1 += x;
  70. rect.y1 += y;
  71. rect.x2 += x;
  72. rect.y2 += y;
  73. mx_gfx_dirty(&rect);
  74. }
  75. /* Free the bitmap */
  76. mx_delete(bitmap);
  77. return 0;
  78. }