wxgraphics.cc
来自「LastWave」· CC 代码 · 共 1,621 行 · 第 1/3 页
CC
1,621 行
else if (key != 0) { return(GetLWKeyEvent(w,event,key,event.ShiftDown(),event.AltDown(),event.ControlDown(),ev)); } } // Otherwise --> regular characters else event.Skip(); } // Case there is a name and the key has been assigned else if (key != 0) { return(GetLWKeyEvent(w,event,key,event.ShiftDown(),event.AltDown(),event.ControlDown(),ev)); } return(false);}void Canvas::KeyDown(wxKeyEvent& event) { BLOCKEVENT; struct event ev; if (GetKeyDownLWEvent(this,event,ev)) ProcessNextEvent(&ev); UNBLOCKEVENT;}// The resize event will be taken care by the Paint eventvoid Canvas::OnResize(wxSizeEvent& event){ struct event ev; ev.object = (GOBJECT) Frame2Window(this->frame); if (ev.object == NULL) return; BLOCKEVENT; Refresh(false); flagResizeEvent =true; // Printf("Resize\n"); UNBLOCKEVENT;}void Canvas::OnMouseEnterLeave(wxMouseEvent& event){ // event.Skip(); struct event ev; ev.object = (GOBJECT) Frame2Window(this->frame); if (ev.object == NULL) return; BLOCKEVENT; if (event.Leaving()) ev.type = Leave; else if (event.Entering()) ev.type = Enter; wxClientDC dc1(this); dc = &dc1; ProcessNextEvent(&ev);// Printf("Enter/Leave %ld\n",ev.type); dc = NULL; UNBLOCKEVENT;}void Canvas::OnMouseMotion(wxMouseEvent& event){ // event.Skip(); struct event ev; ev.object = (GOBJECT) Frame2Window(this->frame); if (ev.object == NULL) return; BLOCKEVENT; ev.type = MouseMotion; ev.key = 0; ev.button = mouseButton; ev.i = event.GetX(); ev.j = event.GetY(); wxClientDC dc1(this); dc = &dc1;// Printf("Motion %ld %d %d \n",ev.button,ev.i,ev.j); ProcessNextEvent(&ev); dc = NULL; UNBLOCKEVENT;}void Canvas::OnMouseUp(wxMouseEvent& event){ if (HasCapture()) ReleaseMouse(); else return; struct event ev; ev.object = (GOBJECT) Frame2Window(this->frame); if (ev.object == NULL) return; BLOCKEVENT; ev.type = ButtonUp; ev.button = mouseButton; ev.key = 0; ev.i = event.GetX(); ev.j = event.GetY(); wxClientDC dc1(this); dc = &dc1; ProcessNextEvent(&ev);// Printf("UnClick %d %d \n",ev.i,ev.j); mouseButton = NoButton; dc = NULL; UNBLOCKEVENT;}void Canvas::OnMouseDown(wxMouseEvent& event){// event.Skip(); struct event ev; ev.object = (GOBJECT) Frame2Window(this->frame); if (ev.object == NULL) return; ev.button = XXMouseButton(event); if (ev.button == NoButton) return; BLOCKEVENT; ev.type = ButtonDown; unsigned long m = 0; if (event.ShiftDown()) m += ModShift; if (event.ControlDown()) m += ModCtrl; ev.button += m; ev.key = 0; ev.i = event.GetX(); ev.j = event.GetY(); wxClientDC dc1(this); dc = &dc1; CaptureMouse(); mouseButton = ev.button; ProcessNextEvent(&ev);// Printf("Click %ld %ld %d %d \n",ev.i,ev.j); dc = NULL; UNBLOCKEVENT;}void Canvas::OnPaint(wxPaintEvent& event){ int i = 0; struct event ev; // event.Skip(); ev.object = (GOBJECT) Frame2Window(this->frame); if (ev.object == NULL) return; if (IsEventBlocked() && !IsEventBlockedByTerminal()) return; wxPaintDC dc1(this); dc = &dc1; if (flagResizeEvent) { flagResizeEvent = false; ev.type = Resize; frame->GetPosition(&(ev.i),&(ev.j)); GetClientSize(&(ev.m),&(ev.n));// ev.m = size.GetWidth()-wBorder;// ev.n = size.GetHeight()-hBorder;// Printf("Resize %d %d %d %d\n",ev.i,ev.j,ev.m,ev.n); ProcessNextEvent(&ev); } else { ev.type = Draw; wxRegionIterator upd(GetUpdateRegion()); // get the update rect list while (upd) { ev.i = upd.GetX(); ev.j = upd.GetY(); ev.m = upd.GetW(); ev.n = upd.GetH();// Printf("Paint %d %d %d %d %d\n",i,ev.i,ev.j,ev.m,ev.n); ProcessNextEvent(&ev); upd ++ ; i++; } } dc = NULL;}Canvas::Canvas(Frame *f) : wxWindow(f, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER )/*wxScrolledWindow(f, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER ) */{ SetBackgroundColour(*wxWHITE); frame = f; dc = NULL; wxClientDC dc1(this); dc1.SetPen(*wxBLACK_PEN); dc1.SetBrush(*wxTRANSPARENT_BRUSH); mouseButton = NoButton; flagResizeEvent = false;}Frame::Frame(wxString title,int x, int y, int w,int h) : wxFrame(NULL, -1, title,wxPoint(x,y),wxSize(w,h),wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS){ // Create the canvas canvas = new Canvas(this); // Useful ?? // canvas->SetFocusIgnoringChildren(); // Allows to resize the canvas SendSizeEvent(); XXFlushEvents(); // Compute frame border int w1,h1; GetClientSize(&w1,&h1); hBorder = h-h1; wBorder = w-w1; // Compute canvas border canvas->GetClientSize(&w1,&h1); int w2,h2; canvas->GetSize(&w2,&h2); canvas->hBorder = h2-h1; canvas->wBorder = w2-w1; SetSize(-1,-1,w+totalWBorder(),h+totalHBorder());// SetWindowStyle(GetWindowStyleFlag() | wxNO_FULL_REPAINT_ON_RESIZE);}Frame::~Frame() {}void XXOpenGraphics(void){ thePen = *wxBLACK_PEN; theBrush = *wxBLACK_BRUSH; theFont = wxFont(12,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL); thePenMode = wxCOPY;/* stupFrame *f = new stupFrame; f->Show(true); f->Raise(); wxClientDC dc(f); *//* dc.SetPen(thePen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetClippingRegion(theClipX,theClipY,theClipW,theClipH);*/ // dc.DrawLine(0,0,100,100);}void XXCloseGraphics(void){}/* Set the style of the line */void XXSetLineStyle(FRAME frame,int flag){ if (flag == LinePlain) thePen.SetStyle(wxSOLID); else thePen.SetStyle(wxSHORT_DASH); if (((Frame *) frame)->canvas->dc != NULL) ((Frame *) frame)->canvas->dc->SetPen(thePen);}/* Change the size of the pen of the Graphic Port */void XXSetPenSize(FRAME frame,int size){ thePen.SetWidth(size); if (((Frame *) frame)->canvas->dc != NULL) ((Frame *) frame)->canvas->dc->SetPen(thePen);}/* Set the pen mode of the Graphic Port */void XXSetPenMode(FRAME frame,int mode){ if (mode == PenPlain) thePenMode = wxCOPY; else thePenMode = wxINVERT; if (((Frame *) frame)->canvas->dc != NULL) ((Frame *) frame)->canvas->dc->SetLogicalFunction(thePenMode);}/* Draw a line in the graphic port */void XXDrawLine(FRAME frame,int x,int y,int x1,int y1){ if (((Frame *) frame)->canvas->dc == NULL) { wxClientDC dc(((Frame *) frame)->canvas); dc.SetPen(thePen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DestroyClippingRegion(); dc.SetClippingRegion(theClipX,theClipY,theClipW,theClipH); dc.SetLogicalFunction(thePenMode); dc.DrawLine(x, y, x1, y1); } else { ((Frame *) frame)->canvas->dc->DrawLine(x, y, x1, y1); }}/* Draw a point in the Graphic Port */void XXDrawPoint(FRAME frame,int x,int y){ if (((Frame *) frame)->canvas->dc == NULL) { wxClientDC dc(((Frame *) frame)->canvas); dc.SetPen(thePen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DestroyClippingRegion(); dc.SetClippingRegion(theClipX,theClipY,theClipW,theClipH); dc.SetLogicalFunction(thePenMode); dc.DrawPoint(x, y); } else { ((Frame *) frame)->canvas->dc->DrawPoint(x, y); } }/* Draw an ellipse in a rect */void XXDrawEllipse(FRAME frame,int x,int y,int dx, int dy){ if (((Frame *) frame)->canvas->dc == NULL) { wxClientDC dc(((Frame *) frame)->canvas); dc.SetPen(thePen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DestroyClippingRegion(); dc.SetClippingRegion(theClipX,theClipY,theClipW,theClipH); dc.SetLogicalFunction(thePenMode); dc.DrawEllipse(x, y, dx, dy); } else { ((Frame *) frame)->canvas->dc->SetBrush(*wxTRANSPARENT_BRUSH); ((Frame *) frame)->canvas->dc->DrawEllipse(x, y, dx, dy); }}/* Fill an ellipse in a rect */void XXFillEllipse(FRAME frame,int x,int y,int dx, int dy){ if (((Frame *) frame)->canvas->dc == NULL) { wxClientDC dc(((Frame *) frame)->canvas); dc.SetPen(thePen); dc.SetBrush(theBrush); dc.DestroyClippingRegion(); dc.SetClippingRegion(theClipX,theClipY,theClipW,theClipH); dc.SetLogicalFunction(thePenMode); dc.DrawEllipse(x, y, dx, dy); } else { ((Frame *) frame)->canvas->dc->SetPen(thePen); ((Frame *) frame)->canvas->dc->SetBrush(theBrush); ((Frame *) frame)->canvas->dc->DrawEllipse(x, y, dx, dy); }}/* Draw a rectangle */void XXDrawRect(FRAME frame,int x,int y,int dx,int dy){ if (((Frame *) frame)->canvas->dc == NULL) { wxClientDC dc(((Frame *) frame)->canvas); dc.SetPen(thePen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DestroyClippingRegion(); dc.SetClippingRegion(theClipX,theClipY,theClipW,theClipH); dc.SetLogicalFunction(thePenMode); dc.DrawRectangle(x, y, dx, dy); } else { ((Frame *) frame)->canvas->dc->SetBrush(*wxTRANSPARENT_BRUSH); ((Frame *) frame)->canvas->dc->DrawRectangle(x, y, dx, dy); }}/* Fill a rectangle */void XXFillRect(FRAME frame,int x,int y,int dx,int dy){ if (((Frame *) frame)->canvas->dc == NULL) { wxClientDC dc(((Frame *) frame)->canvas); dc.SetPen(thePen); dc.SetBrush(theBrush); dc.DestroyClippingRegion(); dc.SetClippingRegion(theClipX,theClipY,theClipW,theClipH); dc.SetLogicalFunction(thePenMode); dc.DrawRectangle(x, y, dx, dy); } else { ((Frame *) frame)->canvas->dc->SetPen(thePen); ((Frame *) frame)->canvas->dc->SetBrush(theBrush); ((Frame *) frame)->canvas->dc->DrawRectangle(x, y, dx, dy); }} /* Set the clip rect */void XXSetClipRect(FRAME frame, int x, int y, int w, int h){ theClipX = x; theClipY = y; theClipW = w; theClipH = h; if (((Frame *) frame)->canvas->dc != NULL) { ((Frame *) frame)->canvas->dc->DestroyClippingRegion(); ((Frame *) frame)->canvas->dc->SetClippingRegion(theClipX,theClipY,theClipW,theClipH); }}/* * Managing Pixmaps */static wxImage *im = NULL;void XXAllocPixMap(int w,int h,unsigned char **pData,int *pRowBytes){ im = new wxImage(w,h,false); *pData = (im->GetData()); *pRowBytes = w*3;}void XXDeletePixMap(void){ delete im; im = NULL;} /* Display an image in a frame */void XXDisplayPixMap(FRAME frame,int winX,int winY){ wxBitmap b(*im); // Create a memory DC wxMemoryDC temp_dc; temp_dc.SelectObject(b); // We can now draw into the memory DC... // Copy from this DC to another DC. wxClientDC dc1(((Frame *) frame)->canvas); dc1.Blit(winX,winY, b.GetWidth(), b.GetHeight(),& temp_dc, 0, 0);}char XXIsDisplayBLittle(void){ return(NO);}void XXFlush(void){}/********************************************************//* Other functions *//********************************************************//* Delete a window */void XXDeleteFrame(FRAME frame){ ((Frame *) frame)->Destroy();}/* Create a window */FRAME XXNewFrame(char *title,int x, int y, int w,int h){ wxWindow *ww = wxWindow::FindFocus(); AHASHELEM e; WINDOW win; win = NULL; for (unsigned r = 0; r<theWindowsHT->nRows;r++) { for (e = (AHASHELEM) theWindowsHT->rows[r]; e != NULL; e = (AHASHELEM) e->next) { win = (WINDOW) e; if (win->frame != NULL && (((Frame *) (win->frame))->canvas == ww || ((Frame *) (win->frame)) == ww)) break; win = NULL; } } if (win == NULL) ww = myApp->terminal; else ww = ((Frame *) (win->frame)); Frame * f = new Frame(ANSI2WXSTRING(title),x,y,w,h); f->Show(true); ww->SetFocus(); ww->Raise(); return(f);}/* Change the size the position and the title of a window */void XXChangeFrame(FRAME frame,char *title,int x,int y,int w, int h){ int x1,y1,w1,h1; ((Frame *) frame)->canvas->GetClientSize(&w1,&h1); ((Frame *) frame)->GetPosition(&x1,&y1); if (w != w1 || h != h1) { ((Frame *) frame)->SetSize(x,y,w+((Frame *) frame)->totalWBorder(),h+((Frame *) frame)->totalHBorder()); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?