コード例 #1
0
ファイル: c_hilit.cpp プロジェクト: OS2World/APP-EDITOR-fte
int EBuffer::HilitWord() {
    PELine L = VLine(CP.Row);
    char s[CK_MAXLEN + 2];
    int P, len = 0;
    
    P = CharOffset(L, CP.Col);
    while ((P > 0) && ((ChClass(L->Chars[P - 1]) == 1) || (L->Chars[P - 1] == '_'))) 
        P--;
    while (len < CK_MAXLEN && P < L->Count && (ChClass(L->Chars[P]) == 1 || L->Chars[P] == '_'))
        s[len++] = L->Chars[P++];
    if (len == 0)
        return 0;
    s[len] = 0;

    return (HilitFindWord(s)) ? HilitRemoveWord(s) : HilitAddWord(s);
}
コード例 #2
0
ファイル: e_search.cpp プロジェクト: AaronDP/efte_adbshell
int EBuffer::SearchWord(int SearchFlags) {
    char word[MAXSEARCH + 1];
    PELine L = VLine(CP.Row);
    int P, len = 0;
    int Case = BFI(this, BFI_MatchCase) ? 0 : SEARCH_NCASE;

    P = CharOffset(L, CP.Col);
    while ((P > 0) && ((ChClass(L->Chars[P - 1]) == 1) || (L->Chars[P - 1] == '_')))
        P--;
    while (len < int(sizeof(word)) && P < L->Count && (ChClass(L->Chars[P]) == 1 || L->Chars[P] == '_'))
        word[len++] = L->Chars[P++];
    word[len] = 0;
    if (len == 0)
        return 0;

    return FindStr(word, len, Case | SearchFlags | SEARCH_WORD);
}
コード例 #3
0
ファイル: e_cmds.cpp プロジェクト: dmcbride/efte
int EBuffer::MoveWordLeftX(int start) {
    if (CP.Col > 0) {
        int wS = start, wE = 1 - start;
        PELine L = VLine(CP.Row);
        int C, P;

        C = CP.Col;
        P = CharOffset(L, C);

        if (P > L->Count) P = L->Count;
        if (P > 0) {
            while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == wE)) P--;
            while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == wS)) P--;
            C = ScreenPos(L, P);
            return SetPos(C, CP.Row);
        } else return 0;
    } else return 0;
}
コード例 #4
0
ファイル: e_cmds.cpp プロジェクト: dmcbride/efte
int EBuffer::MoveWordOrCapEndLeft() {
    if (CP.Col > 0) {
        PELine L = VLine(CP.Row);
        int C, P;

        C = CP.Col;
        P = CharOffset(L, C);

        if (P > L->Count) P = L->Count;
        if (P > 0) {
            while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == 1) && (WGETBIT(Flags.CapitalChars, L->Chars[P - 1]) == 0)) P--;
            while ((P > 0) && (WGETBIT(Flags.CapitalChars, L->Chars[P - 1]) == 1)) P--;
            while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == 0)) P--;
            C = ScreenPos(L, P);
            return SetPos(C, CP.Row);
        } else return 0;
    } else return 0;
}
コード例 #5
0
ファイル: e_cmds.cpp プロジェクト: dmcbride/efte
int EBuffer::KillWordOrCap() {
    int Y = VToR(CP.Row);
    if (CP.Col >= LineLen()) {
        if (KillChar() == 0) return 0;
    } else {
        PELine L = VLine(CP.Row);
        int P = CharOffset(L, CP.Col);
        int C;
        int Class = ChClassK(L->Chars[P]);

        if (Class == 1) {
            if (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 1)
                while ((P < L->Count) && (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 1)) P++;
            while ((P < L->Count) && (WGETBIT(Flags.WordChars, L->Chars[P]) == 1) && (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 0)) P++;
        } else while ((P < L->Count) && (ChClassK(L->Chars[P]) == Class)) P++;
        C = ScreenPos(L, P);
        if (DelText(Y, CP.Col, C - CP.Col) == 0) return 0;
    }
    return 1;
}
コード例 #6
0
ファイル: e_search.cpp プロジェクト: AaronDP/efte_adbshell
int EBuffer::GetMatchBrace(EPoint &M, int MinLine, int MaxLine, int show) {
    int StateLen;
    hsState *StateMap = 0;
    int Pos;
    PELine L = VLine(M.Row);
    int dir = 0;
    hsState State;
    char Ch1, Ch2;
    int CountX = 0;
    int StateRow = -1;

    M.Row = VToR(CP.Row);

    Pos = CharOffset(L, M.Col);
    if (Pos >= L->Count) return 0;
    switch (L->Chars[Pos]) {
    case '{':
        dir = + 1;
        Ch1 = '{';
        Ch2 = '}';
        break;
    case '[':
        dir = + 1;
        Ch1 = '[';
        Ch2 = ']';
        break;
    case '<':
        dir = + 1;
        Ch1 = '<';
        Ch2 = '>';
        break;
    case '(':
        dir = + 1;
        Ch1 = '(';
        Ch2 = ')';
        break;
    case '}':
        dir = -1;
        Ch1 = '}';
        Ch2 = '{';
        break;
    case ']':
        dir = -1;
        Ch1 = ']';
        Ch2 = '[';
        break;
    case '>':
        dir = -1;
        Ch1 = '>';
        Ch2 = '<';
        break;
    case ')':
        dir = -1;
        Ch1 = ')';
        Ch2 = '(';
        break;
    default:
        return 0;
    }
    StateMap = 0;
    if (GetMap(M.Row, &StateLen, &StateMap) == 0) return 0;
    State = StateMap[Pos];
    StateRow = M.Row;

    while (M.Row >= MinLine && M.Row < MaxLine) {
        while (Pos >= 0 && Pos < L->Count) {
            if (L->Chars[Pos] == Ch1 || L->Chars[Pos] == Ch2) {
                // update syntax state if needed
                if (StateRow != M.Row) {
                    free(StateMap);
                    StateMap = 0;
                    GetMap(M.Row, &StateLen, &StateMap);
                    if (StateMap == 0) return 0;
                    StateRow = M.Row;
                }
                if (StateMap[Pos] == State) {
                    if (L->Chars[Pos] == Ch1) CountX++;
                    if (L->Chars[Pos] == Ch2) CountX--;
                    if (CountX == 0) {
                        M.Col = ScreenPos(L, Pos);
                        free(StateMap);
                        return 1;
                    }
                }
            }
            Pos += dir;
        }
        M.Row += dir;
        if (M.Row >= 0 && M.Row < RCount) {
            L = RLine(M.Row);
            Pos = (dir == 1) ? 0 : (L->Count - 1);
        }
    }
    if (StateMap) free(StateMap);
    if (show)
        Msg(S_INFO, "No match (%d missing).", CountX);
    return 0;
}
コード例 #7
0
ファイル: e_search.cpp プロジェクト: AaronDP/efte_adbshell
int EBuffer::ShowPosition() {
    int CLine, NLines;
    int CAct, NAct;
    int CColumn, NColumns;
    int CCharPos, NChars;
#ifdef HEAPWALK
    unsigned long MemUsed = 0, MemFree = 0, BlkUsed = 0, BlkFree = 0, BigFree = 0, BigUsed = 0;
#endif

    if (!View)
        return 0;

    CLine = CP.Row + 1;
    NLines = VCount;
    CAct = VToR(CP.Row) + 1;
    NAct = RCount;
    CColumn = CP.Col + 1;
    NColumns = LineLen(CP.Row);
    CCharPos = CharOffset(VLine(CP.Row), CP.Col) + 1;
    NChars = VLine(CP.Row)->Count;

#ifdef HEAPWALK
    if (_heapchk() != _HEAPOK) {
        MemUsed = -1;
    } else {
        _HEAPINFO hi;

        hi._pentry = NULL;
        while (_heapwalk(&hi) == _HEAPOK) {
            if (hi._useflag == _USEDENTRY) {
                BlkUsed++;
                MemUsed += hi._size;
                if (hi._size > BigUsed)
                    BigUsed = hi._size;
                //fprintf(stderr, "USED %d\n", hi._size);
            } else {
                BlkFree++;
                MemFree += hi._size;
                if (hi._size > BigFree)
                    BigFree = hi._size;
                //fprintf(stderr, "FREE %d\n", hi._size);
            }
        }
    }
#endif

    int NN = -1;
    if (US.UndoPtr > 0)
        NN = US.Top[US.UndoPtr - 1];
    Msg(S_INFO,
#ifdef HEAPWALK
        "M%ld,%ld B%ld,%ld S%ld,%ld"
#endif
        "L%d/%d G%d/%d/%d A%d/%d C%d/%d P%d/%d "
        "U%d/%d/%d "
        "H%d/%d/%d",
#ifdef HEAPWALK
        MemUsed, MemFree, BlkUsed, BlkFree, BigUsed, BigFree,
#endif
        CLine, NLines,
        RGap, RCount, RAllocated,
        CAct, NAct,
        CColumn, NColumns,
        CCharPos, NChars,
        US.UndoPtr, US.Num, NN,
        StartHilit, MinRedraw, MaxRedraw);
    return 1;
}
コード例 #8
0
ファイル: e_redraw.cpp プロジェクト: AaronDP/efte_adbshell
void EBuffer::Redraw() {
  int HilitX;
  EView *V;
  EEditPort *W;
  int Row;
  TDrawBuffer B;
  char s[256];
  ChColor SColor;
  int     RowA, RowZ;

  {
    int W1, H1;

    if (!(View && View->MView)) return;

    View->MView->ConQuerySize(&W1, &H1);

    if ((H1 < 1) || (W1 < 1)) return;
  }

  //    printf("Redraw\n");
  if (CP.Row >= VCount) CP.Row = VCount - 1;

  if (CP.Row < 0) CP.Row = 0;

  CheckBlock();
  V = View; /* check some window data */

  if (!V) {
    MinRedraw   = MaxRedraw = -1;
    RedrawToEos = 0;
    return;
  }

  if ((View == 0) || (View->MView == 0) || (View->MView->Win == 0)) return;

  for (; V; V = V->NextView) {
    //        printf("Checking\x7\n");
    if (V->Model != this) assert(1 == 0);

    W = GetViewVPort(V);

    if ((W->Rows < 1) || (W->Cols < 1)) continue;

    if (V == View) {
      int scrollJumpX   = Min(ScrollJumpX, W->Cols / 2);
      int scrollJumpY   = Min(ScrollJumpY, W->Rows / 2);
      int scrollBorderX = Min(ScrollBorderX, W->Cols / 2);
      int scrollBorderY = Min(ScrollBorderY, W->Rows / 2);

      W->CP = CP;
      TP    = W->TP;

      if (W->ReCenter) {
        W->TP.Row   = CP.Row - W->Rows / 2;
        W->TP.Col   = CP.Col - W->Cols + 8;
        W->ReCenter = 0;
      }

      if (W->TP.Row + scrollBorderY > CP.Row) W->TP.Row = CP.Row - scrollJumpY +
                                                          1 - scrollBorderY;

      if (W->TP.Row + W->Rows - scrollBorderY <= CP.Row) W->TP.Row = CP.Row -
                                                                     W->Rows +
                                                                     1 +
                                                                     scrollJumpY - 1 + scrollBorderY;

      if (!WeirdScroll) if (W->TP.Row + W->Rows >= VCount) W->TP.Row = VCount -
                                                                       W->Rows;

      if (W->TP.Row < 0) W->TP.Row = 0;

      if (W->TP.Col + scrollBorderX > CP.Col) W->TP.Col = CP.Col - scrollJumpX -
                                                          scrollBorderX;

      if (W->TP.Col + W->Cols - scrollBorderX <= CP.Col) W->TP.Col = CP.Col -
                                                                     W->Cols +
                                                                     scrollJumpX
                                                                     + scrollBorderX;

      if (W->TP.Col < 0) W->TP.Col = 0;

      if ((W->OldTP.Row != -1) && (W->OldTP.Col != -1) && (RedrawToEos == 0)) {
        if ((W->OldTP.Row != W->TP.Row) || (W->OldTP.Col != W->TP.Col)) {
          int A, B;
          int DeltaX, DeltaY;
          int Rows   = W->Rows;
          int Delta1 = 0, Delta2 = 0;

          DeltaY = W->TP.Row - W->OldTP.Row;
          DeltaX = W->TP.Col - W->OldTP.Col;

          if ((DeltaX == 0) && (-Rows < DeltaY) && (DeltaY < Rows)) {
            if (DeltaY < 0) {
              W->ScrollY(DeltaY);
              A = W->TP.Row;
              B = W->TP.Row - DeltaY;
            } else {
              W->ScrollY(DeltaY);
              A = W->TP.Row + Rows - DeltaY;
              B = W->TP.Row + Rows;
            }
          } else {
            A = W->TP.Row;
            B = W->TP.Row + W->Rows;
          }

          if (A >= VCount) {
            Delta1 = A - VCount + 1;
            A      = VCount - 1;
          }

          if (B >= VCount) {
            Delta2 = B - VCount + 1;
            B      = VCount - 1;
          }

          if (A < 0) A = 0;

          if (B < 0) B = 0;
          Draw(VToR(A) + Delta1, VToR(B) + Delta2);
        }
      } else {
        int A     = W->TP.Row;
        int B     = A + W->Rows;
        int Delta = 0;

        if (B > VCount) {
          Delta += B - VCount;
          B      = VCount;
        }
        int LastV = VToR(VCount - 1);
        int B1    = (B == VCount) ? RCount : VToR(B);

        if (B1 >= LastV) {
          Delta += B1 - LastV;
          B1     = LastV;
        }

        if (B1 < 0) B1 = 0;
          Draw(VToR(A), B1 + Delta);
      }

      W->OldTP = W->TP;
      TP       = W->TP;
    }

    if (W->CP.Row >= VCount) W->CP.Row = VCount - 1;

    if (W->CP.Row < 0) W->CP.Row = 0;

    if (W->TP.Row > W->CP.Row) W->TP.Row = W->CP.Row;

    if (W->TP.Row < 0) W->TP.Row = 0;

    if (V->MView->IsActive()) // hack
      SColor = hcStatus_Active;
    else SColor = hcStatus_Normal;
    MoveChar(B, 0, W->Cols, ' ', SColor, W->Cols);

    if (V->MView->Win->GetViewContext() == V->MView) {
      V->MView->Win->SetSbVPos(W->TP.Row, W->Rows, VCount +
                               (WeirdScroll ? W->Rows - 1 : 0));
      V->MView->Win->SetSbHPos(W->TP.Col, W->Cols, 1024 +
                               (WeirdScroll ? W->Cols - 1 : 0));
    }

    if (V->CurMsg == 0) {
      {
        int CurLine   = W->CP.Row;
        int ActLine   = VToR(W->CP.Row);
        int CurColumn = W->CP.Col;
        int CurPos    = CharOffset(RLine(ActLine), CurColumn);
        int NumLines  = RCount;
        int NumChars  = RLine(ActLine)->Count;

        //            int NumColumns = ScreenPos(Line(CurLine), NumChars);
        char *fName         = FileName;
        unsigned char CurCh = 0xFF;
        int  lf             = strlen(fName);
        char CCharStr[20]   = "";

        if (lf > 34) fName += lf - 34;

        if (CurPos < NumChars) {
          CurCh = VLine(CurLine)->Chars[CurPos];
          sprintf(CCharStr, "%3u,%02X", CurCh, CurCh);
        } else {
          if (CurPos > NumChars) strcpy(CCharStr, "      ");
          else if (CurLine < NumLines - 1) strcpy(CCharStr, "   EOL");
          else strcpy(CCharStr, "   EOF");
        }

          sprintf(s, "%04d:%02d (%04d:%02d) %c%c%c%c%c %.6s %c",

//                    CurLine + 1,
                ActLine + 1,
                CurColumn + 1,
                NumLines,
                NumChars,

//                    CurPos + 1,
                (BFI(this, BFI_Insert)) ? 'I' : ' ',
                (BFI(this, BFI_AutoIndent)) ? 'A' : ' ',

                //                    (BFI(this, BFI_ExpandTabs))?'T':' ',
                (BFI(this, BFI_MatchCase)) ? 'C' : ' ',
                AutoExtend ?
                (
                  (BlockMode == bmStream) ? 's' :
                  (BlockMode == bmLine) ? 'l' : 'c'
                ) :
                ((BlockMode == bmStream) ? 'S' :
                 (BlockMode == bmLine) ? 'L' : 'C'
                ),
                (BFI(this, BFI_WordWrap) == 3) ? 't' :
                (BFI(this, BFI_WordWrap) == 2) ? 'W' :
                (BFI(this, BFI_WordWrap) == 1) ? 'w' :
                ' ',

//                    (BFI(this, BFI_Undo))?'U':' ',
//                    (BFI(this, BFI_Trim))?'E':' ',
//                    (Flags.KeepBackups)?'B':' ',
                Mode->fName,
                (Modified != 0) ? '*' : (BFI(this, BFI_ReadOnly)) ? '%' : ' '
                );

        int  l  = strlen(s);
        int  fw = W->Cols - l;
        int  fl = strlen(FileName);
        char num[32];

        MoveStr(B, 0, W->Cols, s, SColor, W->Cols);
        sprintf(num, " %s %d", CCharStr, ModelNo);
          MoveStr(B, W->Cols - strlen(num), W->Cols, num, SColor, W->Cols);

        fw -= strlen(num);

        if (fl > fw) {
          MoveStr(B, l, W->Cols, FileName + fl - fw, SColor, W->Cols);
        } else {
          MoveStr(B, l, W->Cols, FileName,           SColor, W->Cols);
        }
      }
    } else {
          MoveStr(B, 0, W->Cols, V->CurMsg, SColor, W->Cols);
    }

    if (V->MView->Win->GetStatusContext() == V->MView) {
      V->MView->ConPutBox(0, W->Rows, W->Cols, 1, B);

      if (V->MView->IsActive()) {
        V->MView->ConSetCursorPos(W->CP.Col - W->TP.Col, W->CP.Row - W->TP.Row);
        V->MView->ConSetInsertState(BFI(this, BFI_Insert));
        V->MView->ConShowCursor();
      }
    }
  }

  Rehilit(VToR(CP.Row));

  if (BFI(this, BFI_AutoHilitParen) == 1) {
    if ((Match.Row == -1) && (Match.Col == -1)) HilitMatchBracket();
  }

  //    if ((Window == WW) && (MinRedraw == -1))
  //        MaxRedraw = MinRedraw = VToR(CP.Row);

  // printf("\n\nMinRedraw = %d, MaxRedraw = %d", MinRedraw, MaxRedraw);
  if (MinRedraw == -1) return;

  //    printf("Will redraw: %d to %d, to eos = %d\n", MinRedraw, MaxRedraw,
  // RedrawToEos);
  if (MinRedraw >= VCount) MinRedraw = VCount - 1;

  if (MinRedraw < 0) MinRedraw = 0;

  //    puts("xxx\x7");
  //    printf("%d\n", MinRedraw);
  Row = RowA = RToVN(MinRedraw);

  //    puts("xxx\x7");
  RowZ = MaxRedraw;

  if (MaxRedraw != -1) {
    int Delta = 0;

    if (MaxRedraw >= RCount) {
      Delta     = MaxRedraw - RCount + 1;
      MaxRedraw = RCount - 1;
    }

    if (MaxRedraw < 0) MaxRedraw = 0;

    //        printf("%d\n", MaxRedraw);
    RowZ = RToVN(MaxRedraw) + Delta;
  }

  //    puts("xxx\x7");
  // printf("\nRowA = %d, RowZ = %d", RowA, RowZ);

  V = View;

  while (V) {
    if (V->Model != this) assert(1 == 0);

    W = GetViewVPort(V);

    for (int R = W->TP.Row; R < W->TP.Row + W->Rows; R++) {
      Row = R;

      if ((Row >= RowA) &&
          (RedrawToEos || (Row <= RowZ))) {
        DrawLine(B, Row, W->TP.Col, W->Cols, HilitX);
        W->DrawLine(Row, B);

        if (HilitX && (Row == RowZ)) RowZ++;
      }
    }
    V = V->NextView;
  }
  MinRedraw   = MaxRedraw = -1;
  RedrawToEos = 0;
}
コード例 #9
0
void TFT_ILI9163C::drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1, uint16_t color){
	if (y0 == y1) {
		if (x1 > x0) {
			drawFastHLine(x0, y0, x1 - x0 + 1, color);
		} else if (x1 < x0) {
			drawFastHLine(x1, y0, x0 - x1 + 1, color);
		} else {
			drawPixel(x0, y0, color);
		}
		return;
	} else if (x0 == x1) {
		if (y1 > y0) {
			drawFastVLine(x0, y0, y1 - y0 + 1, color);
		} else {
			drawFastVLine(x0, y1, y0 - y1 + 1, color);
		}
		return;
	}

	bool steep = abs(y1 - y0) > abs(x1 - x0);
	if (steep) {
		swap(x0, y0);
		swap(x1, y1);
	}
	if (x0 > x1) {
		swap(x0, x1);
		swap(y0, y1);
	}

	int16_t dx, dy;
	dx = x1 - x0;
	dy = abs(y1 - y0);

	int16_t err = dx / 2;
	int16_t ystep;

	if (y0 < y1) {
		ystep = 1;
	} else {
		ystep = -1;
	}

	SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
	int16_t xbegin = x0;
	if (steep) {
		for (; x0<=x1; x0++) {
			err -= dy;
			if (err < 0) {
				int16_t len = x0 - xbegin;
				if (len) {
					VLine(y0, xbegin, len + 1, color);
				} else {
					Pixel(y0, x0, color);
				}
				xbegin = x0 + 1;
				y0 += ystep;
				err += dx;
			}
		}
		if (x0 > xbegin + 1) {
			VLine(y0, xbegin, x0 - xbegin, color);
		}

	} else {
		for (; x0<=x1; x0++) {
			err -= dy;
			if (err < 0) {
				int16_t len = x0 - xbegin;
				if (len) {
					HLine(xbegin, y0, len + 1, color);
				} else {
					Pixel(x0, y0, color);
				}
				xbegin = x0 + 1;
				y0 += ystep;
				err += dx;
			}
		}
		if (x0 > xbegin + 1) {
			HLine(xbegin, y0, x0 - xbegin, color);
		}
	}
	writecommand_last(CMD_NOP);
	SPI.endTransaction();
}
コード例 #10
0
ファイル: graph.cpp プロジェクト: andyfriesen/ika
void CGraphView::AlphaBlit(const Canvas& src,int x,int y)
{
    const int bpp=4;
    
    int nDestwidth=pDib->Width();
    int nDestheight=pDib->Height();
    
    int xstart=0;
    int ystart=0;
    int xlen=src.Width();
    int ylen=src.Height();
    int ox=x;
    int oy=y;
    
    DoClipping(x,y,xstart,xlen,ystart,ylen);
    
    if (xlen<1 || ylen<1)   return; // offscreen
    
    u32* pDest=(u32*)(pDib->GetPixels())+(y*nDestwidth+x);
    u32* pSrc =(u32*)src.GetPixels() +(ystart*src.Width()+xstart);
    
    while (ylen)
    {
        int x=xlen;
        while (x)
        {
            // convert from ARGB to ABGR
            /*
            u32 c=*pSrc++;
            u8 r=(u8)((c>>16)&255);
            u8 b=(u8)(c&255);
            c&=0xFF00FF00;                              // the alpha and green channels don't move, keep them intact                        
            *pDest++=c|(b<<16)|r;
            /*/
            // Did I need to convert this to ASM?  Doubt it. ;D
            __asm
            {
                mov     ebx,[pSrc]
                mov     eax,[ebx]
                
                test    eax,0xFF000000
                jz      nodraw
                
                mov     ebx,[pDest]
                mov     [ebx],eax
                
                mov     al,[ebx]
                mov     ah,[ebx+2]
                mov     [ebx],ah                        // have to switch from BGRA to RGBA
                mov     [ebx+2],al
                
    nodraw:
            }
            ++pSrc; ++pDest;
            //*/
            x--;
        }
        pDest+=nDestwidth-xlen;
        pSrc+=src.Width()-xlen;
        --ylen;
    }
}

void CGraphView::HLine(int x1,int x2,int y,u32 colour)
{
    if (x1>x2)
    std::swap<int>(x1,x2);
    
    if (y<0 || y>=nDIBsize) return;
    if (x1<0)               x1=0;
    if (x2<0)               return;
    if (x1>=nDIBsize)       return;
    if (x2>=nDIBsize)       x2=nDIBsize-1;
    
    u32* p=(u32*)pDib->GetPixels()+(y*pDib->Width())+x1;
    int xlen=x2-x1+1;
    
    while (xlen--)
        *p++=colour;
}

void CGraphView::VLine(int x,int y1,int y2,u32 colour)
{
    if (y1>y2)
    std::swap<int>(y1,y2);
    
    if (x<0 || x>=nDIBsize) return;
    if (y1<0)               y1=0;
    if (y2<0)               return;
    if (y1>=nDIBsize)       return;
    if (y2>=nDIBsize)       y2=nDIBsize-1;

    u32* p=(u32*)pDib->GetPixels()+(y1*pDib->Width())+x;
    int ylen=y2-y1+1;
    while (ylen--)
    {
        *p=colour;
        p+=pDib->Width();
    }
}

void CGraphView::DrawRect(int x1,int y1,int x2,int y2,u32 colour)
{
    HLine(x1,x2,y1,colour);
    HLine(x1,x2,y2,colour);
    VLine(x1,y1,y2,colour);
    VLine(x2,y1,y2,colour);
}
コード例 #11
0
ファイル: button.c プロジェクト: alchar/cpen_391_project1
bool draw_graph_path(int colour){
	if (zoom_level == ZOOM_OUT){
		if (!points_equal(prev_zoomed_out_min_corner, NULL_CORNER) && !points_equal(prev_zoomed_out_max_corner, NULL_CORNER)){
			draw_image_segment(prev_zoomed_out_min_corner,  prev_zoomed_out_max_corner);
		}
	}
	else{
		//First check to see if when subtracted from, it's less than 0...
		prev_zoomed_in_min_corner.x = (prev_zoomed_in_min_corner.x - curr_image_pos.x < 0) ? 0 : prev_zoomed_in_min_corner.x - curr_image_pos.x;
		prev_zoomed_in_min_corner.y = (prev_zoomed_in_min_corner.y - curr_image_pos.y < 0) ? 0 : prev_zoomed_in_min_corner.y - curr_image_pos.y;

		//Then check to see if it's greater than the DISPLAY WIDTH
		prev_zoomed_in_min_corner.x = (prev_zoomed_in_min_corner.x > DISPLAY_WIDTH) ? DISPLAY_WIDTH : prev_zoomed_in_min_corner.x;
		prev_zoomed_in_min_corner.y = (prev_zoomed_in_min_corner.y > DISPLAY_HEIGHT) ? DISPLAY_HEIGHT : prev_zoomed_in_min_corner.y;

		//This is all to make sure we don't die a horrible death of sadness and line apocalypse (of negative displays).
		prev_zoomed_in_max_corner.x = (prev_zoomed_in_max_corner.x - curr_image_pos.x < 0) ? 0 : prev_zoomed_in_max_corner.x - curr_image_pos.x;
		prev_zoomed_in_max_corner.y = (prev_zoomed_in_max_corner.y - curr_image_pos.y < 0) ? 0 : prev_zoomed_in_max_corner.y - curr_image_pos.y;
		prev_zoomed_in_max_corner.x = (prev_zoomed_in_max_corner.x > DISPLAY_WIDTH) ? DISPLAY_WIDTH : prev_zoomed_in_max_corner.x;
		prev_zoomed_in_max_corner.y = (prev_zoomed_in_max_corner.y > DISPLAY_HEIGHT) ? DISPLAY_HEIGHT : prev_zoomed_in_max_corner.y;
		if (!points_equal(prev_zoomed_in_min_corner, NULL_CORNER) && !points_equal(prev_zoomed_in_max_corner, NULL_CORNER)){
			draw_image_segment(prev_zoomed_in_min_corner,  prev_zoomed_in_max_corner);
		}
		printf("Corners are now: %d, %d\n%d, %d", prev_zoomed_in_min_corner.x, prev_zoomed_in_min_corner.y, prev_zoomed_in_max_corner.x, prev_zoomed_in_max_corner.y);
	}

	if (points != NULL){
		prev_zoomed_out_min_corner = points->zoomed_out_min_corner;
		prev_zoomed_out_max_corner = points->zoomed_out_max_corner;

		prev_zoomed_in_min_corner = points->zoomed_in_min_corner;
		prev_zoomed_in_max_corner = points->zoomed_in_max_corner;
		if (zoom_level == ZOOM_OUT)
			draw_path(points->zoomed_out_ordered_point_arr, points->actual_size, colour);
		else{
			Point points_arr[points->actual_size];
			for (int i = 0; i < points->actual_size; i++){

				points_arr[i] = NULL_CORNER;
				points_arr[i].x = points->zoomed_in_ordered_point_arr[i].x - curr_image_pos.x;
				points_arr[i].y = points->zoomed_in_ordered_point_arr[i].y - curr_image_pos.y;

				if (points_arr[i].x < 0 && points_arr[i].y < 0){
					printf("Originally... %d is  %d, %d\n", i, points_arr[i].x, points_arr[i].y);
					while (points_arr[i].x < 0 || points_arr[i].y < 0){
						points_arr[i].x+=3;
						points_arr[i].y+=1;
					}
					printf("Now point (%d): %d %d\n", i, points_arr[i].x, points_arr[i].y);
				}

				if (points_arr[i].x >= DISPLAY_WIDTH){
					points_arr[i].x = DISPLAY_WIDTH - 1;
				}
				if (points_arr[i].y >= DISPLAY_HEIGHT){
					points_arr[i].y = DISPLAY_HEIGHT - 1;
				}
				if (points_arr[i].x < 0){
					points_arr[i].x = 0;
				}
				if (points_arr[i].y < 0){
					points_arr[i].y = 0;
				}
			}
			draw_path(points_arr, points->actual_size, colour);
			VLine(600, 0, 480, BLACK);
		}
		//destroy_path_points(points);
		return true;
	}
	return false;
}