// // Model List Box Handlers // private void OnModelListDoubleClick(object sender, EventArgs e) { String modelName = (String)modelListBox.SelectedItem; // TODO: Not really sure how to handle errors // if either of these functions fail. LOLModel model = reader.GetModel(modelName); if (model != null) { bool result = renderer.LoadModel(model, logger); currentAnimationComboBox.Items.Clear(); foreach (String name in renderer.GetAnimations()) { currentAnimationComboBox.Items.Add(name); } currentAnimationComboBox.Text = ""; if (currentAnimationComboBox.Items.Count > 0) { currentAnimationComboBox.SelectedIndex = 0; } animationController.DisableAnimation(); // Update status bar text. mainWindowStatusLabel.Text = "Viewing " + modelName + ". Left mouse rotates, right mouse pans, and mouse wheel zooms."; } OnResetCameraButtonClick(sender, e); GLControlMainOnUpdateFrame(sender, e); }
public MainWindow() { logger = new Logger(DEFAULT_LOG_FILE); // Not checking result. logger.Event("Program Start."); isGLLoaded = false; timer = new Stopwatch(); camera = new GLCamera(); camera.SetViewParameters(new Vector3(0.0f, 0.0f, 2.0f), Vector3.Zero); renderer = new GLRenderer(); // Set up the reader and initialize its root to the value in 'lolviewer.dat' if // the file exists. { reader = new LOLDirectoryReader(); bool isFileOpen = false; FileStream file = null; try { FileInfo fileInfo = new FileInfo(DEFAULT_DATA_FILE); if (fileInfo.Exists == true) { file = new FileStream(fileInfo.FullName, FileMode.Open); isFileOpen = true; } else { logger.Warning("Failed to locate " + DEFAULT_DATA_FILE + "."); } } catch { logger.Warning("Failed to open " + DEFAULT_DATA_FILE + "."); } if (isFileOpen == true) { BinaryReader fileReader = null; if (file != null) { try { logger.Event("Reading " + DEFAULT_DATA_FILE + "."); fileReader = new BinaryReader(file); reader.Root = fileReader.ReadString(); fileReader.Close(); } catch { logger.Warning("Failed to read " + DEFAULT_DATA_FILE + "."); file.Close(); } } } } InitializeComponent(); mainWindowProgressBar.Style = ProgressBarStyle.Marquee; mainWindowProgressBar.Value = 100; lastSearch = String.Empty; currentSearchSubset = new List <String>(); // Main window Callbacks this.Shown += new EventHandler(OnMainWindowShown); // GLControl Callbacks glControlMain.Load += new EventHandler(GLControlMainOnLoad); glControlMain.Resize += new EventHandler(GLControlMainOnResize); glControlMain.Paint += new PaintEventHandler(GLControlMainOnPaint); glControlMain.Disposed += new EventHandler(GLControlMainOnDispose); // Set mouse events glControlMain.MouseDown += new MouseEventHandler(GLControlOnMouseDown); glControlMain.MouseUp += new MouseEventHandler(GLControlOnMouseUp); glControlMain.MouseWheel += new MouseEventHandler(GLControlOnMouseWheel); glControlMain.MouseMove += new MouseEventHandler(GLControlOnMouseMove); // Set keyboard events glControlMain.KeyDown += new KeyEventHandler(GLControlMainOnKeyDown); glControlMain.KeyUp += new KeyEventHandler(GLControlMainOnKeyUp); // Menu Callbacks exitToolStripMenuItem.Click += new EventHandler(OnExit); aboutToolStripMenuItem.Click += new EventHandler(OnAbout); readDirectoryMainMenuStripItem.Click += new EventHandler(OnReadModels); readMainMenuStripItem.Click += new EventHandler(OnSetDirectory); // Model View Callbacks modelListBox.DoubleClick += new EventHandler(OnModelListDoubleClick); modelListBox.KeyPress += new KeyPressEventHandler(OnModelListKeyPress); // Buttons resetCameraButton.Click += new EventHandler(OnResetCameraButtonClick); backgroundColorButton.Click += new EventHandler(OnBackgroundColorButtonClick); fullscreenButton.Click += new EventHandler(OnFullscreenButtonClick); // // Animation Controller // // TODO: Pass the references and callbacks into constructor instead of doing them out here. // Kind of ugly code. :( animationController = new AnimationController(); // Set references animationController.enableAnimationButton = enableAnimationButton; animationController.currentAnimationComboBox = currentAnimationComboBox; animationController.playAnimationButton = playAnimationButton; animationController.glControlMain = glControlMain; animationController.timelineTrackBar = timelineTrackBar; animationController.mainWindowStatusLabel = mainWindowStatusLabel; animationController.renderer = renderer; // Set callbacks. enableAnimationButton.Click += new EventHandler(animationController.OnEnableAnimationButtonClick); playAnimationButton.Click += new EventHandler(animationController.OnPlayAnimationButtonClick); currentAnimationComboBox.SelectedIndexChanged += new EventHandler(animationController.OnCurrentAnimationComboBoxSelectedIndexChanged); timelineTrackBar.Scroll += new EventHandler(animationController.OnTimelineTrackBar); animationController.DisableAnimation(); // // End Animation Controller // // Search Box modelSearchBox.TextChanged += new EventHandler(OnModelSearchBoxTextChanged); modelSearchBox.KeyPress += new KeyPressEventHandler(OnModelSearchBoxKeyPress); modelSearchBox.KeyDown += new KeyEventHandler(OnModelSearchBoxKeyDown); }
public MainWindow() { logger = new Logger(DEFAULT_LOG_FILE); // Not checking result. logger.Event("Program Start."); isGLLoaded = false; timer = new Stopwatch(); camera = new GLCamera(); camera.SetViewParameters(new Vector3(0.0f, 0.0f, 2.0f), Vector3.Zero); renderer = new GLRenderer(); // Set up the reader and initialize its root to the value in 'lolviewer.dat' if // the file exists. { reader = new LOLDirectoryReader(); bool isFileOpen = false; FileStream file = null; try { FileInfo fileInfo = new FileInfo(DEFAULT_DATA_FILE); if (fileInfo.Exists == true) { file = new FileStream(fileInfo.FullName, FileMode.Open); isFileOpen = true; } else { logger.Warning("Failed to locate " + DEFAULT_DATA_FILE + "."); } } catch { logger.Warning("Failed to open " + DEFAULT_DATA_FILE + "."); } if (isFileOpen == true) { BinaryReader fileReader = null; if (file != null) { try { logger.Event("Reading " + DEFAULT_DATA_FILE + "."); fileReader = new BinaryReader(file); reader.Root = fileReader.ReadString(); fileReader.Close(); } catch { logger.Warning("Failed to read " + DEFAULT_DATA_FILE + "."); file.Close(); } } } } InitializeComponent(); mainWindowProgressBar.Style = ProgressBarStyle.Marquee; mainWindowProgressBar.Value = 100; lastSearch = String.Empty; currentSearchSubset = new List<String>(); // Main window Callbacks this.Shown += new EventHandler(OnMainWindowShown); // GLControl Callbacks glControlMain.Load += new EventHandler(GLControlMainOnLoad); glControlMain.Resize += new EventHandler(GLControlMainOnResize); glControlMain.Paint += new PaintEventHandler(GLControlMainOnPaint); glControlMain.Disposed += new EventHandler(GLControlMainOnDispose); // Set mouse events glControlMain.MouseDown += new MouseEventHandler(GLControlOnMouseDown); glControlMain.MouseUp += new MouseEventHandler(GLControlOnMouseUp); glControlMain.MouseWheel += new MouseEventHandler(GLControlOnMouseWheel); glControlMain.MouseMove += new MouseEventHandler(GLControlOnMouseMove); // Set keyboard events glControlMain.KeyDown += new KeyEventHandler(GLControlMainOnKeyDown); glControlMain.KeyUp += new KeyEventHandler(GLControlMainOnKeyUp); // Menu Callbacks exitToolStripMenuItem.Click += new EventHandler(OnExit); aboutToolStripMenuItem.Click += new EventHandler(OnAbout); readDirectoryMainMenuStripItem.Click += new EventHandler(OnReadModels); readMainMenuStripItem.Click += new EventHandler(OnSetDirectory); // Model View Callbacks modelListBox.DoubleClick += new EventHandler(OnModelListDoubleClick); modelListBox.KeyPress += new KeyPressEventHandler(OnModelListKeyPress); // Buttons resetCameraButton.Click += new EventHandler(OnResetCameraButtonClick); backgroundColorButton.Click += new EventHandler(OnBackgroundColorButtonClick); fullscreenButton.Click += new EventHandler(OnFullscreenButtonClick); // // Animation Controller // // TODO: Pass the references and callbacks into constructor instead of doing them out here. // Kind of ugly code. :( animationController = new AnimationController(); // Set references animationController.enableAnimationButton = enableAnimationButton; animationController.currentAnimationComboBox = currentAnimationComboBox; animationController.playAnimationButton = playAnimationButton; animationController.glControlMain = glControlMain; animationController.timelineTrackBar = timelineTrackBar; animationController.mainWindowStatusLabel = mainWindowStatusLabel; animationController.renderer = renderer; // Set callbacks. enableAnimationButton.Click += new EventHandler(animationController.OnEnableAnimationButtonClick); playAnimationButton.Click += new EventHandler(animationController.OnPlayAnimationButtonClick); currentAnimationComboBox.SelectedIndexChanged += new EventHandler(animationController.OnCurrentAnimationComboBoxSelectedIndexChanged); timelineTrackBar.Scroll += new EventHandler(animationController.OnTimelineTrackBar); animationController.DisableAnimation(); // // End Animation Controller // // Search Box modelSearchBox.TextChanged += new EventHandler(OnModelSearchBoxTextChanged); modelSearchBox.KeyPress += new KeyPressEventHandler(OnModelSearchBoxKeyPress); modelSearchBox.KeyDown += new KeyEventHandler(OnModelSearchBoxKeyDown); }