]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/Painter.C
Rename .C => .cpp for files in src/frontends/controllers, step 1
[lyx.git] / src / frontends / Painter.C
index 8d14ae3cf0c62a66da66c2c040fe58e35b43324b..845106188a1c99dce21788b115833725a9db67f0 100644 (file)
@@ -13,8 +13,6 @@
 
 #include "frontends/Painter.h"
 
-#include "frontends/Application.h"
-#include "frontends/FontLoader.h"
 #include "frontends/FontMetrics.h"
 
 #include "LColor.h"
@@ -28,27 +26,22 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
-void Painter::button(int x, int y, int w, int h)
+void Painter::button(int x, int y, int w, int h, bool mouseHover)
 {
-       fillRectangle(x, y, w, h, LColor::buttonbg);
+       if (mouseHover)
+               fillRectangle(x, y, w, h, LColor::buttonhoverbg);
+       else
+               fillRectangle(x, y, w, h, LColor::buttonbg);
        buttonFrame(x, y, w, h);
 }
 
 
 void Painter::buttonFrame(int x, int y, int w, int h)
 {
-       //  Width of a side of the button
-       int const d = 2;
-
-       fillRectangle(x, y, w, d, LColor::top);
-       fillRectangle(x, y + h - d, w, d, LColor::bottom);
-
-       for (int i = 0 ; i < d ; ++i) {
-               line(x + i, y + i,
-                    x + i, y + h - 1 - i, LColor::left);
-               line(x + w - 1 - i, y + i + 1,
-                    x + w - 1 - i, y + h - 1 - i, LColor::right);
-       }
+       line(x, y, x, y + h - 1, LColor::buttonframe);
+       line(x - 1 + w, y, x - 1 + w, y + h - 1, LColor::buttonframe);
+       line(x, y - 1, x - 1 + w, y - 1, LColor::buttonframe);
+       line(x, y + h - 1, x - 1 + w, y + h - 1, LColor::buttonframe);
 }
 
 
@@ -62,7 +55,7 @@ void Painter::rectText(int x, int y,
        int ascent;
        int descent;
 
-       FontMetrics const & fm = theApp->fontLoader().metrics(font);
+       FontMetrics const & fm = theFontMetrics(font);
        fm.rectText(str, width, ascent, descent);
 
        if (back != LColor::none)
@@ -76,23 +69,57 @@ void Painter::rectText(int x, int y,
 }
 
 
-void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & font)
+void Painter::buttonText(int x, int y, docstring const & str, 
+       LyXFont const & font, bool mouseHover)
 {
        int width;
        int ascent;
        int descent;
 
-       FontMetrics const & fm = theApp->fontLoader().metrics(font);
+       FontMetrics const & fm = theFontMetrics(font);
        fm.buttonText(str, width, ascent, descent);
 
-       button(x, y - ascent, width, descent + ascent);
-       text(x + 4, y, str, font);
+       button(x, y - ascent, width, descent + ascent, mouseHover);
+       text(x + 3, y - 1, str, font);
+}
+
+
+int Painter::preeditText(int x, int y, char_type c,
+       LyXFont const & font, preedit_style style)
+{
+       LyXFont temp_font = font;
+       FontMetrics const & fm = theFontMetrics(font);
+       int ascent = fm.maxAscent();
+       int descent = fm.maxDescent();
+       int height = ascent + descent;
+       int width = fm.width(c);
+
+       switch (style) {
+               case preedit_default:
+                       // default unselecting mode.
+                       fillRectangle(x, y - height + 1, width, height, LColor::background);
+                       dashedUnderline(font, x, y - descent + 1, width);
+                       break;
+               case preedit_selecting:
+                       // We are in selecting mode: white text on black background.
+                       fillRectangle(x, y - height + 1, width, height, LColor::black);
+                       temp_font.setColor(LColor::white);
+                       break;
+               case preedit_cursor:
+                       // The character comes with a cursor.
+                       fillRectangle(x, y - height + 1, width, height, LColor::background);
+                       underline(font, x, y - descent + 1, width);
+                       break;
+       }
+       text(x, y - descent + 1, c, temp_font);
+
+       return width;
 }
 
 
 void Painter::underline(LyXFont const & f, int x, int y, int width)
 {
-       FontMetrics const & fm = theApp->fontLoader().metrics(f);
+       FontMetrics const & fm = theFontMetrics(f);
 
        int const below = max(fm.maxDescent() / 2, 2);
        int const height = max((fm.maxDescent() / 4) - 1, 1);
@@ -103,5 +130,20 @@ void Painter::underline(LyXFont const & f, int x, int y, int width)
                fillRectangle(x, y + below, width, below + height, f.color());
 }
 
+
+void Painter::dashedUnderline(LyXFont const & f, int x, int y, int width)
+{
+       FontMetrics const & fm = theFontMetrics(f);
+
+       int const below = max(fm.maxDescent() / 2, 2);
+       int height = max((fm.maxDescent() / 4) - 1, 1);
+
+       if (height >= 2)
+               height += below;
+
+       for (int n = 0; n < height; ++n)
+               line(x, y + below + n, x + width, y + below + n, f.color(), line_onoffdash);
+}
+
 } // namespace frontend
 } // namespace lyx