Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Своя градиентная заливка, нужна помощь в доработке 
:(
    Опции темы
SerK
Дата 25.12.2007, 20:58 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 263
Регистрация: 31.3.2007

Репутация: нет
Всего: нет



Есть готовая функция, которая создает участок с
градиентной заливкой.
Функция рабочая, хотелось бы прописать ее в отдельный
файл, но возникает проблема, требуется еще подключить
постороннюю библиотеку, как это сделать.
Вот код, пользуйтесь, если кто может - помогите.
Код

#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);
   }
}


Необходимо подключить библиотеку #include "IdGlobal.hpp".
Она нужна для определения Min и Max.

Да, чуть не забыл, это перевод с Делфи - пакет RXLib.

Это сообщение отредактировал(а) SerK - 25.12.2007, 21:09


--------------------
Пусть будет миру хорошо!
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "С++ Builder"
Rrader

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Литературу по С++ Builder обсуждаем здесь
  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Настоятельно рекомендуем заглянуть в DRKB (Delphi Russian Knowledge Base) - крупнейший в рунете сборник материалов по Дельфи


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Rrader.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C++ Builder | Следующая тема »


 




[ Время генерации скрипта: 0.0703 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.