Registered user

Group: Members
Posts: 1621
Member No.: 2549
Joined: 21-August 06
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
Help me. I sometimes get a error on line 122 or line 121 (the line that says gdk::draw_rectangle($this->w_imgedit->window,$this->gc,true,$x,$y,9,9);) but not always, only sometimes. Sometimes it stops after a while and generates a error message on that line, saying the object doesn't exist or is the wrong type. It only does it on that line, and only sometimes. Do you know how to fix this, please?
| CODE | <?php
/* This file is part of PuzzleMesh.
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 <http://www.gnu.org/licenses/>. */
class ImageEditorWindow extends BaseWindow { var $w_pane; var $w_colors; var $w_imgedit; var $colorexposed=false; var $imgexposed=false; var $gc; var $selcolor=0; var $seltool="P"; var $alloc_colors; var $clipboard; var $imgclass; var $imgnum; var $imgdata; var $sel_x=null; var $sel_y=null; function init() { global $gtkcolors; $this->window=&new GtkWindow(); $this->window->set_title("Puzzle Mesh - Image Editor"); $this->window->set_default_size(600,400); $this->window->connect_object('delete-event', array(&$this, 'closed')); $this->window->connect_object('key-press-event', array(&$this, 'KeyPressed')); $this->window->connect_object('focus-in-event',array(&$this,'do_reexposed_event')); $this->w_pane=&new GtkHPaned(); $this->w_colors=&new GtkDrawingArea(); $this->w_colors->set_events(GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK); $this->w_colors->connect_object('expose-event',array(&$this,'do_expose_event')); $this->w_colors->connect_object('button-press-event',array(&$this,'colors_clicked')); $this->w_pane->add1($this->w_colors); $this->w_imgedit=&new GtkDrawingArea(); $this->w_imgedit->set_events(GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON1_MOTION_MASK); $this->w_imgedit->connect_object('expose-event',array(&$this,'do_expose_event')); $this->w_imgedit->connect_object('button-press-event',array(&$this,'imgedit_clicked')); $this->w_imgedit->connect_object('motion-notify-event',array(&$this,'imgedit_motion1')); $this->w_pane->add2($this->w_imgedit); $this->w_pane->connect_object('size-allocate',array(&$this,'do_reexposed_event')); $this->w_pane->set_position(153); $this->window->add($this->w_pane); $this->window->set_modal(true); $f=trim(file_get_contents('colorpalette')); $f=preg_split('/\s+/',$f); $this->alloc_colors=array(); $x=gdk::colormap_get_system(); foreach($f as $k=>$v) $this->alloc_colors[$k]=$x->alloc('#'.$v); $imgdata=str_repeat(chr(0),576); } function closed() { global $ClassEditorWindow,$classes; BaseWindow::hide(); Delete_GTK_Image($classes[$this->imgclass]->ImageIndex[$this->imgnum]); $classes[$this->imgclass]->ImageData[$this->imgnum]=$this->imgdata; $classes[$this->imgclass]->ImageIndex[$this->imgnum]=Add_GTK_Image($this->imgdata); $ClassEditorWindow->do_reexposed_event(); return true; } function show() { $this->imgexposed=false; BaseWindow::show(); $c=gdk::cursor_new(GDK_DRAFT_SMALL); $x=$this->w_colors->window; $x->set_cursor($c); $c=gdk::cursor_new(GDK_PENCIL); $x=$this->w_imgedit->window; $x->set_cursor($c); $this->seltool="P"; $this->gc=$x->new_gc(); } function do_expose_event() { if($this->imgexposed) return null; if($this->w_colors->window===null) return null; if($this->w_imgedit->window===null) return null; $this->imgexposed=true; // Color selection $this->gc->foreground=$this->alloc_colors[0]; gdk::draw_rectangle($this->w_colors->window,$this->gc,true,0,0,149,9); if($this->selcolor==0) { $this->gc->foreground=$this->alloc_colors[1]; gdk::draw_line($this->w_colors->window,$this->gc,0,0,148,0); gdk::draw_line($this->w_colors->window,$this->gc,0,0,0,8); $this->gc->foreground=$this->alloc_colors[15]; gdk::draw_line($this->w_colors->window,$this->gc,148,0,148,8); gdk::draw_line($this->w_colors->window,$this->gc,0,8,148,8); } for($i=0;$i<15*15;$i++) { $this->gc->foreground=$this->alloc_colors[$i+1]; $x=10*(int)($i%15); $y=10+10*(int)($i/15); gdk::draw_rectangle($this->w_colors->window,$this->gc,true,$x,$y,9,9); if($this->selcolor==$i+1) { $this->gc->foreground=$this->alloc_colors[1]; gdk::draw_line($this->w_colors->window,$this->gc,$x,$y,$x+8,$y); gdk::draw_line($this->w_colors->window,$this->gc,$x,$y,$x,$y+8); $this->gc->foreground=$this->alloc_colors[15]; gdk::draw_line($this->w_colors->window,$this->gc,$x+8,$y,$x+8,$y+8); gdk::draw_line($this->w_colors->window,$this->gc,$x,$y+8,$x+8,$y+8); } } // Image space for($i=0;$i<576;$i++) { $this->gc->foreground=$this->alloc_colors[ord($this->imgdata[$i])]; $x=10+10*(int)($i%24); $y=10+10*(int)($i/24); gdk::draw_rectangle($this->w_imgedit->window,$this->gc,true,$x,$y,9,9); } // Why does it stop here sometimes, but not always? if($this->sel_x!==null) { $x=10+10*$this->sel_x; $y=10+10*$this->sel_y; $this->gc->foreground=$this->alloc_colors[1]; gdk::draw_line($this->w_imgedit->window,$this->gc,$x,$y,$x+8,$y); gdk::draw_line($this->w_imgedit->window,$this->gc,$x,$y,$x,$y+8); $this->gc->foreground=$this->alloc_colors[15]; gdk::draw_line($this->w_imgedit->window,$this->gc,$x+8,$y,$x+8,$y+8); gdk::draw_line($this->w_imgedit->window,$this->gc,$x,$y+8,$x+8,$y+8); } } function do_reexposed_event() { $this->imgexposed=false; $this->do_expose_event(); } function KeyPressed($ke) { $k=GTK_ReservedKeyNames($ke->keyval); if($k===null) $k=GTK_KeyNames($ke->keyval); if($k===null) return null; if($k=="HELP") { MsgBox(file_get_contents('help/imageeditor.txt')); } else if($k=="C") { //circle $this->sel_x=null; $this->seltool="C"; $c=gdk::cursor_new(GDK_DOT); $x=$this->w_imgedit->window; $x->set_cursor($c); $this->do_reexposed_event(); } else if($k=="L") { //line $this->sel_x=null; $this->seltool="L"; $c=gdk::cursor_new(GDK_CROSS); $x=$this->w_imgedit->window; $x->set_cursor($c); $this->do_reexposed_event(); } else if($k=="P") { //pencil $this->sel_x=null; $this->seltool="P"; $c=gdk::cursor_new(GDK_PENCIL); $x=$this->w_imgedit->window; $x->set_cursor($c); $this->do_reexposed_event(); } else if($k=="R") { //rectangle $this->sel_x=null; $this->seltool="R"; $c=gdk::cursor_new(GDK_UL_ANGLE); $x=$this->w_imgedit->window; $x->set_cursor($c); $this->do_reexposed_event(); } else if($k=="F1") { //copy $this->clipboard=$this->imgdata; $this->do_reexposed_event(); } else if($k=="F2") { //paste $this->imgdata=$this->clipboard; $this->do_reexposed_event(); } } function colors_clicked($ev) { $b=$ev->button; $x=(int)($ev->x/10); $y=(int)($ev->y/10); if($b==1) { if($y==0) { $this->selcolor=0; } else if($y*15+$x-14<=15*15) { $this->selcolor=$y*15+$x-14; } $this->do_reexposed_event(); } } function imgedit_clicked($ev) { $b=$ev->button; $x=(int)($ev->x/10-1); $y=(int)($ev->y/10-1); if($x<0 || $y<0 || $x>24 || $y>24) return null; $ind=$x+$y*24; if($ind>=576 || $ind<0) return null; if($b==3) { $this->selcolor=ord($this->imgdata[$ind]); $this->do_reexposed_event(); } else if($b==1) { if($this->seltool=="P") { $this->imgdata[$ind]=chr($this->selcolor); } $this->do_reexposed_event(); } } function imgedit_motion1($ev) { $b=$ev->button; $x=(int)($ev->x/10-1); $y=(int)($ev->y/10-1); if($x<0 || $y<0 || $x>24 || $y>24) return null; $ind=$x+$y*24; if($ind>=576 || $ind<0) return null; if($this->seltool=="P") { $this->imgdata[$ind]=chr($this->selcolor); $this->do_reexposed_event(); } } }
$ImageEditorWindow=&new ImageEditorWindow();
|
This post has been edited by zzo38 on Jul 7 2008, 09:46 AM
--------------------
|