xref: /haiku/src/tests/kits/opengl/glinfo/ExtensionsView.cpp (revision 23d878482ed22e55dad6d1fca1df7bea42eb157c)
1 /*
2  * Copyright 2009-2012 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		John Scipione <jscipione@gmail.com>
7  *		Alex Wilson <yourpalal2@gmail.com>
8  *		Artur Wyszynski <harakash@gmail.com>
9  */
10 
11 
12 #include "ExtensionsView.h"
13 
14 #include <Catalog.h>
15 #include <GL/gl.h>
16 #include <GL/glu.h>
17 #include <GroupLayout.h>
18 #include <GroupLayoutBuilder.h>
19 #include <Locale.h>
20 #include <Message.h>
21 #include <SpaceLayoutItem.h>
22 #include <String.h>
23 
24 
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "Extensions"
27 
28 
29 ExtensionsView::ExtensionsView()
30 	:
31 	BGroupView(B_TRANSLATE("Extensions"), B_VERTICAL),
32 	fExtensionsList(new BColumnListView("ExtensionsList", 0))
33 {
34 	// add the columns
35 
36 	float availableColWidth = this->StringWidth("M") * 28;
37 
38 	fAvailableColumn = new BStringColumn(B_TRANSLATE("Available extensions"),
39 		availableColWidth, availableColWidth, availableColWidth,
40 		B_TRUNCATE_MIDDLE);
41 	fExtensionsList->AddColumn(fAvailableColumn, 0);
42 	fExtensionsList->SetSortingEnabled(true);
43 	fExtensionsList->SetSortColumn(fAvailableColumn, true, true);
44 
45 	// add the rows
46 
47 	_AddExtensionsList(fExtensionsList, (char*)glGetString(GL_EXTENSIONS));
48 	_AddExtensionsList(fExtensionsList, (char*)gluGetString(GLU_EXTENSIONS));
49 
50 	// add the list
51 
52 	AddChild(fExtensionsList);
53 	GroupLayout()->SetInsets(5.0, 5.0, 5.0, 5.0);
54 }
55 
56 
57 ExtensionsView::~ExtensionsView()
58 {
59 	BRow *row;
60 	while ((row = fExtensionsList->RowAt((int32)0, NULL)) != NULL) {
61 		fExtensionsList->RemoveRow(row);
62 		delete row;
63 	}
64 	delete fAvailableColumn;
65 	delete fExtensionsList;
66 }
67 
68 
69 //	#pragma mark -
70 
71 
72 void
73 ExtensionsView::_AddExtensionsList(BColumnListView* fExtensionsList, char* stringList)
74 {
75 	if (stringList == NULL) {
76 		// empty extensions string
77 		return;
78 	}
79 
80 	while (*stringList != '\0') {
81 		char extName[255];
82 		int n = strcspn(stringList, " ");
83 		strncpy(extName, stringList, n);
84 		extName[n] = 0;
85 		BRow* row = new BRow();
86 		row->SetField(new BStringField(extName), 0);
87 		fExtensionsList->AddRow(row);
88 		if (!stringList[n])
89 			break;
90 		stringList += (n + 1);
91 			// next !
92 	}
93 }
94