summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
authorBrandon Schaefer <brandontschaefer@gmail.com>2014-02-07 13:50:15 -0800
committerBrandon Schaefer <brandontschaefer@gmail.com>2014-02-07 13:50:15 -0800
commite1fdd6feddcbbfdb0ccfefaf4c491a45f7766b38 (patch)
tree8f3b02359e267cca7e80c9df768249a824a23649 /unity-shared
parente161c04eabdd6bd4f67583bd920d223d475514a5 (diff)
* Add a RawPixel class, which has 2 defined literals (ex: 10_em, 10.0_em)
(bzr r3644.1.1)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/CMakeLists.txt1
-rw-r--r--unity-shared/EMConverter.cpp4
-rw-r--r--unity-shared/EMConverter.h4
-rw-r--r--unity-shared/RawPixel.cpp50
-rw-r--r--unity-shared/RawPixel.h48
5 files changed, 103 insertions, 4 deletions
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt
index 3cb758a84..a8aa6285a 100644
--- a/unity-shared/CMakeLists.txt
+++ b/unity-shared/CMakeLists.txt
@@ -50,6 +50,7 @@ set (UNITY_SHARED_SOURCES
PlacesOverlayVScrollBar.cpp
PreviewStyle.cpp
RatingsButton.cpp
+ RawPixel.cpp
ResizingBaseWindow.cpp
SearchBar.cpp
SearchBarSpinner.cpp
diff --git a/unity-shared/EMConverter.cpp b/unity-shared/EMConverter.cpp
index 42d50449a..e873729e0 100644
--- a/unity-shared/EMConverter.cpp
+++ b/unity-shared/EMConverter.cpp
@@ -86,7 +86,7 @@ double EMConverter::GetDPI() const
return dpi_;
}
-int EMConverter::EMToPixels(double em) const
+double EMConverter::EMToPixels(double em) const
{
return (em * pixels_per_em_);
}
@@ -96,7 +96,7 @@ double EMConverter::PixelsToBaseEM(int pixels) const
return (pixels / base_pixels_per_em_);
}
-int EMConverter::ConvertPixels(int pixels) const
+double EMConverter::ConvertPixels(int pixels) const
{
double pixels_em = PixelsToBaseEM(pixels);
return EMToPixels(pixels_em);
diff --git a/unity-shared/EMConverter.h b/unity-shared/EMConverter.h
index 0c5bc1b06..3231b028f 100644
--- a/unity-shared/EMConverter.h
+++ b/unity-shared/EMConverter.h
@@ -34,7 +34,7 @@ public:
int GetFontSize() const;
double GetDPI() const;
- int ConvertPixels(int pixels) const;
+ double ConvertPixels(int pixels) const;
double DPIScale() const;
double PtToPx(int pt);
@@ -43,7 +43,7 @@ private:
void UpdatePixelsPerEM();
void UpdateBasePixelsPerEM();
- int EMToPixels(double em) const;
+ double EMToPixels(double em) const;
double PixelsToBaseEM(int pixels) const;
double pixels_per_em_;
diff --git a/unity-shared/RawPixel.cpp b/unity-shared/RawPixel.cpp
new file mode 100644
index 000000000..a267eaf9f
--- /dev/null
+++ b/unity-shared/RawPixel.cpp
@@ -0,0 +1,50 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2014 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
+ */
+
+#include "RawPixel.h"
+
+namespace unity
+{
+
+RawPixel operator"" _em(long double pixel)
+{
+ return RawPixel(pixel);
+}
+
+RawPixel operator"" _em(unsigned long long pixel)
+{
+ return RawPixel(pixel);
+}
+
+RawPixel::RawPixel(float raw_pixel)
+ : raw_pixel_(raw_pixel)
+{
+}
+
+float RawPixel::CP(EMConverter const& converter) const
+{
+ return converter.ConvertPixels(raw_pixel_);
+}
+
+RawPixel::operator float() const
+{
+ return raw_pixel_;
+}
+
+} // namesapce unity
diff --git a/unity-shared/RawPixel.h b/unity-shared/RawPixel.h
new file mode 100644
index 000000000..77de270f8
--- /dev/null
+++ b/unity-shared/RawPixel.h
@@ -0,0 +1,48 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2014 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
+ */
+
+#ifndef RAW_PIXEL_H
+#define RAW_PIXEL_H
+
+#include "EMConverter.h"
+
+namespace unity
+{
+
+class RawPixel
+{
+public:
+ RawPixel(float raw_pixel);
+
+ float CP(EMConverter const& converter) const;
+
+ operator float() const;
+
+private:
+ float raw_pixel_;
+
+};
+
+// User-Defined Literals (ex: 10_em, 10.0_em)
+RawPixel operator"" _em(long double pixel);
+RawPixel operator"" _em(unsigned long long pixel);
+
+} // namespace unity
+
+#endif // RAW_PIXEL_H