Giter Club home page Giter Club logo

Comments (5)

davekimble2 avatar davekimble2 commented on June 5, 2024

I think that should be wxPen, not wxBrush, and wxClientDC, however it doesn't make any difference.

<?php
$width = 180;
$height = 100;
$frame = new wxFrame(null, wxID_TOP, "Title", wxDefaultPosition, new wxSize($width, $height), ~wxCAPTION );
$panel = new wxPanel($frame, wxID_ANY, wxDefaultPosition, new wxSize($width, $height));
$chart = new wxClientDC($panel);
$chart->SetPen(new wxPen(new wxColour(255, 255, 255)));
$timer = new wxTimer();
$timer->Connect(wxEVT_TIMER, array(wxID_TOP, "refresh"));
$timer->Start(1000);
$frame->Show();
wxEntry();
function OnInit() {}
function OnExit() {}
//
function refresh()
{   global $chart, $height, $width ;
    for($row=0; $row<$height; $row++)
    {   for($col=0; $col<$width; $col++)
        {   $chart->DrawPoint($col, $row);
        }
    }
}
?>

from wxphp.

jgmdev avatar jgmdev commented on June 5, 2024

Here I modified your sample to make it work:

<?php
$width = 180;
$height = 100;

$frame = new wxFrame(null, wxID_TOP, "Title", wxDefaultPosition, new wxSize($width, $height), ~wxCAPTION );
$panel = new wxPanel($frame, wxID_ANY, wxDefaultPosition, new wxSize($width, $height));
$panel->Connect(wxEVT_PAINT, array(null, "paint"));
$frame->Maximize(false);
$frame->Show();

wxEntry();
function OnInit() {}
function OnExit() {}

function paint(wxPaintEvent $event)
{
    global $panel, $width, $height;

    $dc = new wxPaintDC($panel);

    $dc->SetPen(new wxPen(new wxColour(0xFF, 0, 0)));

    for($row=0; $row<$height; $row++)
    {   for($col=0; $col<$width; $col++)
        {   
            $dc->DrawPoint($col, $row);
        }
    }
}
?>

from wxphp.

jgmdev avatar jgmdev commented on June 5, 2024

by the way I just did 2 commits:

  1. Add support for wxNonOwnedWindow::SetShape which allows to create free form windows.

  2. Disabled error messages when OnInit and OnExit can't be called, so now this short code samples can skip the following bits:

    function OnInit() {}
    function OnExit() {}

from wxphp.

davekimble2 avatar davekimble2 commented on June 5, 2024

I didn't put the ctor in the event handler because some forum comment said it wouldn't get destroyed and by repeated calling eventually you would run out of memory, but maybe that was due to the specific OOP structure of that example.

What is the event that wxEVT_PAINT is trapping? wxWidgets says wxPanel's events are wxNavigationKeyEvent, so if you don't touch the keyboard or mouse I would have thought it wouldn't fire.

Anyway I want the wxTimer event to be the trigger for updating the chart (I didn't mention that before). It seems to work with wxPaintDC, even though its not now in a wxEVT_PAINT handler, but it also works with wxClientDC, as expected.

All working fine now, many thanks again.

from wxphp.

jgmdev avatar jgmdev commented on June 5, 2024
  1. The $dc object is automatically destroyed when it goes out of scope so don't worry about that one.
  2. The wxEVT_PAINT is triggered everytime that the panel needs to be rendered. Examples: when drawing the element for the first time, when moving the window around, if the panel gets behind some element and then on the front again, if the element gets resized, etc...
  3. You can add a wxTimer that calls $frame->Refresh() or $panel->Refresh(), and that would force a paint event even if not required.

from wxphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.