Пример #1
0
void PG_ListBox::SetAlignment(PG_Label::TextAlign style) {
	my_alignment = style;
	
	PG_RectList* list = my_scrollarea->GetChildList();
	if(list == NULL) {
		return;
	}
	
	for(PG_Widget* i = list->first(); i != NULL; i = i->next()) {
		static_cast<PG_ListBoxBaseItem*>(i)->SetAlignment(style);
	}
	Update();
}
Пример #2
0
void PG_ListBox::SetIndent(Uint16 indent) {
	my_indent = indent;
	PG_RectList* list = my_scrollarea->GetChildList();
	if(list == NULL) {
		return;
	}

	for(PG_Widget* w = list->first(); w != NULL; w = w->next()) {
		PG_ListBoxBaseItem* item = static_cast<PG_ListBoxBaseItem*>(w);
		item->SetIndent(my_indent);
	}
	Update();
}
Пример #3
0
void PG_ListBox::GetSelectedItems(std::vector<PG_ListBoxBaseItem*>& items) {
	PG_RectList* list = my_scrollarea->GetChildList();
	if(list == NULL) {
		return;
	}

	for(PG_Widget* i = list->first(); i != NULL; i = i->next()) {
		PG_ListBoxBaseItem* item = static_cast<PG_ListBoxBaseItem*>(i);
		if (item->IsSelected()) {
			items.push_back(item);	
		}
	}
}
Пример #4
0
int PG_WidgetList::FindIndex(PG_Widget* w) {
	int index = 0;

	PG_Widget* list = my_scrollarea->GetChildList()->first();
	for( ; list != NULL; list = list->next()) {
		if(list == w) {
			return index;
		}
		index++;
	}

	return -1;
}
Пример #5
0
bool PG_MessageObject::HandleEvent(SDL_Event *pEvent) // static
{
	if((pEvent->type != SDL_USEREVENT) && (pEvent->type != SDL_VIDEORESIZE)) {
		if(captureObject) {
			return captureObject->ProcessEvent(pEvent);
		}
	}

	PG_Widget* widget = NULL;
	
	switch(pEvent->type) 
	{

		case SDL_KEYDOWN:
		case SDL_KEYUP:
			if(inputFocusObject) {
				// first send it to the focus object
				if(inputFocusObject->ProcessEvent(pEvent)) {
					return true;
				}
				// if the focus object doesn't respond -> pump it into the queue
			}
			break;

		case SDL_MOUSEMOTION:
			widget = PG_Widget::FindWidgetFromPos(pEvent->motion.x, pEvent->motion.y);

			if(lastwidget && (lastwidget != widget)) {
				lastwidget->eventMouseLeave();
				lastwidget = NULL;
			}

			if(widget) {
				lastwidget = widget;
				widget->ProcessEvent(pEvent);
				return true;
			}
			return true;

		case SDL_MOUSEBUTTONUP:
		case SDL_MOUSEBUTTONDOWN:
			widget = PG_Widget::FindWidgetFromPos(pEvent->button.x, pEvent->button.y);
			if(widget) {
				widget->ProcessEvent(pEvent);
				return true;
			}
			break;
	}

	return false;
}
Пример #6
0
PG_ListBoxBaseItem::~PG_ListBoxBaseItem() {
	if(GetParent() == NULL) {
		return;
	}

	if(GetParent()->GetSelectedItem() == this) {
		GetParent()->SelectItem(NULL);
		//GetParent()->RemoveWidget(this, true, true);
	}

	for (PG_Widget* w = next(); w != NULL; w = w->next()) {
		w->SetID(w->GetID() - 1);
	}
}
Пример #7
0
PG_Widget* PG_WidgetList::FindWidget(int index) {

	if((index < 0) || (index >= GetWidgetCount())) {
		return NULL;
	}

	int i = 0;
	PG_Widget* list = my_scrollarea->GetChildList()->first();
	for( ; list != NULL; list = list->next()) {
		if(i == index) {
			return list;
		}
		i++;
	}

	return NULL;
}
Пример #8
0
PG_Widget* PG_WidgetList::GetWidgetFromPos(Sint32 y) {
	Uint32 dy = 0;
	Uint32 min_dy = 100000000;

	PG_Widget* result = NULL;

	PG_Widget* list = GetChildList()->first();
	for( ; list != NULL; list = list->next()) {
		dy = abs(0- (list->my_ypos - my_ypos));

		if(dy < min_dy) {
			min_dy = dy;
			result = list;
		}
	}

	return result;
}
Пример #9
0
int main( int argc, char **argv )
{
	PG_Application app;
	
	app.LoadTheme( "default" );
	
	app.InitScreen( 640, 480, 0 );
	app.SetEmergencyQuit(true);
	
	PG_Label l( NULL, PG_Rect(10,50,250,25), NULL );
	l.Show();
	
	PG_TabBar bar( NULL, PG_Rect(10, 10, 300, 33) );
	bar.sigTabSelect.connect(slot(handleTab), &l);
	bar.Show();
	
	bar.AddTab("Tab1");
	bar.AddTab("Tab2");
	bar.AddTab("Tab3");
	bar.AddTab("MoreTab1");
	bar.AddTab("MoreTab2");
	bar.AddTab("MoreTab3");
	bar.AddTab("EvenLongerTab1");
	bar.AddTab("Tab4");
	
	PG_NoteBook notebook(NULL, PG_Rect(50, 100, 300, 200));
	
	notebook.sigPageSelect.connect(slot(handlePageSelect));
	
	PG_Button b(NULL, 1, PG_Rect(0,0,10,10), "Big fat button");
	b.sigButtonClick.connect(slot(handleBigFatButton));
	
	notebook.AddPage("button", &b, slot(handlePageButton));
	
	PG_Widget* custom = notebook.CreatePage("custom", slot(handlePageCustom));
	custom->SetID(2);
	PG_Label label(custom, PG_Rect(5,5,100,25), "My Page");
	PG_CheckButton check(custom, -1, PG_Rect(5,35,150,25), "Check me");
	
	PG_ListBox listpage(NULL, PG_Rect(0,0,300,100));
	listpage.AddItem(new PG_ListBoxItem(25, "Item1"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item2"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item3"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item4"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item5"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item6"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item7"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item8"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item9"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item10"));
	listpage.SetID(3);
	
	notebook.AddPage("list", &listpage);

	PG_NoteBook subnotebook(NULL, PG_Rect(0,0,100,100));
	
	PG_Widget* complex = subnotebook.CreatePage("custom2");
	PG_Button b2(complex, -1, PG_Rect(10,10,100,25), "Button");
	
	subnotebook.AddPage("button2", new PG_Button(NULL, -1, 	PG_Rect(0,0,10,10), "Not so big button"));
	
	notebook.AddPage("complex", &subnotebook);
	
	notebook.Show();
	
	app.Run();
	
	return 0;
}
Пример #10
0
int main( int argc, char **argv ) {

    // create custom factory. key is "unsigned long"
    typedef PG_FactoryHolder<unsigned long> MyFactory;

    PG_Application app(argv[0]);

    app.LoadTheme( "default" );
    app.InitScreen( 640, 480, 0 );
    app.SetEmergencyQuit(true);

    // register classes (default factory, key "std::string")
    PG_Factory::RegisterClass<PG_ThemeWidget>("themewidget");
    PG_Factory::RegisterClass<PG_Button>("button");
    PG_Factory::RegisterClass<PG_Window>("window");
    PG_Factory::RegisterClass<PG_Label>("label");

    // register classes (custom factory)
    MyFactory::RegisterClass<PG_Label>(1);
    
    // create PG_ThemeWidget object
    PG_Widget* w = PG_Factory::CreateObject("themewidget");
    w->MoveWidget(PG_Rect(10,10,300,200));
    w->Show();

    // create PG_Button object
    PG_Widget* b = PG_Factory::CreateObject("button", w);
    b->MoveWidget(PG_Rect(100,100,150,30));
    b->SetText("Factory");
    b->Show();

    // create PG_Window object
    PG_Widget* wnd = PG_Factory::CreateObject("window");
    wnd->MoveWidget(PG_Rect(100,100,200,300));
    wnd->SetText("Window");

    // create PG_Label object (custom factory)
    PG_Widget* l = MyFactory::CreateObject(1, wnd);
    l->MoveWidget(PG_Rect(50,50,100,20));
    l->SetText("Label");
	
    wnd->Show();
	
    app.Run();

    return 0;
}