Design Pattern Examples
Overview of object-oriented design patterns
HandlerChain_WindowRectangle.c
Go to the documentation of this file.
1
7
8#include <stdbool.h>
9#include <stdlib.h>
10#include <stdio.h>
11
12#include "helpers/formatstring.h"
13
15
19const int MINIMUM_WIDTH = 4;
23const int MINIMUM_HEIGHT = 4;
24
25
27// WindowRectangle_Initialize()
29void WindowRectangle_Initialize(WindowRectangle* rectangle, int x, int y, int width, int height)
30{
31 if (rectangle != NULL)
32 {
33 if (width < MINIMUM_WIDTH)
34 {
35 width = MINIMUM_WIDTH;
36 }
37 if (height < MINIMUM_HEIGHT)
38 {
39 height = MINIMUM_HEIGHT;
40 }
41 rectangle->Left = x;
42 rectangle->Top = y;
43 rectangle->Right = x + width;
44 rectangle->Bottom = y + height;
45 }
46}
47
49// WindowRectangle_PointInside()
52{
53 bool isInside = false;
54 if (rectangle != NULL && point != NULL)
55 {
56
57 if (point->X >= rectangle->Left && point->X < rectangle->Right &&
58 point->Y >= rectangle->Top && point->Y < rectangle->Bottom)
59 {
60 isInside = true;
61 }
62
63 }
64 return isInside;
65}
66
68// WindowRectangle_ToString()
71{
72 bool success = false;
73
74 if (rectangle != NULL && output != NULL)
75 {
76 char *buffer = formatstring("x1=%2d, y1=%2d, x2=%2d, y2=%2d",
77 rectangle->Left, rectangle->Top, rectangle->Right, rectangle->Bottom);
78 if (buffer != NULL)
79 {
80 success = DynamicString_Append(output, buffer);
81 if (!success)
82 {
83 printf(" Error! Out of memory condition formatting a window's rectangle as a string in WindowRectangle_ToString()!\n");
84 }
85 free(buffer);
86 }
87 else
88 {
89 printf(" Error! Out of memory formatting window rectangle in WindowRectangle_ToString()!\n");
90 }
91 }
92
93 return success;
94}
bool WindowRectangle_ToString(WindowRectangle *rectangle, DynamicString *output)
Convert the given WindowRectangle to a string representation.
void WindowRectangle_Initialize(WindowRectangle *rectangle, int x, int y, int width, int height)
Initialize the specified WindowRectangle based on the given position and size in some arbitrary space...
const int MINIMUM_WIDTH
Minimum width of a window (to accommodate a close box).
bool WindowRectangle_PointInside(WindowRectangle *rectangle, MessagePosition *point)
Determine if the given WindowRectangle object contains the given MessagePosition.
const int MINIMUM_HEIGHT
Minimum height of a window (to accommodate a close box).
Declaration of the WindowRectangle structure and its support functions, WindowRectangle_Initialize(),...
bool DynamicString_Append(DynamicString *string, const char *s)
Append the specified string to the DynamicString object.
Definition: dynamicstring.c:39
char * formatstring(const char *format,...)
Use the given string and arguments to return a buffer containing the formatted string....
Definition: formatstring.c:15
Represents a string that can be grown dynamically.
Definition: dynamicstring.h:16
Position of the message in global coordinates (same scope of coordinates as windows)....
Represents a rectangular region, with upper left and lower right coordinates.