[Add] More vscroll widget work. Still incomplete though.
This commit is contained in:
		
							parent
							
								
									948652f752
								
							
						
					
					
						commit
						b7698e8e08
					
				| @ -10,11 +10,11 @@ include_HEADERS = body.h frame.h generic_system_view.h glfreetype.h gui_button.h | ||||
| 		planet.h player.h dynamic_body.h sector.h sector_view.h ship_cpanel.h ship.h space.h star.h star_system.h system_info_view.h \
 | ||||
| 		system_view.h vector3.h view.h world_view.h utils.h space_station.h space_station_view.h model_body.h gui_iselectable.h \
 | ||||
| 		ship_type.h object.h info_view.h model_coll_mesh_data.h object_viewer_view.h fixed.h custom_starsystems.h gameconsts.h \
 | ||||
| 		aabb.h serializer.h sfx.h gui_vscroll_bar.h | ||||
| 		aabb.h serializer.h sfx.h gui_vscroll_portal.h gui_vscroll_bar.h gui_adjustment.h | ||||
| 
 | ||||
| libgui_a_SOURCES = gui_button.cpp gui.cpp gui_fixed.cpp gui_screen.cpp gui_label.cpp gui_tooltip.cpp gui_toggle_button.cpp gui_radio_button.cpp \
 | ||||
| 									 gui_radio_group.cpp gui_image_button.cpp gui_image.cpp gui_image_radio_button.cpp gui_multi_state_image_button.cpp gui_widget.cpp \
 | ||||
| 									 gui_container.cpp gui_vscroll_bar.cpp | ||||
| 									 gui_container.cpp gui_vscroll_portal.cpp gui_vscroll_bar.cpp | ||||
| 
 | ||||
| Lephisto3D_SOURCES	= main.cpp glfreetype.cpp body.cpp space.cpp ship.cpp player.cpp dynamic_body.cpp planet.cpp \
 | ||||
| 											star.cpp frame.cpp ship_cpanel.cpp sector_view.cpp mtrand.cpp world_view.cpp system_view.cpp \
 | ||||
|  | ||||
							
								
								
									
										16
									
								
								src/gui_adjustment.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/gui_adjustment.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| namespace Gui { | ||||
| 
 | ||||
| class Adjustment { | ||||
| public: | ||||
|   Adjustment(void): m_values(0) {} | ||||
|   float GetValue(void) { return m_value; } | ||||
|   void SetValue(float v) { m_value = (v>0?(v<1?v:1):0); } | ||||
| 
 | ||||
| private: | ||||
|   float m_value; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| @ -103,6 +103,15 @@ void Container::AppendChild(Widget* child, float x, float y) { | ||||
|   m_children.push_back(wp); | ||||
| } | ||||
| 
 | ||||
| void Container::RemoveChild(Widget* child) { | ||||
|   for(std::list<widget_pos>::iterator i = m_children.begin(); i != m_children.end(); ++i) { | ||||
|     if((*i).w == child) { | ||||
|       m_children.erase(i); | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void Container::Draw(void) { | ||||
|   for(std::list<widget_pos>::iterator i = m_children.begin(); i != m_children.end(); ++i) { | ||||
|     if(!(*i).w->IsVisible()) continue; | ||||
|  | ||||
| @ -15,12 +15,14 @@ namespace Gui { | ||||
|     virtual void Draw(void); | ||||
|     virtual void ShowAll(void); | ||||
|     virtual void HideAll(void); | ||||
|     virtual void OnChildResizeRequest(Widget*) = 0; | ||||
|   private: | ||||
|     void _OnMouseLeave(void); | ||||
|     bool HandleMouseEvent(MouseButtonEvent* e); | ||||
|   protected: | ||||
|     void PrependChild(Widget* w, float x, float y); | ||||
|     void AppendChild(Widget* w, float x, float y); | ||||
|     void RemoveChild(Widget* w); | ||||
| 
 | ||||
|     struct widget_pos { | ||||
|       Widget* w; | ||||
|  | ||||
| @ -20,29 +20,44 @@ Fixed::~Fixed(void) { | ||||
| } | ||||
| 
 | ||||
| void Fixed::Draw(void) { | ||||
|   float size[2]; | ||||
|   GetSize(size); | ||||
|   if(!m_transparent) { | ||||
|     glBegin(GL_QUADS); | ||||
|       glColor3f(m_bgcol[0], m_bgcol[1], m_bgcol[2]); | ||||
|       glVertex2f(0, m_h); | ||||
|       glVertex2f(m_w, m_h); | ||||
|       glVertex2f(m_w, 0); | ||||
|       glVertex2f(0, size[1]); | ||||
|       glVertex2f(size[0], size[1]); | ||||
|       glVertex2f(size[0], 0); | ||||
|       glVertex2f(0, 0); | ||||
|     glEnd(); | ||||
|   } | ||||
|   Container::Draw(); | ||||
| } | ||||
| 
 | ||||
| void Fixed::OnChildResizeRequest(Widget* child) { | ||||
|   for(std::list<widget_pos>::iterator i = m_children.begin(); i != m_children.end(); ++i) { | ||||
|     if((*i).w == child) { | ||||
|       float rsize[2] = { m_w - (*i).pos[0], | ||||
|                          m_h - (*i).pos[1] }; | ||||
|       child->GetSizeRequested(rsize); | ||||
|       if((*i).pos[0] + rsize[0] > m_w) rsize[0] = m_w - (*i).pos[0]; | ||||
|       if((*i).pos[1] + rsize[1] > m_h) rsize[1] = m_w - (*i).pos[1]; | ||||
|       child->SetSize(rsize[0], rsize[1]); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void Fixed::Add(Widget* child, float x, float y) { | ||||
|   AppendChild(child, x, y); | ||||
|   float rsize[2] = { m_w - x, m_h - y }; | ||||
|   child->GetSizeRequested(rsize); | ||||
|   if(x+rsize[0] > m_w) rsize[0] = m_w-x; | ||||
|   if(y+rsize[1] > m_h) rsize[1] = m_h-y; | ||||
|   child->SetSize(rsize[0], rsize[1]); | ||||
| } | ||||
| 
 | ||||
| void Fixed::Remove(Widget* child) { | ||||
|   for(std::list<widget_pos>::iterator i = m_children.begin(); i != m_children.end(); ++i) { | ||||
|     if((*i).w == child) { | ||||
|       m_children.erase(i); | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
|   Container::RemoveChild(child); | ||||
| } | ||||
| 
 | ||||
| void Fixed::SetBgColor(float rgb[3]) { | ||||
|  | ||||
| @ -13,6 +13,7 @@ namespace Gui { | ||||
|     virtual void Draw(void); | ||||
|     virtual ~Fixed(void); | ||||
|     virtual void GetSizeRequested(float size[2]); | ||||
|     virtual void OnChildResizeRequest(Widget*); | ||||
|     void SetBgColor(float rgb[3]); | ||||
|     void SetBgColor(float r, float g, float b); | ||||
|     void SetTransparency(bool a) { m_transparent = a; } | ||||
|  | ||||
| @ -3,19 +3,21 @@ | ||||
| namespace Gui { | ||||
| 
 | ||||
| Label::Label(const char* text) { | ||||
|   m_dlist = 0; | ||||
|   SetText(text); | ||||
|   m_color[0] = m_color[1] = m_color[2] = 1.0f; | ||||
| } | ||||
| 
 | ||||
| Label::Label(std::string& text) { | ||||
|   m_dlist = 0; | ||||
|   SetText(text); | ||||
|   m_color[0] = m_color[1] = m_color[2] = 1.0f; | ||||
| } | ||||
| 
 | ||||
| void Label::RecalcSize(void) { | ||||
|   float w, h; | ||||
|   Screen::MeasureString(m_text, w, h); | ||||
|   SetSize(w,h); | ||||
|   //float size[2];
 | ||||
|   //Screen::MeasureLayout(m_text, FLT_MAX, size);
 | ||||
|   ResizeRequest(); | ||||
| } | ||||
| 
 | ||||
| void Label::SetText(const char* text) { | ||||
| @ -29,24 +31,20 @@ void Label::SetText(std::string& text) { | ||||
| } | ||||
| 
 | ||||
| void Label::Draw(void) { | ||||
| #if 0 | ||||
|   float size[2]; GetSize(size); | ||||
|   glColor3f(1, 0, 0); | ||||
|   /*glColor3f(1, 0, 0);
 | ||||
|   glBegin(GL_QUADS); | ||||
|     glVertex2f(0, size[1]); | ||||
|     glVertex2f(size[0]), size[1]); | ||||
|     glVertex2f(size[0], 0); | ||||
|     glVertex2f(0, 0); | ||||
|   glEnd(); | ||||
| #endif /* 0 */ | ||||
|   glEnd();*/ | ||||
|   glColor3fv(m_color); | ||||
|   Screen::RenderMarkup(m_text); | ||||
|   //Screen::LayoutString(m_text, 400);
 | ||||
|   Screen::LayoutString(m_text, size[0]); | ||||
| } | ||||
| 
 | ||||
| void Label::GetSizeRequested(float size[2]) { | ||||
|   RecalcSize(); | ||||
|   GetSize(size); | ||||
|   Screen::MeasureLayout(m_text, size[0], size); | ||||
| } | ||||
| 
 | ||||
| void Label::SetColor(float r, float g, float b) { | ||||
|  | ||||
| @ -17,6 +17,7 @@ namespace Gui { | ||||
|     void RecalcSize(void); | ||||
|     std::string m_text; | ||||
|     float m_color[3]; | ||||
|     GLuint m_dlist; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -140,6 +140,19 @@ void Screen::MeasureString(const std::string& s, float& w, float& h) { | ||||
|   h *= fontScale; | ||||
| } | ||||
| 
 | ||||
| void Screen::MeasureLayout(const std::string& s, const float width, float outSize[2]) { | ||||
|   font->MeasureLayout(s.c_str(), width, outSize); | ||||
|   outSize[0] *= Screen::fontScale; | ||||
|   outSize[1] *= Screen::fontScale; | ||||
| } | ||||
| 
 | ||||
| void Screen::LayoutString(const std::string& s, const float width) { | ||||
|   glPushMatrix(); | ||||
|   glScalef(Screen::fontScale, Screen::fontScale, 1); | ||||
|   font->LayoutString(s.c_str(), width); | ||||
|   glPopMatrix(); | ||||
| } | ||||
| 
 | ||||
| void Screen::RenderString(const std::string& s) { | ||||
|   glPushMatrix(); | ||||
|   glScalef(Screen::fontScale, Screen::fontScale, 1); | ||||
|  | ||||
| @ -14,7 +14,8 @@ namespace Gui { | ||||
|     static void OnMouseMotion(SDL_MouseMotionEvent* e); | ||||
|     static void OnClick(SDL_MouseButtonEvent* e); | ||||
|     static void OnKeyDown(const SDL_keysym* sym); | ||||
|     static void LayoutString(const std::string& s, float width); | ||||
|     static void LayoutString(const std::string& s, const float width); | ||||
|     static void MeasureLayout(const std::string& s, const float width, float outSize[2]); | ||||
|     static void RenderString(const std::string& s); | ||||
|     static void MeasureString(const std::string& s, float& w, float& h); | ||||
|     static void RenderMarkup(const std::string& s); | ||||
|  | ||||
| @ -61,9 +61,8 @@ void ToolTip::Draw(void) { | ||||
| } | ||||
| 
 | ||||
| void ToolTip::GetSizeRequested(float size[2]) { | ||||
| #pragma message("Not setting size correctly.") | ||||
|   size[0] = 70; | ||||
|   size[1] = 10; | ||||
|   Screen::MeasureString(m_text, size[0], size[1]); | ||||
|   size[0] += 2 * TOOLTIP_PADDING; | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -109,6 +109,14 @@ void Widget::Hide(void) { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void Widget::ResizeRequest(void) { | ||||
|   if(m_parent) m_parent->OnChildrenResizeRequest(this); | ||||
|   else { | ||||
|     float size[2] = { FLT_MAX, FLT_MAX }; | ||||
|     GetSizeRequested(size); | ||||
|     SetSize(size[0], size[1]); | ||||
|   } | ||||
| 
 | ||||
| Widget::~Widget(void) { | ||||
|   if(m_tooltipWidget) { | ||||
|     Screen::RemoveBaseWidget(m_tooltipWidget); | ||||
|  | ||||
| @ -9,12 +9,17 @@ namespace Gui { | ||||
|     Widget(void); | ||||
|     virtual void Draw(void) = 0; | ||||
|     virtual ~Widget(void); | ||||
|     /**
 | ||||
|      * Containers call this on children. input: size[] will contain max permissable size | ||||
|      * output: size[] will contain what space the widget desires. | ||||
|      */ | ||||
|     virtual void GetSizeRequested(float size[2]) = 0; | ||||
|     void GetPosition(float pos[2]) const { pos[0] = m_size.x; pos[1] = m_size.y; } | ||||
|     void GetAbsolutePosition(float pos[2]); | ||||
|     void SetPosition(float x, float y)  { m_size.x = x; m_size.y = y; } | ||||
|     void GetSize(float size[2])         { size[0] = m_size.w; size[1] = m_size.h; } | ||||
|     void SetSize(float w, float h)      { m_size.w = w; m_size.h = h; }; | ||||
|     void ResizeRequest(void); | ||||
|     void SetShortcut(SDLKey key, SDLMod mod); | ||||
|     void SetClipping(float width, float height); | ||||
|     void EndClipping(void); | ||||
|  | ||||
| @ -31,6 +31,13 @@ private: | ||||
| StationFrontView::StationFrontView(SpaceStationView* parent): StationSubView(parent) { | ||||
|   SetTransparency(false); | ||||
| 
 | ||||
|   Gui::Fixed* fbox = new Gui::Fixed(720, 150); | ||||
|   Add(fbox, 40, 100); | ||||
| 
 | ||||
|   Gui::VScrollBar* scroll = new Gui::VScrollBar(); | ||||
|   Gui::VScrollPortal* box = new Gui::VScrollPortal(400, 150); | ||||
|   scroll->SetAdjustment(&box->vscollAdjust); | ||||
| 
 | ||||
|   Gui::Label* l = new Gui::Label("Hello friend! Thankyou for docking with this space station! " | ||||
|     "You may have noticed that the docking procedure was not entirely " | ||||
|     "physically correct. this is a result of unimplemented physics in this " | ||||
| @ -41,7 +48,12 @@ StationFrontView::StationFrontView(SpaceStationView* parent): StationSubView(par | ||||
|     "can offer you this promotional message from one of the station's sponsors: \n" | ||||
|     "         ADOPT A CAT: THEY CHEW IMPORTANT CABLES!"); | ||||
| 
 | ||||
|   Add(l, 40, 100); | ||||
| 
 | ||||
|   fbox->Add(box, 0, 0); | ||||
|   fbox->Add(scroll, 405, 0); | ||||
|   box->Add(l); | ||||
|   box->ShowAll(); | ||||
|   fbox->ShowAll(); | ||||
| 
 | ||||
|   Gui::SolidButton* b = new Gui::SolidButton(); | ||||
|   b->onClick.connect(sigc::mem_fun(this, &StationFrontView::OnClickRequestLaunch)); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Rtch90
						Rtch90