summaryrefslogtreecommitdiffhomepage
path: root/Public/Developer/SystemLib/Sources/Wm.c
blob: 79eda22abea6e6e0885e4307ebedeff19be21c1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* -------------------------------------------

    Copyright Mahrouss Logic

------------------------------------------- */

#include <Headers/Wm.h>
#include <Headers/Math.h>

/// invalid resource handle, they always start from 1.
#define kInvalidRsrc (0U)

/// @brief Color refs.

const ColorRef kRgbRed = 0x000000FF;
const ColorRef kRgbGreen = 0x0000FF00;
const ColorRef kRgbBlue = 0x00FF0000;
const ColorRef kRgbBlack = 0x00000000;
const ColorRef kRgbWhite = 0xFFFFFFFF;

/////////////////////////////////////////////////////////////////////////

CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name,
                                       const DWordType rsrcId) {
  CA_MUST_PASS(name);
  CA_MUST_PASS(rsrcId != kInvalidRsrc);

  if (!name) return NullPtr;
  if (rsrcId == kInvalidRsrc) return NullPtr;

  return (WindowPort*)kSharedApplication->Invoke(
      kSharedApplication, kCallCreateWindow, name, rsrcId);
}

/////////////////////////////////////////////////////////////////////////

CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* winPort) {
  CA_MUST_PASS(winPort);
  if (!winPort) return;

  kSharedApplication->Invoke(kSharedApplication, kCallCloseWindow, winPort);
}

/////////////////////////////////////////////////////////////////////////

CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name,
                                     const DWordType rsrcId) {
  CA_MUST_PASS(name);
  CA_MUST_PASS(rsrcId != kInvalidRsrc);

  if (!name) return NullPtr;
  if (rsrcId == kInvalidRsrc) return NullPtr;

  return (WindowPort*)kSharedApplication->Invoke(kSharedApplication,
                                                 kCallCreateMenu, name, rsrcId);
}

/////////////////////////////////////////////////////////////////////////

CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* winPort) {
  CA_MUST_PASS(winPort);

  if (!winPort) return;
  kSharedApplication->Invoke(kSharedApplication, kCallCloseMenu, winPort);
}

/////////////////////////////////////////////////////////////////////////

CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* wndPort, WmPoint where) {
  if (!wndPort) return kWmErrInvalidArg;

  wndPort->windowPosition.X = where.X;
  wndPort->windowPosition.Y = where.Y;
  wndPort->windowMoving = True;

  return 0;
}

/// @brief Draws a blur effect on the window.
/// @param wndPort the window port.
CA_EXTERN_C VoidType WmBlur(WindowPort* wndPort) {
  if (wndPort != NullPtr) {
    WmGFXRef refGfx = wndPort->windowGfx;

    UInt32Type lookupTbl[4] = {0.21336, 0.41336, 0.61336, 0.81336};

    for (SizeType width = 0; width < refGfx->DataFrameWidth; ++width) {
      for (SizeType height = 0; height < refGfx->DataFrameHeight; ++height) {
        refGfx->DataFrame[width * height] =
            refGfx->DataFrame[width * height] * lookupTbl[MathRand() % 4];
      }
    }
  }
}

/// @brief Causes the window to invalidate and redraw.
/// @param wndPort The Window port.
/// @return nothing.
CA_EXTERN_C VoidType WmInvalidateGfx(WindowPort* wndPort) {
  if (wndPort) {
    wndPort->windowInvalidate = Yes;
  }
}