/[paragui]/paragui/src/widgets/pgwidget.cpp
ViewVC logotype

Diff of /paragui/src/widgets/pgwidget.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4.4.22.2.1 by braindead, Fri Nov 21 12:27:56 2003 UTC revision 1.4.4.22.2.2 by braindead, Mon Nov 24 09:17:22 2003 UTC
# Line 39  bool PG_Widget::bBulkUpdate = false; Line 39  bool PG_Widget::bBulkUpdate = false;
39  PG_RectList PG_Widget::widgetList;  PG_RectList PG_Widget::widgetList;
40  int PG_Widget::my_ObjectCounter = 0;  int PG_Widget::my_ObjectCounter = 0;
41    
42  typedef STL_MAP<int, PG_Widget*> PG_IdToWidgetMap;  class PG_WidgetDataInternal {
43  typedef map<string, PG_Widget*> PG_NameToWidgetMap;  public:
44            PG_WidgetDataInternal() {};
 struct PG_WidgetDataInternal{  
45    
46          PG_Font* font;          PG_Font* font;
47    
         PG_IdToWidgetMap childrenIdMap;  
         PG_NameToWidgetMap childrenNameMap;  
   
48          bool quitModalLoop;          bool quitModalLoop;
49          bool dirtyUpdate;          bool dirtyUpdate;
50                    
# Line 100  void PG_Widget::InitWidget(PG_Widget* pa Line 96  void PG_Widget::InitWidget(PG_Widget* pa
96          my_internaldata = new PG_WidgetDataInternal;          my_internaldata = new PG_WidgetDataInternal;
97                    
98          my_internaldata->inDestruct = false;          my_internaldata->inDestruct = false;
99            my_internaldata->font = NULL;
100            my_internaldata->dirtyUpdate = false;
101            my_internaldata->widgetParent = parent;
102            my_internaldata->id = -1;
103            my_internaldata->transparency = 0;
104            my_internaldata->quitModalLoop = false;
105            my_internaldata->visible = false;
106            my_internaldata->hidden = false;
107            my_internaldata->firstredraw = true;
108            my_internaldata->childList = NULL;
109            my_internaldata->haveTooltip = false;
110            my_internaldata->fadeSteps = 10;
111            my_internaldata->mouseInside = false;
112            my_internaldata->userdata = NULL;
113            my_internaldata->userdatasize = 0;
114            my_internaldata->widthText = TXT_HEIGHT_UNDEF;
115            my_internaldata->heightText = TXT_HEIGHT_UNDEF;
116    
117            my_internaldata->havesurface = bObjectSurface;
118    
119          //Set default font          //Set default font
120          if(PG_Application::DefaultFont != NULL) {          if(PG_Application::DefaultFont != NULL) {
# Line 108  void PG_Widget::InitWidget(PG_Widget* pa Line 123  void PG_Widget::InitWidget(PG_Widget* pa
123                                          PG_Application::DefaultFont->GetSize());                                          PG_Application::DefaultFont->GetSize());
124          }          }
125          else {          else {
                 my_internaldata->font = NULL;  
126                  PG_LogWRN("Unable to get default font! Did you load a theme ?");                  PG_LogWRN("Unable to get default font! Did you load a theme ?");
127          }          }
128    
         my_internaldata->dirtyUpdate = false;  
         my_internaldata->widgetParent = parent;  
         my_internaldata->havesurface = bObjectSurface;  
129          my_srfScreen = PG_Application::GetScreen();          my_srfScreen = PG_Application::GetScreen();
130    
131          if(my_internaldata->havesurface) {          if(my_internaldata->havesurface) {
# Line 143  void PG_Widget::InitWidget(PG_Widget* pa Line 154  void PG_Widget::InitWidget(PG_Widget* pa
154          my_colorBorder[1][1].g = 134;          my_colorBorder[1][1].g = 134;
155          my_colorBorder[1][1].b = 134;          my_colorBorder[1][1].b = 134;
156    
         my_internaldata->id = -1;  
         my_internaldata->transparency = 0;  
         my_internaldata->quitModalLoop = false;  
         my_internaldata->visible = false;  
         my_internaldata->hidden = false;  
         my_internaldata->firstredraw = true;  
   
         my_internaldata->childList = NULL;  
         my_internaldata->haveTooltip = false;  
         my_internaldata->fadeSteps = 10;  
   
157          my_text = "";          my_text = "";
158    
159          if (my_internaldata->widgetParent != NULL) {          if (my_internaldata->widgetParent != NULL) {
# Line 162  void PG_Widget::InitWidget(PG_Widget* pa Line 162  void PG_Widget::InitWidget(PG_Widget* pa
162                  my_internaldata->widgetParent->AddChild(this);                  my_internaldata->widgetParent->AddChild(this);
163          }          }
164    
         my_internaldata->mouseInside = false;  
         my_internaldata->userdata = NULL;  
         my_internaldata->userdatasize = 0;  
   
         my_internaldata->widthText = TXT_HEIGHT_UNDEF;  
         my_internaldata->heightText = TXT_HEIGHT_UNDEF;  
   
165          my_internaldata->rectClip = *this;          my_internaldata->rectClip = *this;
166    
167          AddToWidgetList();          AddToWidgetList();
# Line 349  void PG_Widget::AddChild(PG_Widget * chi Line 342  void PG_Widget::AddChild(PG_Widget * chi
342    
343          my_internaldata->childList->Add(child);          my_internaldata->childList->Add(child);
344    
345      AddChildToCache(child, child->GetName());      //AddChildToCache(child, child->GetName());
346          AddChildToCache(child,  child->GetID());          //AddChildToCache(child,  child->GetID());
347  }  }
348    
349  void PG_Widget::AddChildToCache(PG_Widget *child, const char *name) {  /*void PG_Widget::AddChildToCache(PG_Widget *child, const char *name) {
350          if (name == NULL) {          if (name == NULL) {
351                  return;                  return;
352          }          }
# Line 365  void PG_Widget::AddChildToCache(PG_Widge Line 358  void PG_Widget::AddChildToCache(PG_Widge
358                          string n = name;                          string n = name;
359                          my_internaldata->childrenNameMap[n] = child;                          my_internaldata->childrenNameMap[n] = child;
360          }          }
361  }  }*/
362    
363  void PG_Widget::AddChildToCache(PG_Widget *child, int id) {  /*void PG_Widget::AddChildToCache(PG_Widget *child, int id) {
364          if (id <= 0) {          if (id <= 0) {
365                  return;                  return;
366          }          }
# Line 378  void PG_Widget::AddChildToCache(PG_Widge Line 371  void PG_Widget::AddChildToCache(PG_Widge
371          else {          else {
372                  my_internaldata->childrenIdMap[id] = child;                  my_internaldata->childrenIdMap[id] = child;
373          }          }
374  }  }*/
375    
376  /**  */  /**  */
377  bool PG_Widget::MoveWindow(int x, int y) {  bool PG_Widget::MoveWindow(int x, int y) {
# Line 552  bool PG_Widget::ProcessEvent(const SDL_E Line 545  bool PG_Widget::ProcessEvent(const SDL_E
545  }  }
546    
547  bool PG_Widget::RemoveChild(PG_Widget * child) {  bool PG_Widget::RemoveChild(PG_Widget * child) {
548          if(my_internaldata->childList == NULL) {          if(my_internaldata->childList == NULL || child == NULL) {
549                  return false;                  return false;
550          }          }
551    
552      if (!child)      //const char *name = child->GetName();
553          return false;      //int id = child->GetID();
       
     const char *name = child->GetName();  
     int id = child->GetID();  
554    
555      if (FindChild(name))      /*if (FindChild(name))
556          my_internaldata->childrenNameMap[name] = 0;          my_internaldata->childrenNameMap[name] = 0;
557    
558      if (FindChild(id))      if (FindChild(id))
559          my_internaldata->childrenIdMap[id] = 0;          my_internaldata->childrenIdMap[id] = 0;*/
560    
561          return my_internaldata->childList->Remove(child);          return my_internaldata->childList->Remove(child);
562  }  }
# Line 945  void PG_Widget::BulkBlit() { Line 935  void PG_Widget::BulkBlit() {
935    
936  void PG_Widget::LoadThemeStyle(const char* widgettype, const char* objectname) {  void PG_Widget::LoadThemeStyle(const char* widgettype, const char* objectname) {
937          PG_Theme* t = PG_Application::GetTheme();          PG_Theme* t = PG_Application::GetTheme();
938          SDL_Color* c;          PG_Color c;
939    
940          const char *font = t->FindFontName(widgettype, objectname);          const char *font = t->FindFontName(widgettype, objectname);
941          int fontsize = t->FindFontSize(widgettype, objectname);          int fontsize = t->FindFontSize(widgettype, objectname);
# Line 960  void PG_Widget::LoadThemeStyle(const cha Line 950  void PG_Widget::LoadThemeStyle(const cha
950          if (fontstyle >= 0)          if (fontstyle >= 0)
951                  SetFontStyle(fontstyle, true);                  SetFontStyle(fontstyle, true);
952    
953          c = t->FindColor(widgettype, objectname, "textcolor");          c = GetFontColor();
954          if(c != NULL)          t->GetColor(widgettype, objectname, "textcolor", c);
955                  SetFontColor(*c);          SetFontColor(c);
   
         c = t->FindColor(widgettype, objectname, "bordercolor0");  
         if(c != NULL) {  
                 my_colorBorder[0][0] = *c;  
         }  
956    
957          c = t->FindColor(widgettype, objectname, "bordercolor1");          t->GetColor(widgettype, objectname, "bordercolor0", my_colorBorder[0][0]);
958          if(c != NULL) {          t->GetColor(widgettype, objectname, "bordercolor1", my_colorBorder[1][0]);
                 my_colorBorder[1][0] = *c;  
         }  
959  }  }
960    
961  void PG_Widget::LoadThemeStyle(const char* widgettype) {}  void PG_Widget::LoadThemeStyle(const char* widgettype) {}
# Line 1324  void PG_Widget::SetTextFormat(const char Line 1307  void PG_Widget::SetTextFormat(const char
1307          va_end(ap);          va_end(ap);
1308  }  }
1309    
1310  void PG_Widget::SetFontColor(const SDL_Color& Color) {  void PG_Widget::SetFontColor(const PG_Color& Color) {
1311          my_internaldata->font->SetColor(Color);          my_internaldata->font->SetColor(Color);
1312  }  }
1313    
 void PG_Widget::SetFontColor(int Red, int Green, int Blue) {  
         SDL_Color c;  
         c.r = Red;  
         c.g = Green;  
         c.b = Blue;  
         SetFontColor(c);  
 }  
   
 void PG_Widget::SetFontColor(int Color) {  
         SDL_Color c;  
         c.r = (Color >> 16) & 0xff;  
         c.g = (Color >> 8) & 0xff;  
         c.b = Color & 0xff;  
         SetFontColor(c);  
 }  
   
1314  void PG_Widget::SetFontAlpha(int Alpha, bool bRecursive) {  void PG_Widget::SetFontAlpha(int Alpha, bool bRecursive) {
1315          my_internaldata->font->SetAlpha(Alpha);          my_internaldata->font->SetAlpha(Alpha);
1316    
# Line 1504  void PG_Widget::DrawText(int x, int y, c Line 1471  void PG_Widget::DrawText(int x, int y, c
1471          }          }
1472  }  }
1473    
1474  void PG_Widget::DrawText(const PG_Rect& rect, const char* text, const SDL_Color& c) {  void PG_Widget::DrawText(const PG_Rect& rect, const char* text, const PG_Color& c) {
1475          SetFontColor(c);          SetFontColor(c);
1476          DrawText(rect, text);          DrawText(rect, text);
1477  }  }
1478    
1479  void PG_Widget::DrawText(int x, int y, const char* text, const SDL_Color& c) {  void PG_Widget::DrawText(int x, int y, const char* text, const PG_Color& c) {
1480          DrawText(PG_Rect(x,y,w,h), text, c);          DrawText(PG_Rect(x,y,w,h), text, c);
1481  }  }
1482    
# Line 1596  void PG_Widget::DrawBorder(const PG_Rect Line 1563  void PG_Widget::DrawBorder(const PG_Rect
1563    
1564          // outer frame          // outer frame
1565          if (size >= 1) {          if (size >= 1) {
1566                  DrawHLine(r.x + 0, r.y + 0, r.w, my_colorBorder[i0][0].r, my_colorBorder[i0][0].g, my_colorBorder[i0][0].b);                  DrawHLine(r.x + 0, r.y + 0, r.w, my_colorBorder[i0][0]);
1567                  DrawVLine(r.x + 0, r.y + 0, r.h - 1, my_colorBorder[i0][0].r, my_colorBorder[i0][0].g, my_colorBorder[i0][0].b);                  DrawVLine(r.x + 0, r.y + 0, r.h - 1, my_colorBorder[i0][0]);
1568    
1569                  DrawHLine(r.x + 0, r.y + r.h - 1, r.w - 1, my_colorBorder[i1][0].r, my_colorBorder[i1][0].g, my_colorBorder[i1][0].b);                  DrawHLine(r.x + 0, r.y + r.h - 1, r.w - 1, my_colorBorder[i1][0]);
1570                  DrawVLine(r.x + r.w - 1, r.y + 1, r.h - 1, my_colorBorder[i1][0].r, my_colorBorder[i1][0].g, my_colorBorder[i1][0].b);                  DrawVLine(r.x + r.w - 1, r.y + 1, r.h - 1, my_colorBorder[i1][0]);
1571          }          }
1572          // inner frame          // inner frame
1573          if (size >= 2) {          if (size >= 2) {
1574                  DrawHLine(r.x + 1, r.y + 1, r.w - 1, my_colorBorder[i0][1].r, my_colorBorder[i0][1].g, my_colorBorder[i0][1].b);                  DrawHLine(r.x + 1, r.y + 1, r.w - 1, my_colorBorder[i0][1]);
1575                  DrawVLine(r.x + 1, r.y + 1, r.h - 2, my_colorBorder[i0][1].r, my_colorBorder[i0][1].g, my_colorBorder[i0][1].b);                  DrawVLine(r.x + 1, r.y + 1, r.h - 2, my_colorBorder[i0][1]);
1576    
1577                  DrawHLine(r.x + 1, r.y + r.h - 2, r.w - 2, my_colorBorder[i1][1].r, my_colorBorder[i1][1].g, my_colorBorder[i1][1].b);                  DrawHLine(r.x + 1, r.y + r.h - 2, r.w - 2, my_colorBorder[i1][1]);
1578                  DrawVLine(r.x + r.w - 2, r.y + 2, r.h - 2, my_colorBorder[i1][1].r, my_colorBorder[i1][1].g, my_colorBorder[i1][1].b);                  DrawVLine(r.x + r.w - 2, r.y + 2, r.h - 2, my_colorBorder[i1][1]);
1579          }          }
1580  }  }
1581    
# Line 1641  void PG_Widget::GetClipRects(PG_Rect& sr Line 1608  void PG_Widget::GetClipRects(PG_Rect& sr
1608          src.my_height = dst.my_height;          src.my_height = dst.my_height;
1609  }  }
1610    
1611  void PG_Widget::SetPixel(int x, int y, Uint8 r, Uint8 g, Uint8 b) {  void PG_Widget::SetPixel(int x, int y, const PG_Color& c) {
1612          static PG_Point p;          static PG_Point p;
1613    
1614          if(my_srfObject == NULL) {          if(my_srfObject == NULL) {
1615                  p.x = my_xpos + x;                  p.x = my_xpos + x;
1616                  p.y = my_ypos + y;                  p.y = my_ypos + y;
1617                  if(my_internaldata->rectClip.IsInside(p)) {                  if(my_internaldata->rectClip.IsInside(p)) {
1618                          PG_Draw::SetPixel(p.x, p.y, r, g, b, my_srfScreen);                          PG_Draw::SetPixel(p.x, p.y, c, my_srfScreen);
1619                  }                  }
1620          } else {          } else {
1621                  PG_Draw::SetPixel(x, y, r, g, b, my_srfObject);                  PG_Draw::SetPixel(x, y, c, my_srfObject);
1622          }          }
1623  }  }
1624    
1625  void PG_Widget::DrawHLine(int x, int y, int w, Uint8 r, Uint8 g, Uint8 b) {  void PG_Widget::DrawHLine(int x, int y, int w, const PG_Color& color) {
1626          static PG_Rect rect;          static PG_Rect rect;
1627          SDL_Surface* surface = my_srfObject;          SDL_Surface* surface = my_srfObject;
1628                    
# Line 1679  void PG_Widget::DrawHLine(int x, int y, Line 1646  void PG_Widget::DrawHLine(int x, int y,
1646          // clip to widget cliprect          // clip to widget cliprect
1647          int x0 = PG_MAX(x, my_internaldata->rectClip.x);          int x0 = PG_MAX(x, my_internaldata->rectClip.x);
1648          int x1 = PG_MIN(x+w, my_internaldata->rectClip.x+my_internaldata->rectClip.w);          int x1 = PG_MIN(x+w, my_internaldata->rectClip.x+my_internaldata->rectClip.w);
1649          Uint32 c = SDL_MapRGB(surface->format, r, g, b);          Uint32 c = color.MapRGB(surface->format);
1650    
1651          // clip to surface cliprect          // clip to surface cliprect
1652          /*x0 = PG_MAX(x0, rect.x);          /*x0 = PG_MAX(x0, rect.x);
# Line 1700  void PG_Widget::DrawHLine(int x, int y, Line 1667  void PG_Widget::DrawHLine(int x, int y,
1667          SDL_FillRect(surface, &rect, c);          SDL_FillRect(surface, &rect, c);
1668  }  }
1669    
1670  void PG_Widget::DrawVLine(int x, int y, int h, Uint8 r, Uint8 g, Uint8 b) {  void PG_Widget::DrawVLine(int x, int y, int h, const PG_Color& color) {
1671          static PG_Rect rect;          static PG_Rect rect;
1672          SDL_Surface* surface = my_srfObject;          SDL_Surface* surface = my_srfObject;
1673                    
# Line 1724  void PG_Widget::DrawVLine(int x, int y, Line 1691  void PG_Widget::DrawVLine(int x, int y,
1691          // clip to widget cliprect          // clip to widget cliprect
1692          int y0 = PG_MAX(y, my_internaldata->rectClip.y);          int y0 = PG_MAX(y, my_internaldata->rectClip.y);
1693          int y1 = PG_MIN(y+h, my_internaldata->rectClip.y+my_internaldata->rectClip.h);          int y1 = PG_MIN(y+h, my_internaldata->rectClip.y+my_internaldata->rectClip.h);
1694          Uint32 c = SDL_MapRGB(surface->format, r, g, b);          Uint32 c = color.MapRGB(surface->format);
1695    
1696          // clip to surface cliprect          // clip to surface cliprect
1697          /*y0 = PG_MAX(y0, rect.y);          /*y0 = PG_MAX(y0, rect.y);
# Line 1746  void PG_Widget::DrawVLine(int x, int y, Line 1713  void PG_Widget::DrawVLine(int x, int y,
1713  }  }
1714    
1715  /**  */  /**  */
1716  void PG_Widget::DrawRectWH(int x, int y, int w, int h, Uint8 r, Uint8 g, Uint8 b) {  void PG_Widget::DrawRectWH(int x, int y, int w, int h, const PG_Color& c) {
1717    
1718          DrawHLine(x, y, w, r, g, b);          DrawHLine(x, y, w, c);
1719          DrawHLine(x, y + h - 1, w, r, g, b);          DrawHLine(x, y + h - 1, w, c);
1720          DrawVLine(x, y, h, r, g, b);          DrawVLine(x, y, h, c);
1721          DrawVLine(x + w - 1, y, h, r, g, b);          DrawVLine(x + w - 1, y, h, c);
1722    
1723  }  }
1724    
1725  void PG_Widget::DrawLine(Uint32 x0, Uint32 y0, Uint32 x1, Uint32 y1, const SDL_Color& color, Uint8 width) {  void PG_Widget::DrawLine(Uint32 x0, Uint32 y0, Uint32 x1, Uint32 y1, const PG_Color& color, Uint8 width) {
1726          SDL_Surface* surface = my_srfObject;          SDL_Surface* surface = my_srfObject;
1727    
1728          if(surface == NULL) {          if(surface == NULL) {
# Line 1811  int PG_Widget::GetID() { Line 1778  int PG_Widget::GetID() {
1778  }  }
1779    
1780  PG_Widget* PG_Widget::FindChild(int id) {  PG_Widget* PG_Widget::FindChild(int id) {
1781          PG_IdToWidgetMap::iterator r = my_internaldata->childrenIdMap.find(id);          if(my_internaldata->childList == NULL) {
   
         if(r == my_internaldata->childrenIdMap.end()) {  
1782                  return NULL;                  return NULL;
1783          }          }
1784            return my_internaldata->childList->Find(id);
         return (*r).second;  
1785  }  }
1786    
1787  PG_Widget* PG_Widget::FindChild(const char *name) {  PG_Widget* PG_Widget::FindChild(const char *name) {
1788          string n = name;          if(my_internaldata->childList == NULL) {
         PG_NameToWidgetMap::iterator r = my_internaldata->childrenNameMap.find(n);  
   
         if(r == my_internaldata->childrenNameMap.end()) {  
1789                  return NULL;                  return NULL;
1790          }          }
1791            return my_internaldata->childList->Find(name);
         return (*r).second;  
1792  }  }
1793    
1794  PG_RectList* PG_Widget::GetChildList() {  PG_RectList* PG_Widget::GetChildList() {
# Line 1845  PG_RectList* PG_Widget::GetWidgetList() Line 1805  PG_RectList* PG_Widget::GetWidgetList()
1805    
1806  void PG_Widget::SetName(const char *name) {  void PG_Widget::SetName(const char *name) {
1807          my_internaldata->name = name;          my_internaldata->name = name;
         if (my_internaldata->widgetParent) {  
                 my_internaldata->widgetParent->AddChildToCache(this, name);  
         }  
1808  }  }
1809    
1810  const char* PG_Widget::GetName() {  const char* PG_Widget::GetName() {
# Line 1862  int PG_Widget::GetFontHeight() { Line 1819  int PG_Widget::GetFontHeight() {
1819          return my_internaldata->font->GetFontHeight();          return my_internaldata->font->GetFontHeight();
1820  }  }
1821    
1822  SDL_Color PG_Widget::GetFontColor() {  PG_Color PG_Widget::GetFontColor() {
1823          return my_internaldata->font->GetColor();          return my_internaldata->font->GetColor();
1824  }  }
1825    
# Line 1911  bool PG_Widget::eventMessage(MSG_MESSAGE Line 1868  bool PG_Widget::eventMessage(MSG_MESSAGE
1868    
1869  void PG_Widget::SetID(int id) {  void PG_Widget::SetID(int id) {
1870          my_internaldata->id = id;          my_internaldata->id = id;
         if (my_internaldata->widgetParent) {  
                 my_internaldata->widgetParent->AddChildToCache(this, id);  
         }  
1871  }  }
1872    
1873  void PG_Widget::SetDirtyUpdate(bool bDirtyUpdate) {  void PG_Widget::SetDirtyUpdate(bool bDirtyUpdate) {

Legend:
Removed from v.1.4.4.22.2.1  
changed lines
  Added in v.1.4.4.22.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26