Доброй ночи! Чтобы не создавать новой темы, вопрос по этой же теме. Как к моей *.h подключить другую библиотеку Вот пример кода:
Код | #ifndef GradientFillH #define GradientFillH //--------------------------------------------------------------------------- #include "IdGlobal.hpp"
//--------------------------------------------------------------------------- typedef unsigned char uc; enum TDirection {gdBottomToTop,gdRightToLeft,gdTopToBottom,gdLeftToRight};
//--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- void __fastcall SGVGradientFillRect(TCanvas *Canvas,TRect ARect, TColor StartColor,TColor EndColor,TDirection Direction,uc Colors) { uc StartRGB[3]; int RGBDelta[3]; TRect ColorBand; int I, Delta; HBRUSH Brush; div_t dv;
if(IsRectEmpty(ARect)) return; if(Colors < 2) { Brush = CreateSolidBrush(ColorToRGB(StartColor)); FillRect(Canvas->Handle, &ARect, Brush); DeleteObject(Brush); return; } switch(Direction) { case gdBottomToTop : StartRGB[0] = GetRValue(StartColor); StartRGB[1] = GetGValue(StartColor); StartRGB[2] = GetBValue(StartColor);
RGBDelta[0] = GetRValue(EndColor) - StartRGB[0]; RGBDelta[1] = GetGValue(EndColor) - StartRGB[1]; RGBDelta[2] = GetBValue(EndColor) - StartRGB[2]; break; case gdRightToLeft : StartRGB[0] = GetRValue(StartColor); StartRGB[1] = GetGValue(StartColor); StartRGB[2] = GetBValue(StartColor);
RGBDelta[0] = GetRValue(EndColor) - StartRGB[0]; RGBDelta[1] = GetGValue(EndColor) - StartRGB[1]; RGBDelta[2] = GetBValue(EndColor) - StartRGB[2]; break; case gdTopToBottom: StartRGB[0] = GetRValue(EndColor); StartRGB[1] = GetGValue(EndColor); StartRGB[2] = GetBValue(EndColor);
RGBDelta[0] = GetRValue(StartColor) - StartRGB[0]; RGBDelta[1] = GetGValue(StartColor) - StartRGB[1]; RGBDelta[2] = GetBValue(StartColor) - StartRGB[2]; break; case gdLeftToRight: StartRGB[0] = GetRValue(EndColor); StartRGB[1] = GetGValue(EndColor); StartRGB[2] = GetBValue(EndColor);
RGBDelta[0] = GetRValue(StartColor) - StartRGB[0]; RGBDelta[1] = GetGValue(StartColor) - StartRGB[1]; RGBDelta[2] = GetBValue(StartColor) - StartRGB[2]; break; } ColorBand = ARect; if (Direction == gdBottomToTop || Direction == gdTopToBottom) { Colors = Max(2, Min(Colors, ARect.Height())); dv = div(ARect.Height(),Colors); Delta = dv.quot; } else { Colors = Max(2, Min(Colors, ARect.Width())); dv = div(ARect.Width(),Colors); Delta = dv.quot; } Canvas->Pen->Style = psSolid; Canvas->CopyMode = cmSrcCopy; if (Delta > 0) { for (I = 0; I <= Colors; I++) { switch(Direction) { case gdBottomToTop: ColorBand.Top = ARect.Top + I * Delta; ColorBand.Bottom = ColorBand.Top + Delta; break; case gdTopToBottom: ColorBand.Top = ARect.Top + I * Delta; ColorBand.Bottom = ColorBand.Top + Delta; break; case gdRightToLeft: ColorBand.Left = ARect.Left + I * Delta; ColorBand.Right = ColorBand.Left + Delta; break; case gdLeftToRight: ColorBand.Left = ARect.Left + I * Delta; ColorBand.Right = ColorBand.Left + Delta; break; } Brush = CreateSolidBrush(RGB( StartRGB[0] + MulDiv(I, RGBDelta[0], Colors - 1), StartRGB[1] + MulDiv(I, RGBDelta[1], Colors - 1), StartRGB[2] + MulDiv(I, RGBDelta[2], Colors - 1))); FillRect(Canvas->Handle, &ColorBand, Brush); DeleteObject(Brush); } } if (Direction == gdBottomToTop || Direction == gdTopToBottom) Delta = ARect.Height() % Colors; else Delta = ARect.Width() % Colors; if (Delta > 0) { switch(Direction) { case gdBottomToTop: ColorBand.Top = ARect.Bottom - Delta; ColorBand.Bottom = ColorBand.Top + Delta; break; case gdTopToBottom: ColorBand.Top = ARect.Bottom - Delta; ColorBand.Bottom = ColorBand.Top + Delta; break; case gdRightToLeft: ColorBand.Left = ARect.Right - Delta; ColorBand.Right = ColorBand.Left + Delta; break; case gdLeftToRight: ColorBand.Left = ARect.Right - Delta; ColorBand.Right = ColorBand.Left + Delta; break; } switch(Direction) { case gdBottomToTop: Brush = CreateSolidBrush(EndColor); break; case gdRightToLeft: Brush = CreateSolidBrush(EndColor); break; default: //{3, 4} Brush = CreateSolidBrush(StartColor); break; } FillRect(Canvas->Handle, &ColorBand, Brush); DeleteObject(Brush); } }
|
Кстати, это функция градиентной заливки, которую мы перевели с Паскаля (RX Lib). Хотелось бы ее хранить и вызывать из отдельного файла, но чтобы это получилось, нужно подключить библиотеку #include "IdGlobal.hpp", а вот ее то компилятор не видит, кто знает - в чем проблема?
Эта библиотека нужна для использования функций Маx и Min. |