From 9d3221abf1ba10f7228b6006cf4fdd64aedd4ddd Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 17 Aug 1998 09:16:28 +0000 Subject: [PATCH] GTK's toolbar class has no OnPaint Added missing bitmap in mdi sample Added OpenGL support (I Get segv on my Debian/Mesa system, don't know why). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@568 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/mdi/bitmaps/paste.xpm | 27 ++++++ utils/dialoged/src/reseditr.cpp | 9 ++ utils/glcanvas/Makefile | 1 + utils/glcanvas/src/.cvsignore | 3 + utils/glcanvas/src/Makefile | 1 + utils/glcanvas/src/Makefile.in | 44 +++++++++ utils/glcanvas/src/glcanvas.cpp | 161 ++++++++++++++++++++++++++++++++ utils/glcanvas/src/glcanvas.h | 98 +++++++++++++++++++ 8 files changed, 344 insertions(+) create mode 100644 samples/mdi/bitmaps/paste.xpm create mode 100644 utils/glcanvas/Makefile create mode 100644 utils/glcanvas/src/.cvsignore create mode 100644 utils/glcanvas/src/Makefile create mode 100644 utils/glcanvas/src/Makefile.in create mode 100644 utils/glcanvas/src/glcanvas.cpp create mode 100644 utils/glcanvas/src/glcanvas.h diff --git a/samples/mdi/bitmaps/paste.xpm b/samples/mdi/bitmaps/paste.xpm new file mode 100644 index 0000000000..69177e9b19 --- /dev/null +++ b/samples/mdi/bitmaps/paste.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char *paste_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 6 1", +" c None", +". c Black", +"X c Yellow", +"o c #808080", +"O c #000080", +"+ c Gray100", +/* pixels */ +" ", +" .... ", +" .....XX..... ", +".ooo.X..X.ooo. ", +".oo. .oo. ", +".oo........oo. ", +".oooooooooooo. ", +".oooooOOOOOOO. ", +".oooooO+++++OO ", +".oooooO+++++O+O ", +".oooooO+OOO+OOO ", +".oooooO+++++++O ", +".oooooO+OOOOO+O ", +" .....O+++++++O ", +" OOOOOOOOO " +}; diff --git a/utils/dialoged/src/reseditr.cpp b/utils/dialoged/src/reseditr.cpp index c112a89b23..cf9467e0d4 100644 --- a/utils/dialoged/src/reseditr.cpp +++ b/utils/dialoged/src/reseditr.cpp @@ -2187,10 +2187,19 @@ void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event) * */ +#ifdef __WXGTK__ // I don't dare to delete it... + +BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar) +END_EVENT_TABLE() + +#else + BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar) EVT_PAINT(EditorToolBar::OnPaint) END_EVENT_TABLE() +#endif + EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size, long style): wxToolBar(frame, -1, pos, size, style) diff --git a/utils/glcanvas/Makefile b/utils/glcanvas/Makefile new file mode 100644 index 0000000000..3684ed3ced --- /dev/null +++ b/utils/glcanvas/Makefile @@ -0,0 +1 @@ +include ../../install/unix/setup/general/makedirs diff --git a/utils/glcanvas/src/.cvsignore b/utils/glcanvas/src/.cvsignore new file mode 100644 index 0000000000..4646a42c35 --- /dev/null +++ b/utils/glcanvas/src/.cvsignore @@ -0,0 +1,3 @@ +Linux +linux-gnu +linux diff --git a/utils/glcanvas/src/Makefile b/utils/glcanvas/src/Makefile new file mode 100644 index 0000000000..e87123793d --- /dev/null +++ b/utils/glcanvas/src/Makefile @@ -0,0 +1 @@ +include ../../../install/unix/setup/general/makedirs diff --git a/utils/glcanvas/src/Makefile.in b/utils/glcanvas/src/Makefile.in new file mode 100644 index 0000000000..da1865a403 --- /dev/null +++ b/utils/glcanvas/src/Makefile.in @@ -0,0 +1,44 @@ +# +# wGLCanvas source makefile for Unix +# +# Copyright 1998, Robert Roebling +# + +# wxWindows base directory +WXBASEDIR=@WXBASEDIR@ + +# set the OS type for compilation +OS=@OS@ + +# compile a library only +RULE=gslib + +# needed for unactivated +NONE= + +# define library name +LIB_TARGET=wx_opengl_gtk +LIB_MAJOR=0 +LIB_MINOR=1 + +# define library sources + +LIB_CPP_SRC= \ +\ + glcanvas.cpp + +#define library objects +LIB_OBJ= \ +\ + $(LIB_CPP_SRC:.cpp=.o) + +all:: + +clean:: + +#additional things needed for compile +ADD_COMPILE= + +# include the definitions now +include ../../../../template.mak + diff --git a/utils/glcanvas/src/glcanvas.cpp b/utils/glcanvas/src/glcanvas.cpp new file mode 100644 index 0000000000..44f28e7e0b --- /dev/null +++ b/utils/glcanvas/src/glcanvas.cpp @@ -0,0 +1,161 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: glcanvas.cpp +// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK +// Author: Robert Roebling +// Modified by: +// Created: 17/08/98 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "glcanvas.h" +#endif + +#include "wx/wxprec.h" + +#include "wx/frame.h" +#include "wx/colour.h" +#include "glcanvas.h" +#include + +//--------------------------------------------------------------------------- +// wxGLContext +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLContext,wxObject) + +wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) ) +{ + m_window = win; + m_widget = win->m_wxwindow; + + int data[] = {GLX_RGBA,GLX_RED_SIZE,1,GLX_GREEN_SIZE,1, + GLX_BLUE_SIZE,1,GLX_DOUBLEBUFFER,None}; + + Display *display = GDK_WINDOW_XDISPLAY( m_widget->window ); + XVisualInfo *visual_info = glXChooseVisual( display, DefaultScreen(display), data ); + + wxCHECK_RET( visual_info != NULL, "Couldn't choose visual for OpenGl" ); + + m_glContext = glXCreateContext( display, visual_info, None, GL_TRUE ); + + wxCHECK_RET( m_glContext != NULL, "Couldn't create OpenGl context" ); + + glXMakeCurrent( display, GDK_WINDOW_XWINDOW(m_widget->window), m_glContext ); +} + +wxGLContext::~wxGLContext() +{ + if (m_glContext) + { + Display *display = GDK_WINDOW_XDISPLAY( m_widget->window ); + glXMakeCurrent( display, GDK_WINDOW_XWINDOW(m_widget->window), m_glContext ); + + glXDestroyContext( display, m_glContext ); + } +} + +void wxGLContext::SwapBuffers() +{ + if (m_glContext) + { + Display *display = GDK_WINDOW_XDISPLAY( m_widget->window ); + glXSwapBuffers( display, GDK_WINDOW_XWINDOW( m_widget->window ) ); + } +} + +void wxGLContext::SetCurrent() +{ + if (m_glContext) + { + Display *display = GDK_WINDOW_XDISPLAY( m_widget->window ); + glXMakeCurrent( display, GDK_WINDOW_XWINDOW(m_widget->window), m_glContext ); + } +} + +void wxGLContext::SetColour(const char *colour) +{ + float r = 0.0; + float g = 0.0; + float b = 0.0; + wxColour *col = wxTheColourDatabase->FindColour(colour); + if (col) + { + r = (float)(col->Red()/256.0); + g = (float)(col->Green()/256.0); + b = (float)(col->Blue()/256.0); + glColor3f( r, g, b); + } +} + +void wxGLContext::SetupPixelFormat() +{ +} + +void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) ) +{ +} + +wxPalette wxGLContext::CreateDefaultPalette() +{ + return wxNullPalette; +} + +//--------------------------------------------------------------------------- +// wxGlCanvas +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow) + +BEGIN_EVENT_TABLE(wxGLCanvas, wxScrolledWindow) + EVT_SIZE(wxGLCanvas::OnSize) +END_EVENT_TABLE() + +wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, long style, const wxString& name, + int *WXUNUSED(attribList), const wxPalette& palette): + wxScrolledWindow(parent, id, pos, size, style, name) +{ + m_glContext = new wxGLContext( TRUE, this, palette ); +} + +wxGLCanvas::~wxGLCanvas() +{ + if (m_glContext) delete m_glContext; +} + +void wxGLCanvas::SwapBuffers() +{ + if (m_glContext) m_glContext->SwapBuffers(); +} + +void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event)) +{ + int width, height; + GetClientSize(& width, & height); + + if (m_glContext) + { + m_glContext->SetCurrent(); + + glViewport(0, 0, (GLint)width, (GLint)height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 ); + glMatrixMode(GL_MODELVIEW); + } +} + +void wxGLCanvas::SetCurrent() +{ + if (m_glContext) m_glContext->SetCurrent(); +} + +void wxGLCanvas::SetColour( const char *colour ) +{ + if (m_glContext) m_glContext->SetColour( colour ); +} + + diff --git a/utils/glcanvas/src/glcanvas.h b/utils/glcanvas/src/glcanvas.h new file mode 100644 index 0000000000..f277c771c9 --- /dev/null +++ b/utils/glcanvas/src/glcanvas.h @@ -0,0 +1,98 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: glcanvas.h +// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK +// Author: Robert Roebling +// Modified by: +// Created: 17/8/98 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma interface "glcanvas.h" +#endif + +#ifndef _WX_GLCANVAS_H_ +#define _WX_GLCANVAS_H_ + +#include "wx/defs.h" +#include "wx/scrolwin.h" + +#include "GL/gl.h" +#include "GL/glx.h" +#include "GL/glu.h" + +//--------------------------------------------------------------------------- +// classes +//--------------------------------------------------------------------------- + +class wxGLContext; +class wxGLCanvas; + +//--------------------------------------------------------------------------- +// wxGLContext +//--------------------------------------------------------------------------- + + +class wxGLContext: public wxObject +{ + DECLARE_CLASS(wxGLContext) + + public: + + wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette ); + ~wxGLContext(); + + void SetCurrent(); + void SetColour(const char *colour); + void SwapBuffers(); + + void SetupPixelFormat(); + void SetupPalette(const wxPalette& palette); + wxPalette CreateDefaultPalette(); + + inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; } + inline wxWindow* GetWindow() const { return m_window; } + inline GtkWidget* GetWidget() const { return m_widget; } + inline GLXContext GetContext() const { return m_glContext; } + + public: + + GLXContext m_glContext; + + GtkWidget *m_widget; + wxPalette m_palette; + wxWindow* m_window; +}; + +//--------------------------------------------------------------------------- +// wxGLContext +//--------------------------------------------------------------------------- + +class wxGLCanvas: public wxScrolledWindow +{ + DECLARE_CLASS(wxGLCanvas) + + public: + wxGLCanvas(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxString& name = "GLCanvas", int *attribList = 0, const wxPalette& palette = wxNullPalette); + ~wxGLCanvas(); + + void SetCurrent(); + void SetColour(const char *colour); + void SwapBuffers(); + + void OnSize(wxSizeEvent& event); + + inline wxGLContext* GetContext() const { return m_glContext; } + + protected: + + wxGLContext* m_glContext; // this is typedef-ed ptr, in fact + + DECLARE_EVENT_TABLE() +}; + +#endif -- 2.45.2