summaryrefslogtreecommitdiffstats
path: root/src/st/st-border-image.c
blob: ee09d0265022801865ea353eab7b53ed25910c4e (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
 * st-border-image.c: store information about an image with borders
 *
 * Copyright 2009, 2010 Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include <config.h>

#include <string.h>

#include "st-border-image.h"

struct _StBorderImage {
  GObject parent;

  GFile *file;
  int border_top;
  int border_right;
  int border_bottom;
  int border_left;

  int scale_factor;
};

struct _StBorderImageClass {
  GObjectClass parent_class;

};

G_DEFINE_TYPE (StBorderImage, st_border_image, G_TYPE_OBJECT)

static void
st_border_image_finalize (GObject *object)
{
  StBorderImage *image = ST_BORDER_IMAGE (object);

  g_object_unref (image->file);

  G_OBJECT_CLASS (st_border_image_parent_class)->finalize (object);
}

static void
st_border_image_class_init (StBorderImageClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = st_border_image_finalize;
}

static void
st_border_image_init (StBorderImage *image)
{
}

/**
 * st_border_image_new:
 * @file: a #GFile
 * @border_top: the top border
 * @border_right: the right border
 * @border_bottom: the bottom border
 * @border_left: the left border
 * @scale_factor: the scale factor
 *
 * Creates a new #StBorderImage.
 *
 * Returns: a new #StBorderImage.
 */
StBorderImage *
st_border_image_new (GFile *file,
                     int    border_top,
                     int    border_right,
                     int    border_bottom,
                     int    border_left,
                     int    scale_factor)
{
  StBorderImage *image;

  image = g_object_new (ST_TYPE_BORDER_IMAGE, NULL);

  image->file = g_object_ref (file);
  image->border_top = border_top;
  image->border_right = border_right;
  image->border_bottom = border_bottom;
  image->border_left = border_left;
  image->scale_factor = scale_factor;

  return image;
}

/**
 * st_border_image_get_file:
 * @image: a #StBorderImage
 *
 * Get the #GFile for @image.
 *
 * Returns: (transfer none): a #GFile
 */
GFile *
st_border_image_get_file (StBorderImage *image)
{
  g_return_val_if_fail (ST_IS_BORDER_IMAGE (image), NULL);

  return image->file;
}

/**
 * st_border_image_get_border:
 * @image: a #StBorderImage
 * @border_top: (out) (optional): the top border
 * @border_right: (out) (optional): the right border
 * @border_bottom: (out) (optional): the bottom border
 * @border_left: (out) (optional): the left border
 *
 * Get the border widths for @image, taking into account the scale factor
 * provided at construction.
 */
void
st_border_image_get_borders (StBorderImage *image,
                             int           *border_top,
                             int           *border_right,
                             int           *border_bottom,
                             int           *border_left)
{
  g_return_if_fail (ST_IS_BORDER_IMAGE (image));

  if (border_top)
    *border_top = image->border_top * image->scale_factor;
  if (border_right)
    *border_right = image->border_right * image->scale_factor;
  if (border_bottom)
    *border_bottom = image->border_bottom * image->scale_factor;
  if (border_left)
    *border_left = image->border_left * image->scale_factor;
}

/**
 * st_border_image_equal:
 * @image: a #StBorderImage
 * @other: a different #StBorderImage
 *
 * Check if two #StBorderImage objects are identical.
 *
 * Returns: %TRUE if the two border image objects are identical
 */
gboolean
st_border_image_equal (StBorderImage *image,
                       StBorderImage *other)
{
  g_return_val_if_fail (ST_IS_BORDER_IMAGE (image), FALSE);
  g_return_val_if_fail (ST_IS_BORDER_IMAGE (other), FALSE);

  return (image->border_top == other->border_top &&
          image->border_right == other->border_right &&
          image->border_bottom == other->border_bottom &&
          image->border_left == other->border_left &&
          g_file_equal (image->file, other->file));
}