OSDN Git Service

move calling GetColor from hexview to view
authorsuma <devnull@localhost>
Thu, 4 Dec 2008 07:46:28 +0000 (16:46 +0900)
committersuma <devnull@localhost>
Thu, 4 Dec 2008 07:46:28 +0000 (16:46 +0900)
src/control/color.h [new file with mode: 0644]
src/control/highlight.h
src/control/standard/hexview.cpp
src/control/standard/hexview.h
src/control/view.cpp
src/control/view.h

diff --git a/src/control/color.h b/src/control/color.h
new file mode 100644 (file)
index 0000000..9dcebac
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef COLOR_H_INC
+#define COLOR_H_INC
+
+namespace Color {
+       enum color {
+               Background = 0,
+               Text,
+               HiBackground,   // hilighted
+               HiSelText,
+               ColorCount,
+       };
+}
+
+
+#endif
index de63694..f1177fd 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <QColor>
 #include <vector>
-#include "view.h"
+#include "color.h"
 
 class Document;
 
index 76bdbd2..ce9d81d 100644 (file)
@@ -75,9 +75,8 @@ int HexConfig::toLine(int y)
 ////////////////////////////////////////
 // View
 HexView::HexView(QWidget *parent, Document *doc, Cursor *cur, Highlight *hi)
-       : ::View(parent, doc)
+       : ::View(parent, doc, hi)
        , cur_(cur)
-       , high_(hi)
 {
        setWindowOpacity(0.5);
 }
@@ -140,7 +139,7 @@ void HexView::refreshPixmap(int)
        doc_->get(top, &buff_[0], size);
 
        // Draw
-       DrawInfo di(y, top, yCount, xb, xe, sb, se, size);
+       ::DrawInfo di(y, top, yCount, xb, xe, sb, se, size, selected);
        if (selected) {
        } else {
        }
@@ -164,170 +163,6 @@ void HexView::refreshPixmap(int)
        update();
 }
 
-// x: [xb, xe)
-// y: [line, line_e)
-// line: line begin
-// line_e: line end
-// xb: x begin
-// xe: x end
-/*
-int y;
-int count;
-int xb;
-int xe;
-uint size;
-quint64 top;
-quint64 sb;
-quint64 se;
-std::vector<uchar> buff;
-*/
-void HexView::drawSelected(const DrawInfo &di)
-{
-       // 1. draw bakcground: selected/nonselected/hilighted
-
-       // 2. draw hex 
-
-       // -: nonselected
-       // o: selected
-       // case:
-       // a [-------]
-       // b [ooooooo]
-       // c [oooo---]
-       // d [---oooo]
-       // e [--ooo--]
-       /*
-       bool sel = false;
-       st = case()
-       swich (st) {
-       case a:
-               push(A)
-               if (sel) {
-                       RENZOKU
-               } else {
-                       A/D/E
-               }
-       case b: sel = true
-               // CHECK RENZOKU
-               // else A/C/D/E
-       case c: sel = true
-               // CHECK A
-       case d: sel = true
-               // CHECK B/C
-       case e: sel = true
-               // CHECK A
-       }
-*/
-
-       // o: selected
-       // -: nonselected
-       // case Y
-       //  [ooooooo]
-       //  [oooo---]
-       //  [---oooo]
-       //  [--ooo--]
-       // case X
-       //  [ooooooo] on
-       //  [oooo---] on + non
-       //  [---oooo] non + on
-       //  [--ooo--] non + on + non
-       //  [-------] nonselected
-
-}
-
-#ifdef HOGEHOGE_DEBUG
-struct ColorInfo {
-       quint64 Length;
-       Color[ColorCount]
-};
-
-struct DrawInfo {
-       // type: all, piece
-       int line;
-       int size;
-       QColor color[2];        // text and background
-}
-
-struct DrawHighlightInfo {
-       // type: all, piece
-       int line;
-       int size;
-       bool continuous;        // front of line
-       QColor color;
-};
-
-{
-       int y = config_.top();
-       const int yMax = height();
-       const int yCount = (height() - y + config_.byteHeight()) / config_.byteHeight();
-       quint64 top = cur_->Top * 16;
-       const int xb = 0, xe = width();
-       const uint size = min(doc_->length() - top, 16ULL * yCount);
-
-       bool selected = false;
-       quint64 sb = 0, se = 0;
-       if (cur_->Selected) {
-               sb = max(cur_->SelBegin, cur_->SelEnd);
-               se = min(cur_->SelBegin, cur_->SelEnd);
-               if (top <= se) {
-                       const quint64 vpos_end = max(top + (16ULL * yCount), top + size);
-                       if (sb <= vpos_end) {
-                               selected = true;
-                       }
-               }
-       }
-
-       if (!selected) {
-               // non selected
-               if (!high_->GetPosColor(buff_, top, size, colors_)) {
-                       DrawInfo di(ALL, y, lines, width_count);
-               } else {
-               }
-               return;
-       } else {
-               // selected
-               quint64 index = top;
-               if (high_ == NULL || !high_->GetPosColor(buff_, top, size, colors_)) {
-                       // case:
-                       // B only
-                       // B and W
-                       // W and B
-                       // W and B and W
-                       qint64 diff = sb - index;
-                       qint64 left = se - index;
-               } else {
-                       // check colors
-                       for (int i = 0, j = 0; i < lines; i++, j = (j+1) & 0xF, index++) {
-                               qint64 diff = sb - index;
-                               qint64 left = se - index;
-                               if (0 < diff && diff < 16) {
-                                       // begin after
-                               } else if (0 < left && left < 16) {
-                                       // end after
-                               } else if (diff <= 0 && left <= 0) {
-                                       // equal (sb <= index && index <= se)
-                                       // inner selected
-                               } else {
-                                       // normal
-                               }
-                       }
-               }
-       }
-}
-#endif
-
-void HexView::drawNonSelected(const DrawInfo &di)
-{
-       /*
-       Q_ASSERT(doc_->length() >= (top * 16));
-       const uint size = min(doc_->length() - top, 16ULL * count);
-       vector<uchar> buff(size);
-       doc_->get(top, &buff[0], size);
-       */
-
-       //for (int i = 0; i < count; i++) {
-       //}
-}
-
 void HexView::mousePressEvent(QMouseEvent*)
 {
 }
index d261bc7..8005481 100644 (file)
@@ -100,18 +100,10 @@ namespace Standard {
                };
 
 
-               void drawSelected(const DrawInfo &di);
-               void drawNonSelected(const DrawInfo &di);
-
        protected:
                // Main components
                HexConfig config_;
                Cursor *cur_;
-               Highlight *high_;
-       
-               // Temporary buffer
-               std::vector<uchar> buff_;
-               std::vector<ColorInfo> colors_;
        };
 
 }
index ef44c32..7c998eb 100644 (file)
@@ -3,9 +3,10 @@
 #include "view.h"
 #include "document.h"
 
-View::View(QWidget *parent, Document *doc)
+View::View(QWidget *parent, Document *doc, Highlight *hi)
        : QWidget(parent)
        , doc_(doc)
+       , high_(hi)
 {
 }
 
@@ -21,3 +22,70 @@ void View::resizeEvent(QResizeEvent *)
        refreshPixmap();
 }
 
+
+void View::getDrawColors(const DrawInfo &di, std::vector<ColorInfo> &ci)
+{
+       int y = di.y;
+       quint64 top = di.top;
+       const int sb = di.sb, se = di.se;
+       const uint size = di.size;
+
+       if (!di.selected) {
+               // non selected
+               if (high_ == NULL || !high_->GetColor(buff_, top, size, colors_)) {
+                       //DrawInfo di(ALL, y, lines, width_count);
+               } else {
+               }
+               return;
+       } else {
+               // selected
+               quint64 index = top;
+               if (high_ == NULL || !high_->GetColor(buff_, top, size, colors_)) {
+                       // case:
+                       // B only
+                       // B and W
+                       // W and B
+                       // W and B and W
+                       qint64 diff = sb - index;
+                       qint64 left = se - index;
+               } else {
+                       // check colors
+                       for (int i = 0; i < size; i++, index++) {
+                               qint64 diff = sb - index;
+                               qint64 left = se - index;
+                               if (0 < diff && diff < 16) {
+                                       // begin after
+                               } else if (0 < left && left < 16) {
+                                       // end after
+                               } else if (diff <= 0 && left <= 0) {
+                                       // equal (sb <= index && index <= se)
+                                       // inner selected
+                               } else {
+                                       // normal
+                               }
+                       }
+               }
+       }
+}
+#ifdef HOGEHOGE_DEBUG
+struct ColorInfo {
+       quint64 Length;
+       Color[ColorCount]
+};
+
+struct DrawInfo {
+       // type: all, piece
+       int line;
+       int size;
+       QColor color[2];        // text and background
+}
+
+struct DrawHighlightInfo {
+       // type: all, piece
+       int line;
+       int size;
+       bool continuous;        // front of line
+       QColor color;
+};
+
+#endif
index 3ae1d92..9e7738a 100644 (file)
@@ -2,19 +2,37 @@
 #define VIEW_H_INC
 
 #include <QWidget>
+#include <vector>
+#include "color.h"
+#include "highlight.h"
 
 class Document;
 
-namespace Color {
-       enum color {
-               Background = 0,
-               Text,
-               HiBackground,   // hilighted
-               HiSelText,
-               ColorCount,
-       };
-}
-
+struct DrawInfo {
+       int y;
+       int count;
+       int xb;
+       int xe;
+       uint size;
+       quint64 top;
+       quint64 sb;
+       quint64 se;
+       bool selected;
+       DrawInfo(int Y, quint64 Top, int Count, int Xb, int Xe, quint64 Sb, quint64 Se, uint Size, bool sel)
+       {
+               y = Y;
+               count = Count;
+               xb = Xb;
+               Xe = Xe;
+               size = Size;
+               top = Top;
+               sb = Sb;
+               se = Se;
+               selected = sel;
+       }
+       DrawInfo() {}
+       ~DrawInfo() {}
+};
 
 class View : public QWidget
 {
@@ -23,13 +41,19 @@ class View : public QWidget
 protected:
        Document *doc_;
        QPixmap pix_;
+       Highlight *high_;
+
+       // Temporary buffer
+       std::vector<uchar> buff_;
+       std::vector<ColorInfo> colors_;
 
 public:
-       View(QWidget *parent = 0, Document *doc = 0);
+       View(QWidget *parent = NULL, Document *doc = NULL, Highlight *hi = NULL);
 
 protected:
        void paintEvent(QPaintEvent*);
        void resizeEvent(QResizeEvent*);
+       void getDrawColors(const DrawInfo &di, std::vector<ColorInfo> &ci);
 
 protected:
        virtual void refreshPixmap() = 0;