summaryrefslogtreecommitdiff
path: root/src/main.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.vala')
-rw-r--r--src/main.vala452
1 files changed, 13 insertions, 439 deletions
diff --git a/src/main.vala b/src/main.vala
index 5c621b3..3329726 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -21,443 +21,6 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. */
using Emulation;
-using Gtk;
-
-namespace GUI
-{
- public class MainWindow : Window
- {
- private static const string xml_ui = """
- <?xml version="1.0"?>
- <interface>
- <requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy project-wide -->
- <object class="GtkUIManager" id="uimanager1">
- <child>
- <object class="GtkActionGroup" id="actiongroup1">
- <child>
- <object class="GtkAction" id="New">
- <property name="name">New</property>
- <property name="stock_id">gtk-new</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="Open">
- <property name="name">Open</property>
- <property name="stock_id">gtk-open</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="Save">
- <property name="name">Save</property>
- <property name="stock_id">gtk-save</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="SaveAs">
- <property name="name">SaveAs</property>
- <property name="stock_id">gtk-save-as</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="Quit">
- <property name="name">Quit</property>
- <property name="stock_id">gtk-quit</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="ViewCS">
- <property name="name">ViewCS</property>
- <property name="label">_View CS</property>
- <property name="tooltip">View the selected command stream.</property>
- <property name="icon_name">gtk-open</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="RemoveCS">
- <property name="name">RemoveCS</property>
- <property name="label">_Remove CS</property>
- <property name="tooltip">Remove the selected command stream from the current project.</property>
- <property name="icon_name">gtk-delete</property>
- </object>
- <accelerator key="Delete"/>
- </child>
- <child>
- <object class="GtkAction" id="ImportCS">
- <property name="name">ImportCS</property>
- <property name="label">_Import CS</property>
- <property name="tooltip">Import a new command stream to the current project.</property>
- <property name="icon_name">gtk-add</property>
- </object>
- <accelerator key="i" modifiers="GDK_CONTROL_MASK"/>
- </child>
- <child>
- <object class="GtkAction" id="ExportCS">
- <property name="name">ExportCS</property>
- <property name="label">_Export CS</property>
- <property name="tooltip">Export the selected command stream to a file.</property>
- <property name="icon_name">gtk-convert</property>
- </object>
- <accelerator key="e" modifiers="GDK_CONTROL_MASK"/>
- </child>
- <child>
- <object class="GtkAction" id="About">
- <property name="name">About</property>
- <property name="stock_id">gtk-about</property>
- </object>
- <accelerator key="F1"/>
- </child>
- <child>
- <object class="GtkAction" id="FileMenu">
- <property name="name">FileMenu</property>
- <property name="label" translatable="yes">_File</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="EditMenu">
- <property name="name">EditMenu</property>
- <property name="label" translatable="yes">_Edit</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="HelpMenu">
- <property name="name">HelpMenu</property>
- <property name="label" translatable="yes">_Help</property>
- </object>
- </child>
- </object>
- </child>
- <ui>
- <menubar name="menubar1">
- <menu action="FileMenu" name="FileMenu">
- <menuitem action="New" name="New"/>
- <menuitem action="Open" name="Open"/>
- <menuitem action="Save" name="Save"/>
- <menuitem action="SaveAs" name="SaveAs"/>
- <separator/>
- <menuitem action="Quit" name="Quit"/>
- </menu>
- <menu action="EditMenu" name="EditMenu">
- <menuitem action="ViewCS" name="ViewCS"/>
- <menuitem action="ImportCS" name="ImportCS"/>
- <menuitem action="ExportCS" name="ExportCS"/>
- <separator/>
- <menuitem action="RemoveCS" name="RemoveCS"/>
- </menu>
- <menu action="HelpMenu" name="HelpMenu">
- <menuitem action="About" name="About"/>
- </menu>
- </menubar>
- <toolbar name="toolbar1">
- <toolitem action="New" name="New"/>
- <toolitem action="Open" name="Open"/>
- <toolitem action="Save" name="Save"/>
- <separator/>
- <toolitem action="ImportCS" name="ImportCS"/>
- <toolitem action="ExportCS" name="ExportCS"/>
- <separator/>
- <toolitem action="RemoveCS" name="RemoveCS"/>
- </toolbar>
- <popup name="popup1">
- <menuitem action="ViewCS" name="ViewCS"/>
- <menuitem action="ExportCS" name="ExportCS"/>
- <separator/>
- <menuitem action="RemoveCS" name="RemoveCS"/>
- </popup>
- </ui>
- </object>
- <object class="GtkVBox" id="mainbox">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object constructor="uimanager1" class="GtkMenuBar" id="menubar1">
- <property name="visible">True</property>
- <child internal-child="accessible">
- <object class="AtkObject" id="a11y-menubar">
- <property name="AtkObject::accessible-name">The menubar</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- </packing>
- </child>
- <child>
- <object constructor="uimanager1" class="GtkToolbar" id="toolbar1">
- <property name="visible">True</property>
- <child internal-child="accessible">
- <object class="AtkObject" id="a11y-toolbar">
- <property name="AtkObject::accessible-name">The toolbar</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
- <child>
- <object class="GtkTreeView" id="cs_list">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="reorderable">True</property>
- <property name="model">cs_store</property>
- <child>
- <object class="GtkTreeViewColumn" id="pkts_column">
- <property name="title">Packets</property>
- <child>
- <object class="GtkCellRendererText" id="pkts_cell"/>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn1">
- <property name="title">Name</property>
- <child>
- <object class="GtkCellRendererText" id="cellrenderertext1"/>
- <attributes>
- <attribute name="text">0</attribute>
- </attributes>
- </child>
- </object>
- </child>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- </object>
- <object class="GtkListStore" id="cs_store">
- <columns>
- <!-- column-name Name -->
- <column type="gchararray"/>
- <!-- column-name CS -->
- <column type="GObject"/>
- </columns>
- </object>
- <object constructor="uimanager1" class="GtkMenu" id="popup1">
- <child internal-child="accessible">
- <object class="AtkObject" id="a11y-popup">
- <property name="AtkObject::accessible-name">The popup menu</property>
- </object>
- </child>
- </object>
- </interface>
- """;
-
- private static const string about_xml_ui = """
- <?xml version="1.0"?>
- <interface>
- <requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy project-wide -->
- <object class="GtkAboutDialog" id="about_dialog">
- <property name="border_width">5</property>
- <property name="type_hint">normal</property>
- <property name="skip_taskbar_hint">True</property>
- <property name="has_separator">False</property>
- <property name="program_name">Radeon Simulator</property>
- <property name="copyright" translatable="yes">Copyright &#xA9; 2010 Joakim Sindholt</property>
- <property name="comments" translatable="yes">A simulator for Radeon GPUs</property>
- <property name="website">http://cgit.freedesktop.org/~jsindholt/rsim</property>
- <property name="license" translatable="yes">This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</property>
- <property name="authors">Joakim Sindholt &lt;opensource@zhasha.com&gt;</property>
- <property name="logo">/usr/share/pixmaps/rsim.png</property>
- <property name="wrap_license">True</property>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox1">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area1">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- </object>
- </interface>
- """;
-
- private ListStore cs_store;
- private TreeView cs_list;
- private Menu edit_menu;
-
- private Action action_viewcs;
- private Action action_exportcs;
- private Action action_removecs;
-
- construct {
- var builder = new Builder();
- try {
- builder.add_from_string(xml_ui, xml_ui.length);
- } catch (Error e) {
- stderr.printf("Unable to construct main window: %s.\n", e.message);
- assert(false);
- }
- set_size_request(400, 200);
- title = "Radeon Simulator";
-
- /* Packets column */
- var col = builder.get_object("pkts_column") as TreeViewColumn;
- var cell = builder.get_object("pkts_cell") as CellRendererText;
- col.set_cell_data_func(cell, (col, cell, model, iter) => {
- CS cs;
- model.get(iter, 1, out cs, -1);
- assert(cs != null);
- (cell as CellRendererText).text = cs.length.to_string();
- });
-
- /* connect actions */
- action_viewcs = builder.get_object("ViewCS") as Action;
- action_exportcs = builder.get_object("ExportCS") as Action;
- action_removecs = builder.get_object("RemoveCS") as Action;
- var action_importcs = builder.get_object("ImportCS") as Action;
-
- action_viewcs.activate.connect((source) => { open_csview(); });
- action_importcs.activate.connect((source) => { var d = new CSImport(); d.run(); });
- action_exportcs.activate.connect((source) => { open_csexport(); });
- action_removecs.activate.connect((source) => { remove_cs(); });
-
- /* about dialog is kind of a special case. */
- (builder.get_object("About") as Action).activate.connect((source) => {
- var about = new Builder();
- try {
- about.add_from_string(about_xml_ui, about_xml_ui.length);
- var dlg = about.get_object("about_dialog") as AboutDialog;
- dlg.run();
- dlg.destroy();
- } catch (Error e) { }
- });
-
- /* menus */
- cs_store = builder.get_object("cs_store") as ListStore;
- cs_list = builder.get_object("cs_list") as TreeView;
- edit_menu = builder.get_object("popup1") as Menu;
- /* double clicking a row */
- cs_list.row_activated.connect((path, column) => { open_csview(); });
- /* right clicking */
- cs_list.button_press_event.connect((event) => {
- CS? cs = get_selected_cs();
- if (cs != null && event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3) {
- edit_menu.popup(null, null, null, event.button, event.time);
- }
- });
- /* selecting something */
- cs_list.cursor_changed.connect((source) => {
- edit_set_sensitive(cs_list.get_selection().get_selected(null, null));
- });
- edit_set_sensitive(false);
-
- add(builder.get_object("mainbox") as Widget);
- destroy.connect(main_quit);
-
- try {
- /* XXX This shouldn't be hardcoded */
- set_icon_from_file("/usr/share/pixmaps/rsim.png");
- } catch (Error e) { /* don't care */ }
- }
-
- private void edit_set_sensitive(bool setting)
- {
- action_viewcs.sensitive = setting;
- action_exportcs.sensitive = setting;
- action_removecs.sensitive = setting;
- }
-
- private CS? get_selected_cs()
- {
- TreeIter iter;
- CS cs;
-
- var selection = cs_list.get_selection();
- if (!selection.get_selected(null, out iter)) { return null; }
-
- cs_store.get(iter, 1, out cs, -1);
- return cs;
- }
-
- public void add_cs(string name, CS cs)
- {
- TreeIter iter;
- cs_store.append(out iter);
- cs_store.set(iter, 0, name, 1, cs, -1);
- }
-
- public void remove_cs()
- {
- TreeIter iter;
- string name;
-
- var selection = cs_list.get_selection();
- if (!selection.get_selected(null, out iter)) { return; }
- cs_store.get(iter, 0, out name, -1);
-
- var d = new MessageDialog(this, DialogFlags.DESTROY_WITH_PARENT,
- MessageType.QUESTION, ButtonsType.YES_NO,
- "Are you sure you want to delete the command stream '%s'", name);
- int result = d.run();
- d.destroy();
- if (result != ResponseType.YES) { return; }
-
- cs_store.remove(iter);
- }
-
- private void open_csview()
- {
- CS? cs = get_selected_cs();
- if (cs != null) {
- var csv = new CSView(cs);
- csv.show_all();
- }
- }
-
- private void open_csexport()
- {
- CS? cs = get_selected_cs();
- if (cs != null) {
- var d = new CSExport(cs);
- d.run();
- }
- }
- }
-
- public static MainWindow main;
-
- static void init(ref weak string[] args)
- {
- Gtk.init(ref args);
-
- specs = new SpecEntry[2];
- specs[0].spec = new Spec("/usr/share/rsim/r300reg.xml", "r300");
- specs[0].name = "r300";
- specs[1].spec = new Spec("/usr/share/rsim/r300reg.xml", "r500");
- specs[1].name = "r500";
-
- main = new MainWindow();
- main.show_all();
-
- Gtk.main();
- }
-}
namespace Emulation
{
@@ -473,13 +36,24 @@ namespace Emulation
public static int main(string[] args)
{
- GUI.init(ref args);
+ Gtk.init(ref args);
+
+ /* XXX these paths shouldn't be hardcoded */
+ specs = new SpecEntry[2];
+ specs[0].spec = new Spec("/usr/share/rsim/r300reg.xml", "r300");
+ specs[0].name = "r300";
+ specs[1].spec = new Spec("/usr/share/rsim/r300reg.xml", "r500");
+ specs[1].name = "r500";
+
+ var main = new Project.Window();
+ main.show_all();
+
+ Gtk.main();
/* vala doesn't unref globals */
for (uint i = 0; i < specs.length; i++) {
specs[i].spec.unref();
}
- GUI.main.unref();
return 0;
}