[go: up one dir, main page]

File: dw.c

package info (click to toggle)
dillo 0.8.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,168 kB
  • ctags: 3,987
  • sloc: ansic: 32,778; sh: 3,401; makefile: 251; perl: 17
file content (107 lines) | stat: -rw-r--r-- 2,281 bytes parent folder | download | duplicates (2)
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
104
105
106
107
/*
 * Init and freeall, and some general functions.
 */

#include "dw.h"
#include "dw_style.h"
#include <gdk/gdk.h>
#include "debug.h"

GdkCursor *Dw_cursor_hand;

void a_Dw_init (void)
{
   DBG_OBJ_COLOR ("^Dw", "ffffe0");
   DBG_OBJ_COLOR ("^Gtk", "d0ffd0");

   a_Dw_style_init ();

   Dw_cursor_hand = gdk_cursor_new(GDK_HAND2);
}


void a_Dw_freeall (void)
{
   a_Dw_style_freeall ();

   gdk_cursor_destroy (Dw_cursor_hand);
}

/*
 * Return whether src1 and src2 intersect. If yes, return the intersection
 * rectangle in dest.
 *
 * The function has been copied from gdktrectangle.c
 */
gint p_Dw_rectangle_intersect (DwRectangle *src1,
                               DwRectangle *src2,
                               DwRectangle *dest)
{
   DwRectangle *temp;
   gint src1_x2, src1_y2;
   gint src2_x2, src2_y2;
   gint return_val;

   g_return_val_if_fail (src1 != NULL, FALSE);
   g_return_val_if_fail (src2 != NULL, FALSE);
   g_return_val_if_fail (dest != NULL, FALSE);

   return_val = FALSE;

   if (src2->x < src1->x) {
      temp = src1;
      src1 = src2;
      src2 = temp;
   }
   dest->x = src2->x;

   src1_x2 = src1->x + src1->width;
   src2_x2 = src2->x + src2->width;

   if (src2->x < src1_x2) {
      if (src1_x2 < src2_x2)
         dest->width = src1_x2 - dest->x;
      else
         dest->width = src2_x2 - dest->x;

      if (src2->y < src1->y) {
         temp = src1;
         src1 = src2;
         src2 = temp;
      }
      dest->y = src2->y;

      src1_y2 = src1->y + src1->height;
      src2_y2 = src2->y + src2->height;

      if (src2->y < src1_y2) {
         return_val = TRUE;

         if (src1_y2 < src2_y2)
            dest->height = src1_y2 - dest->y;
         else
            dest->height = src2_y2 - dest->y;

         if (dest->height == 0)
            return_val = FALSE;
         if (dest->width == 0)
            return_val = FALSE;
      }
   }

   return return_val;
}


/*
 * Return whether rect1 is a subset of rect2.
 */
gboolean p_Dw_rectangle_is_subset (DwRectangle *rect1,
                                   DwRectangle *rect2)
{
   return
      rect1->x >= rect2->x &&
      rect1->y >= rect2->y &&
      rect1->x + rect1->width <= rect2->x + rect2->width &&
      rect1->y + rect1->height <= rect2->y + rect2->height;
}