paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/test/colorselector pgcolorselector.cpp,1.1.2.


From: Alexander Pipelka <address@hidden>
Subject: [paragui-cvs] CVS: paragui/test/colorselector pgcolorselector.cpp,1.1.2.1,1.1.2.2 pgcolorselector.h,1.1.2.1,1.1.2.2
Date: Fri, 12 Jul 2002 05:26:01 -0400

Update of /cvsroot/paragui/paragui/test/colorselector
In directory subversions:/tmp/cvs-serv10716/test/colorselector

Modified Files:
      Tag: devel-1-0
        pgcolorselector.cpp pgcolorselector.h 
Log Message:
added PG_ThemeWidget::GetGradient
more colorselector fun



Index: pgcolorselector.cpp
===================================================================
RCS file: 
/cvsroot/paragui/paragui/test/colorselector/Attic/pgcolorselector.cpp,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** pgcolorselector.cpp 12 Jul 2002 06:10:21 -0000      1.1.2.1
--- pgcolorselector.cpp 12 Jul 2002 09:25:59 -0000      1.1.2.2
***************
*** 1,17 ****
  #include "pgcolorselector.h"
  
! PG_ColorSelector::PG_ColorSelector(PG_Widget* parent, const PG_Rect&r, const 
char* style) : PG_ThemeWidget(parent, r, style)  {
!       my_colorbox = new PG_ThemeWidget(this, PG_Rect(5,5,r.h-10,r.h-10));
        
        PG_Gradient g;
        g.colors[0].r = 255;
!       g.colors[0].g = 0;
        g.colors[0].b = 0;
        
        g.colors[1].r = 0;
        g.colors[1].g = 255;
!       g.colors[1].b = 0;
        
!       g.colors[2].r = 0;
        g.colors[2].g = 0;
        g.colors[2].b = 255;
--- 1,98 ----
  #include "pgcolorselector.h"
  
! PG_ColorSelector::PG_ColorBox::PG_ColorBox(PG_ColorSelector* parent, const 
PG_Rect& r) : PG_ThemeWidget(parent, r) {
!       my_btndown = false;
! 
!       p.x = r.w/2;
!       p.y = r.h/2;
! }
!               
! bool PG_ColorSelector::PG_ColorBox::eventMouseMotion(const 
SDL_MouseMotionEvent* motion) {
!       if(!my_btndown) {
!               return false;
!       }
!       
!       p = ScreenToClient(motion->x, motion->y);
!       Update();
!       GetParent()->SetBaseColor(GetBaseColor());
!       return true;
! }
! 
! bool PG_ColorSelector::PG_ColorBox::eventMouseButtonDown(const 
SDL_MouseButtonEvent* button) {
!       if(my_btndown) {
!               return false;
!       }
        
+       my_btndown = true;
+       p = ScreenToClient(button->x, button->y);
+       Update();
+       GetParent()->SetBaseColor(GetBaseColor());
+       return true;
+ }
+ 
+ bool PG_ColorSelector::PG_ColorBox::eventMouseButtonUp(const 
SDL_MouseButtonEvent* button) {
+       my_btndown = false;
+       return true;
+ }
+ 
+ void PG_ColorSelector::PG_ColorBox::eventBlit(SDL_Surface* srf, const 
PG_Rect& src, const PG_Rect& dst) {
+       PG_ThemeWidget::eventBlit(srf, src, dst);
+       
+       // draw crosshair
+       DrawHLine(0, p.y, w, 255,255,255);
+       DrawVLine(p.x, 0, h, 255,255,255);
+ }
+ 
+ SDL_Color PG_ColorSelector::PG_ColorBox::GetBaseColor() {
+       SDL_Color result;
+       
+       SDL_Color cy1, cy2;
+       SDL_Color r,g,b,w;
+       PG_Gradient gr = GetGradient();
+       
+       r = gr.colors[0];
+       g = gr.colors[1];
+       b = gr.colors[2];
+       w = gr.colors[3];
+       
+       // cy1 = ( (b - r) / h ) * y
+       
+       cy1.r = (Uint8)((float)r.r + (((float)b.r - (float)r.r) / 
(float)my_height) * (float)p.y);
+       cy1.g = (Uint8)((float)r.g + (((float)b.g - (float)r.g) / 
(float)my_height) * (float)p.y);
+       cy1.b = (Uint8)((float)r.b + (((float)b.b - (float)r.b) / 
(float)my_height) * (float)p.y);
+       
+       // cy2 = ( (w - g) / h ) * y
+       
+       cy2.r = (Uint8)((float)g.r + (((float)w.r - (float)g.r) / 
(float)my_height) * (float)p.y);
+       cy2.g = (Uint8)((float)g.g + (((float)w.g - (float)g.g) / 
(float)my_height) * (float)p.y);
+       cy2.b = (Uint8)((float)g.b + (((float)w.b - (float)g.b) / 
(float)my_height) * (float)p.y);
+       
+       // result = ( (cy2 - cy1) / w ) * x
+ 
+       result.r = (Uint8)((float)cy1.r + (((float)cy2.r - (float)cy1.r) / 
(float)my_width) * (float)p.x);
+       result.g = (Uint8)((float)cy1.g + (((float)cy2.g - (float)cy1.g) / 
(float)my_width) * (float)p.x);
+       result.b = (Uint8)((float)cy1.b + (((float)cy2.b - (float)cy1.b) / 
(float)my_width) * (float)p.x);
+       
+       return result;
+ }
+ 
+ PG_ColorSelector::PG_ColorSelector(PG_Widget* parent, const PG_Rect&r, const 
char* style) : PG_ThemeWidget(parent, r, style)  {
        PG_Gradient g;
+ 
+       my_color.r = 255;
+       my_color.g = 255;
+       my_color.b = 255;
+ 
+       my_colorbox = new PG_ColorBox(this, PG_Rect(5,5,r.h-10,r.h-10));
+       
        g.colors[0].r = 255;
!       g.colors[0].g = 255;
        g.colors[0].b = 0;
        
        g.colors[1].r = 0;
        g.colors[1].g = 255;
!       g.colors[1].b = 255;
        
!       g.colors[2].r = 255;
        g.colors[2].g = 0;
        g.colors[2].b = 255;
***************
*** 24,29 ****
--- 105,146 ----
        my_colorbox->SetBackground((SDL_Surface*)NULL);
        my_colorbox->SetSimpleBackground(false);
+ 
+       my_colorslider = new PG_Slider(this, -1, PG_Rect(r.h, 5, 20, r.h-10), 
PG_SB_VERTICAL);
+       my_colorslider->SetRange(0, 255);
+ 
+       my_colorslider->SetBackground((SDL_Surface*)NULL);
+       my_colorslider->SetSimpleBackground(false);
+ 
+       SetBaseColor(my_color);
+ 
  }
  
  PG_ColorSelector::~PG_ColorSelector() {
+ }
+ 
+ void PG_ColorSelector::SetColor(const SDL_Color& c) {
+       my_color = c;
+ }
+ 
+ void PG_ColorSelector::SetBaseColor(const SDL_Color& c) {
+       PG_Gradient g;
+       my_basecolor = c;
+ 
+       g.colors[0].r = my_basecolor.r;
+       g.colors[0].g = my_basecolor.g;
+       g.colors[0].b = my_basecolor.b;
+ 
+       g.colors[1].r = my_basecolor.r;
+       g.colors[1].g = my_basecolor.g;
+       g.colors[1].b = my_basecolor.b;
+       
+       g.colors[2].r = 0;
+       g.colors[2].g = 0;
+       g.colors[2].b = 0;
+       
+       g.colors[3].r = 0;
+       g.colors[3].g = 0;
+       g.colors[3].b = 0;
+ 
+       my_colorslider->SetGradient(g);
  }

Index: pgcolorselector.h
===================================================================
RCS file: /cvsroot/paragui/paragui/test/colorselector/Attic/pgcolorselector.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** pgcolorselector.h   12 Jul 2002 06:10:21 -0000      1.1.2.1
--- pgcolorselector.h   12 Jul 2002 09:25:59 -0000      1.1.2.2
***************
*** 3,8 ****
--- 3,36 ----
  
  #include "pgthemewidget.h"
+ #include "pgslider.h"
  
  class DECLSPEC PG_ColorSelector : public PG_ThemeWidget {
+ protected:
+       
+       class PG_ColorBox : public PG_ThemeWidget {
+       public:
+               
+               PG_ColorBox(PG_ColorSelector* parent, const PG_Rect& r);
+               
+               inline PG_ColorSelector* GetParent() {
+                       return 
static_cast<PG_ColorSelector*>(PG_ThemeWidget::GetParent());
+               }
+               
+       protected:
+               
+               void eventBlit(SDL_Surface* srf, const PG_Rect& src, const 
PG_Rect& dst);
+               
+               bool eventMouseMotion(const SDL_MouseMotionEvent* motion);
+               bool eventMouseButtonDown(const SDL_MouseButtonEvent* button);
+               bool eventMouseButtonUp(const SDL_MouseButtonEvent* button);
+               
+               SDL_Color GetBaseColor();
+               
+       private:
+               
+               bool my_btndown;
+               PG_Point p;
+       };
+       
  public:
        
***************
*** 10,16 ****
        ~PG_ColorSelector();
  
  protected:
-       PG_ThemeWidget* my_colorbox;
        
  };
  
--- 38,54 ----
        ~PG_ColorSelector();
  
+       void SetColor(const SDL_Color& c);
+       
  protected:
        
+       void SetBaseColor(const SDL_Color& c);
+       
+       PG_ColorBox* my_colorbox;
+       PG_Slider* my_colorslider;
+       
+       SDL_Color my_color;
+       SDL_Color my_basecolor;
+       
+       friend class PG_ColorBox;
  };
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]