1
General discussions / iPhone Port (in progress)
« on: January 28, 2010, 01:18:01 am »
Is this still being worked on? No posts in months...
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <unistd.h>
#include <fstream>
#include "wx/wx.h"
#include "wxSFMLCanvas.hpp"
////////////////////////////////////////////////////////////
/// Custom SFML canvas
////////////////////////////////////////////////////////////
class MyCanvas : public wxSFMLCanvas
{
public :
////////////////////////////////////////////////////////////
/// Construct the canvas
///
////////////////////////////////////////////////////////////
MyCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style = 0) :
wxSFMLCanvas(Parent, Id, Position, Size, Style)
{
// Load an image and assign it to our sprite
myImage.LoadFromFile("grid.png");
mySprite.SetImage(myImage);
}
private :
////////////////////////////////////////////////////////////
/// /see wxSFMLCanvas::OnUpdate
///
////////////////////////////////////////////////////////////
virtual void OnUpdate()
{
Clear(sf::Color(255, 0, 0));
}
////////////////////////////////////////////////////////////
/// Member data
////////////////////////////////////////////////////////////
sf::Image myImage; ///< Some image to load...
sf::Sprite mySprite; ///< Something to draw...
};
////////////////////////////////////////////////////////////
/// Our main window
////////////////////////////////////////////////////////////
class MyFrame : public wxFrame
{
public :
void MyFrame::OnMenuFileQuit(wxCommandEvent &event);
void OnMenuFileOpen(wxCommandEvent &event);
void OnMenuFileSave(wxCommandEvent &event);
////////////////////////////////////////////////////////////
/// Default constructor : setup the window
///
////////////////////////////////////////////////////////////
MyFrame() :
wxFrame(NULL, wxNewId(), wxString::FromAscii("Yeah!Edit"), wxDefaultPosition, wxSize(800, 600))
{
ThisIsExitID = 4269;
// Let's create our SFML view
// status bar
CreateStatusBar(3);
SetStatusText(wxT("Ready"), 0);;
// menu bar
m_pMenuBar = new wxMenuBar();
// File Menu
m_pFileMenu = new wxMenu();
m_pFileMenu->Append(wxID_OPEN, _T("&Open"), _T("Opens an existing file"));
m_pFileMenu->Append(wxID_SAVE, _T("&Save"), _T("Save the content"));
m_pFileMenu->AppendSeparator();
m_pFileMenu->Append(ThisIsExitID, _T("&Quit"), _T("Quit the application"));
m_pMenuBar->Append(m_pFileMenu, _T("&File"));
// About menu
m_pHelpMenu = new wxMenu();
m_pHelpMenu->Append(wxID_ABOUT, _T("&About"), _T("Shows information about the application"));
m_pMenuBar->Append(m_pHelpMenu, _T("&Help"));
SetMenuBar(m_pMenuBar);
new MyCanvas(this, wxID_ANY, wxPoint(50, 50), wxSize(700, 500));
}
protected:
DECLARE_EVENT_TABLE()
private :
wxTextCtrl *m_pTextCtrl;
wxMenuBar *m_pMenuBar;
wxMenu *m_pFileMenu;
wxMenu *m_pHelpMenu;
int ThisIsExitID;
};
// If you're doing an application by inheriting from wxApp
// be sure to change wxFrame to wxApp (or whatever component
// you've inherited your class from).
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_OPEN, MyFrame::OnMenuFileOpen)
EVT_MENU(wxID_SAVE, MyFrame::OnMenuFileSave)
EVT_MENU(4269, MyFrame::OnMenuFileQuit)
END_EVENT_TABLE()
void MyFrame::OnMenuFileOpen(wxCommandEvent &event)
{
// ...
}
void MyFrame::OnMenuFileSave(wxCommandEvent &event)
{
// ...
}
void MyFrame::OnMenuFileQuit(wxCommandEvent &event)
{
Close(false);
}
////////////////////////////////////////////////////////////
/// Our application class
////////////////////////////////////////////////////////////
class MyApplication : public wxApp
{
private :
////////////////////////////////////////////////////////////
/// Initialize the application
///
////////////////////////////////////////////////////////////
virtual bool OnInit()
{
// Create the main window
MyFrame* MainFrame = new MyFrame;
MainFrame->Show();
return true;
}
};
IMPLEMENT_APP(MyApplication);
#ifndef WXSFMLCANVAS_HPP
#define WXSFMLCANVAS_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <wx/wx.h>
////////////////////////////////////////////////////////////
/// wxSFMLCanvas allows to run SFML in a wxWidgets control
////////////////////////////////////////////////////////////
class wxSFMLCanvas : public wxControl, public sf::RenderWindow
{
public :
////////////////////////////////////////////////////////////
/// Construct the wxSFMLCanvas
///
/// \param Parent : Parent of the control (NULL by default)
/// \param Id : Identifier of the control (-1 by default)
/// \param Position : Position of the control (wxDefaultPosition by default)
/// \param Size : Size of the control (wxDefaultSize by default)
/// \param Style : Style of the control (0 by default)
///
////////////////////////////////////////////////////////////
wxSFMLCanvas(wxWindow* Parent = NULL, wxWindowID Id = -1, const wxPoint& Position = wxDefaultPosition, const wxSize& Size = wxDefaultSize, long Style = 0);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
virtual ~wxSFMLCanvas();
private :
DECLARE_EVENT_TABLE()
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing its update and drawing stuff
///
////////////////////////////////////////////////////////////
virtual void OnUpdate();
////////////////////////////////////////////////////////////
/// Called when the window is idle - we can refresh our
/// SFML window
///
////////////////////////////////////////////////////////////
void OnIdle(wxIdleEvent&);
////////////////////////////////////////////////////////////
/// Called when the window is repainted - we can display our
/// SFML window
///
////////////////////////////////////////////////////////////
void OnPaint(wxPaintEvent&);
////////////////////////////////////////////////////////////
/// Called when the window needs to draw its background
///
////////////////////////////////////////////////////////////
void OnEraseBackground(wxEraseEvent&);
};
#endif // WXSFMLCANVAS_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "wxSFMLCanvas.hpp"
// Platform-specific includes
#ifdef __WXGTK__
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <wx/gtk/win_gtk.h>
#endif
////////////////////////////////////////////////////////////
// Event table
////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE(wxSFMLCanvas, wxControl)
EVT_IDLE(wxSFMLCanvas::OnIdle)
EVT_PAINT(wxSFMLCanvas::OnPaint)
EVT_ERASE_BACKGROUND(wxSFMLCanvas::OnEraseBackground)
END_EVENT_TABLE()
////////////////////////////////////////////////////////////
/// Construct the wxSFMLCanvas
////////////////////////////////////////////////////////////
wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
wxControl(Parent, Id, Position, Size, Style)
{
#ifdef __WXGTK__
// GTK implementation requires to go deeper to find the low-level X11 identifier of the widget
gtk_widget_realize(m_wxwindow);
gtk_widget_set_double_buffered(m_wxwindow, false);
GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
XFlush(GDK_WINDOW_XDISPLAY(Win));
sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));
#else
// Tested under Windows XP only (should work with X11 and other Windows versions - no idea about MacOS)
sf::RenderWindow::Create(GetHandle());
#endif
}
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
wxSFMLCanvas::~wxSFMLCanvas()
{
// Nothing to do...
}
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing its update and drawing stuff
////////////////////////////////////////////////////////////
void wxSFMLCanvas::OnUpdate()
{
// Nothing to do by default...
}
////////////////////////////////////////////////////////////
/// Called when the control is idle - we can refresh our
/// SFML window
////////////////////////////////////////////////////////////
void wxSFMLCanvas::OnIdle(wxIdleEvent&)
{
// Send a paint message when the control is idle, to ensure maximum framerate
Refresh();
}
////////////////////////////////////////////////////////////
/// Called when the control is repainted - we can display our
/// SFML window
////////////////////////////////////////////////////////////
void wxSFMLCanvas::OnPaint(wxPaintEvent&)
{
// Make sure the control is able to be repainted
wxPaintDC Dc(this);
// Let the derived class do its specific stuff
OnUpdate();
// Display on screen
Display();
}
////////////////////////////////////////////////////////////
/// Called when the control needs to draw its background
////////////////////////////////////////////////////////////
void wxSFMLCanvas::OnEraseBackground(wxEraseEvent&)
{
// Don't do anything. We intercept this event in order to prevent the
// parent class to draw the background before repainting the window,
// which would cause some flickering
}
[Session started at 2009-01-04 22:36:32 -0500.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/zhinchliffe/Projects/Yeah! I've Got The Times!/build/Debug/Yeah! I've Got The Times!.app/Contents/MacOS/Yeah! I've Got The Times!', process 24177.
warning: Unable to read symbols for "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss" (file not found).
warning: Unable to read symbols from "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss" (not yet mapped into memory).
warning: Unable to read symbols for "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss" (file not found).
warning: Unable to read symbols from "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss" (not yet mapped into memory).
gdb stack crawl at point of internal error:
[ 0 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (align_down+0x0) [0x122510]
[ 1 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (objfile_data+0x69) [0xa7a93]
[ 2 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (dwarf2_frame_find_fde+0x33) [0xe0565]
[ 3 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (dwarf2_frame_sniffer+0x2e) [0xe1015]
[ 4 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (frame_unwind_find_by_frame+0x3b) [0x129e5d]
[ 5 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (get_prev_frame+0x63) [0x129270]
[ 6 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (do_check_is_thread_unsafe+0x195) [0x3ed42]
[ 7 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (catch_errors+0x4d) [0x7ae0e]
[ 8 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (safe_check_is_thread_unsafe+0x69) [0x3edd2]
[ 9 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (iterate_over_threads+0x24) [0x78e7e]
[ 10 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (check_safe_call+0xe4) [0x3eecb]
[ 11 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (mi_cmd_stack_check_threads+0x292) [0x12873]
[ 12 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (captured_mi_execute_command+0x16d) [0x1766f]
/SourceCache/gdb/gdb-962/src/gdb/objfiles.c:2218: internal-error: objfile_data: Assertion `data->index < objfile->num_data' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
The Debugger has exited with status 1.
What's written in the Xcode's console ?
[Session started at 2009-01-03 19:08:10 -0500.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/zhinchliffe/Desktop/Coobie and the Robots/build/Release/Coobie and the Robots.app/Contents/MacOS/Coobie and the Robots', process 5549.
(gdb)
Never has this been done automatically.but when I compile the basic included SFML template, it DOES do it automatically. :?
The debugger asks for the frameworks to be copied in appname.app/Contents/Frameworks. Make sure this is where you put them.right, but usually the frameworks are automatically put in that folder, and now, for some reason, they are not.
Otherwise, for general development with SFML, the frameworks must be copied in /Library/Frameworks.
warning: Unable to read symbols for "@executable_path/../Frameworks/sfml-audio-d.framework/Versions/A/sfml-audio-d" (file not found).
warning: Unable to read symbols from "sfml-audio-d" (not yet mapped into memory).
warning: Unable to read symbols for "@executable_path/../Frameworks/sfml-graphics-d.framework/Versions/A/sfml-graphics-d" (file not found).
warning: Unable to read symbols from "sfml-graphics-d" (not yet mapped into memory).
warning: Unable to read symbols for "@executable_path/../Frameworks/sfml-system-d.framework/Versions/A/sfml-system-d" (file not found).
warning: Unable to read symbols from "sfml-system-d" (not yet mapped into memory).
warning: Unable to read symbols for "@executable_path/../Frameworks/sfml-window-d.framework/Versions/A/sfml-window-d" (file not found).
warning: Unable to read symbols from "sfml-window-d" (not yet mapped into memory).
use cocoa's bundle-handling code to load your images from the bundle's resource directory.Alright, I'll need a bit more help than that, since I'm not a cocoa programmer. How exactly would I go about doing this?