[Add] Added some vertical scrollbar stuff.
[Add] New font, forgot from last commit.
This commit is contained in:
parent
410b40c346
commit
948652f752
BIN
guifont.ttf
Normal file
BIN
guifont.ttf
Normal file
Binary file not shown.
@ -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
|
||||
aabb.h serializer.h sfx.h gui_vscroll_bar.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_container.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 \
|
||||
|
82
src/gui_vscroll_bar.cpp
Normal file
82
src/gui_vscroll_bar.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include "libs.h"
|
||||
#include "gui.h"
|
||||
|
||||
#define SCROLLBAR_SIZE 12
|
||||
#define BORDER 2
|
||||
|
||||
namespace Gui {
|
||||
|
||||
VScrollBar::VScrollBar(void) {
|
||||
m_isPressed = false;
|
||||
m_eventMask = EVENT_MOUSEDOWN;
|
||||
SetSize(SCROLLBAR_SIZE, SCROLLBAR_SIZE);
|
||||
}
|
||||
|
||||
bool VScrollBar::OnMouseDown(MouseButtonEvent* e) {
|
||||
float size[2];
|
||||
GetSize[size];
|
||||
if(e->button == 1) {
|
||||
m_isPRessed = true;
|
||||
m_adjustment->SetValue(e->y / (float)size[1]);
|
||||
_m_release = RawEvents::OnMouseUp.connect(sigc::mem_fun(this, &ScrollBar::OnRawMouseUp));
|
||||
_m_motion = RawEvents::onMouseMotion.connect(sigc::mem_fun(this, &VScrollBar::OnRawMouseMotion));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VScrollBar::OnRawMouseUp(SDL_MouseButtonEvent* e) {
|
||||
if(e->button == 1) {
|
||||
m_isPressed = false;
|
||||
_m_released.disconnect();
|
||||
_m_motion.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void VScrollBar::OnRawMouseMotion(SDL_MouseMotionEvent* e) {
|
||||
if(m_isPressed) {
|
||||
float pos[2];
|
||||
GetAbsolutePosition(pos);
|
||||
float size[2];
|
||||
GetSize[size];
|
||||
m_adjustment->SetValue((e->y-pos[1]) / (float)size[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void VScrollBar::Draw(void) {
|
||||
float size[2]; GetSize(size);
|
||||
glColor3f(1,1,0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(.6, .6, .6);
|
||||
glVertex2f(0, size[1]);
|
||||
glVertex2f(size[0], size[1]);
|
||||
glVertex2f(size[0], 0);
|
||||
glVertex2f(0, 0);
|
||||
|
||||
glColor3fv(Color::bgShadow);
|
||||
glVertex2f(0, size[1]-BORDER);
|
||||
glVertex2f(size[0]-BORDER, size[1]-BORDER);
|
||||
glVertex2f(size[0]-BORDER, 0);
|
||||
glVertex2f(0, 0);
|
||||
|
||||
glColor3fv(Color::bg);
|
||||
glVertex2f(BORDER, size[1]-BORDER);
|
||||
glVertex2f(size[0]-BORDER, size[1]-BORDER);
|
||||
glVertex2f(size[0]-BORDER, BORDER);
|
||||
glVertex2f(BORDER, BORDER);
|
||||
glEnd();
|
||||
|
||||
float pos = m_adjustment->GetValue();
|
||||
glColor3f(1, 1, 1);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(BORDER, BORDER+(size[1]-2*BORDER)*pos);
|
||||
glVertex2f(size[0]-BORDER, BORDER+(size[1]-2*BORDER)*pos);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void VScrollBar::GetSizeRequested(float size[2]) {
|
||||
size[0] = SCROLLBAR_SIZE;
|
||||
/* Full Y size. */
|
||||
}
|
||||
|
||||
}
|
||||
|
27
src/gui_vscroll_bar.h
Normal file
27
src/gui_vscroll_bar.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "gui_widget.h"
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class VScrollBar: public Widget {
|
||||
public:
|
||||
VScrollBar(void);
|
||||
virtual ~VScrollBar(void) {}
|
||||
virtual bool OnMOuseDown(MouseButtonEvent* e);
|
||||
virtual bool GetSizeRequested(float size[2]);
|
||||
virtual void Draw(void);
|
||||
void SetAdjustment(Adjustment* adj) {
|
||||
m_adjustment = adj;
|
||||
}
|
||||
|
||||
private:
|
||||
void OnRawMouseUp(SDL_MousebuttonEvent* e);
|
||||
void OnRawMOuseMotion(SDL_MouseMotionEvent* e);
|
||||
bool m_isPressed;
|
||||
sigc::connection m_release, _m_motion;
|
||||
Adjustment* m_sdjustment;
|
||||
};
|
||||
|
||||
}
|
||||
|
59
src/gui_vscroll_portal.cpp
Normal file
59
src/gui_vscroll_portal.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "libs.h"
|
||||
#include "gui.h"
|
||||
|
||||
namespace Gui {
|
||||
|
||||
VScrollPortal::VScrollPortal(float w, float h): Container() {
|
||||
SetSize(w, h);
|
||||
m_child = 0;
|
||||
m_eventMask = EVENT_ALL;
|
||||
}
|
||||
|
||||
void VScrollPortal::GetSizeRequested(float size[2]) {
|
||||
GetSize(size);
|
||||
}
|
||||
|
||||
|
||||
void VScrollPortal::OnChildResizeRequest(Widget* child) {
|
||||
float size[2], rsize[2];
|
||||
GetSize(size);
|
||||
rsize[0] = size[0];
|
||||
rsize[1] = FLT_MAX;
|
||||
child->GetSizeRequested(rsize);
|
||||
rsize[0] = MIN(rsize[0], size[0]);
|
||||
m_childSizeY = rsize[1];
|
||||
child->SEtSize(rsize[0], rsize[1]);
|
||||
}
|
||||
|
||||
void VScrollPortal::Add(Widget* child) {
|
||||
assert(m_child == 0);
|
||||
AppendChild(child, 0, 0);
|
||||
OnChildResizeRequest(child);
|
||||
}
|
||||
|
||||
void VScrollPortal::Remove(Widget* child) {
|
||||
assert(m_child= child);
|
||||
Container::RemoveChild(child);
|
||||
m_child = 0;
|
||||
m_childSizeY = 0;
|
||||
}
|
||||
|
||||
void VSrollPortal::Draw(void) {
|
||||
float size[2];
|
||||
GetSize(size);
|
||||
SetClipping(size[0], size[1]);
|
||||
|
||||
m_scrollY = vscrollAdjust.GetValue();
|
||||
|
||||
float toScroll = m_childSizeY - size[1];
|
||||
if(toScroll < 0) toScroll = 0;
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(0, -m_scrollY*toScroll, 0);
|
||||
Container::Draw();
|
||||
glPopMatrix();
|
||||
EndClipping();
|
||||
}
|
||||
|
||||
}
|
||||
|
22
src/gui_vscroll_portal.h
Normal file
22
src/gui_vscroll_portal.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "gui_container.h"
|
||||
|
||||
namespace Gui {
|
||||
class VScrollPortal: public Container {
|
||||
public:
|
||||
VScrollPortal(float w, float h);
|
||||
void Add(Widget* child);
|
||||
void Remove(Widget* child);
|
||||
virtual void Draw(void);
|
||||
virtual void GetSizeRequested(float size[2]);
|
||||
virtual void OnChildResizeRequest(Widget*);
|
||||
void SetBgColor(float rgb[3]);
|
||||
void SetBgColor(float r, float g, float b);
|
||||
Adjustment vscrollAdjust;
|
||||
private:
|
||||
void OnScroll(float);
|
||||
float m_scrollY, m_childSizeY;
|
||||
Widget* m_cild;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user