summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/scoped_canvas.h
blob: 96ccaffa25d3a28c1f6d4b0295b5224afeeed224 (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
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_SCOPED_CANVAS_H_
#define UI_GFX_SCOPED_CANVAS_H_

#include "base/macros.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/gfx_export.h"

namespace gfx {

// Saves the drawing state, and restores the state when going out of scope.
class GFX_EXPORT ScopedCanvas {
 public:
  explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) {
    if (canvas_)
      canvas_->Save();
  }
  ~ScopedCanvas() {
    if (canvas_)
      canvas_->Restore();
  }

 private:
  gfx::Canvas* canvas_;

  DISALLOW_COPY_AND_ASSIGN(ScopedCanvas);
};

// Saves the drawing state.  If |flip| is true, and the UI is in RTL layout,
// applies a transform such that anything drawn inside the supplied width will
// be flipped horizontally.
class GFX_EXPORT ScopedRTLFlipCanvas {
 public:
  ScopedRTLFlipCanvas(gfx::Canvas* canvas, int width, bool flip = true);
  ~ScopedRTLFlipCanvas() {}

 private:
  ScopedCanvas canvas_;

  DISALLOW_COPY_AND_ASSIGN(ScopedRTLFlipCanvas);
};

}  // namespace gfx

#endif  // UI_GFX_SCOPED_CANVAS_H_