Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
B

Bryan White

@Bryan White
About
Posts
11
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Plotting on a Map using latitudes/longitudes(GPS)
    B Bryan White

    If you're plotting simple Lat/Long as X/Y (or is that Y/X?) and your Long is too short(?!) on the map (i.e. if you 'walk' in a square and an oblong appears) ... then if: - area is small (less than say 100 miles/kilometres) - not a polar region then let LonAdj = Lon/cos(LatOfMapMidPoint) and plot that. If a polar region, plot as polar (radius = 90-abs(Lat) & theta/angle = Long * sign(Lat)) Regards Brewman

    C# help code-review

  • Endless Mouse Move Events
    B Bryan White

    Yup - I've experienced it. It was an OpenGL control with mouse interaction, and didn't bother to work out WHY it happened - I just stopped it being a pain with following pseudocode: PointOrWhatever savedPosition; void HandleMouseEvent(whatever args) { if(args.position == savedPosition) return; DoMyMouseMovingStuff(); savedPosition = args.position; } Regards Brewman

    C# com question

  • Converting strings to DateTime structs
    B Bryan White

    A word of warning when reading December's data in January - it may have wrong year! Remember to add logic something like pseudocode: if(Month(data) > Month(Now)) DataYear -= 1; Regards Brewman

    C# question learning

  • C# time to C++ time_t
    B Bryan White

    "For instance, 0xffff is -1 for an Int32 while it is 65535 for a UInt64" I think that you'll find that 0xffff is 65535 for Int32 as well as in UInt16, UInt32, Int64 & UInt64 but -1 in Int16. 0xffffffff is -1 in Int32 & 4,294,967,295 in UInt32, Int64 & UInt64. Regards Brewman

    C# csharp c++ question

  • Is this a pointer operation ?
    B Bryan White

    Yes (but maybe no, if UserTri is actually a value type (like struct) rather than 'true' class). I'm an Assembler programmer at heart, and in cases like this, ask myself, "Is this storing an address (of, say, 4 bytes), or the value?" The C++ code is storing an address. The C# code stores address of classes & copy of variable for value types (simple data types & structs). I LOVE pointers, and regard C#'s reference (and C++'s, for that matter) as 'pointers in disguise'. Regards Brewman

    C# question csharp

  • Plotting on a Map using latitudes/longitudes(GPS)
    B Bryan White

    Define 'accuracy' and 'plot'. What method did you use? What is its purpose? I have experience of plotting lat/long country outlines and GPS data onto a computer screen. Treat the lat/long as a coordinate in 3D space (polar coords with constant Radius - or is this the inaccuracy you talk about? Do you want a more accurate geoid(earth-shape)?). Convert to Cartesian coords (X, Y, Z) Then project onto a 2D surface. Which projection do you want to use? There are hundreds, but probably less than a dozen that cover 99% of needs. Each projection has its own strengths and weaknesses (read: inaccuracies). e.g. a Mercator allows sailors (& others) to travel at a constant bearing to reach their destination, but distorts shapes. To allow 'autosizing' of the display, I just used the min/max lat/long rectangle diagonal & scaled it - fine unless you're working near the poles (I was using Europe, US & Canada - Canada was almost a problem!). Give more specific details of what you're doing & want to achieve, and you could receive more specific help. Regards Brewman

    C# help code-review

  • PrintDocument PrintPage event
    B Bryan White

    You wrote " Bryan White wrote: I don't like flags. The idea of OO stuff is encapsulation. Is there any reason that part of such encapsulation is not using some sort of state flags? MANY of the implementations in the class library - especially those that wrap the Windows Common Controls - use state flags / variables and act accordingly. It's just part of the encapsulation. " I have no problem with flags describing an objects INTERNAL state. You are correct, and I agree. I should probably have said "I don't like flags holding the state of, or describing, OTHER objects". This is hinted at by my following sentence (encapsulation). If (as in this case) an object(PrintDocument) is being activated from another one(either PreviewPrintController/PrintPreviewDialog or StandardPrintController/PrintDialog), then rather than storing a flag about which one activated it (and causing headaches if you decide Preview = !Standard and a third one is added), I feel that it is better to just store the controller/dialog object as a 'parent object'. Then, Microsoft decided to specifically hide this 'parent object', which I find VERY FRUSTRATING (as you can probably guess from the tone of my earlier response. BTW my own technique for defining an item as "this is public but you probably shouldn't be using it" is to prefix the name with an underscore "_". This may not be part of any standard, but hopefully makes people (and myself in a week's time!) think twice before using it.) If this hidden member did not exist, then rather than create a flag I would still prefer to: - create a derived class from PrintDocument (called PrintDocumentWithActivator?) with a member of type object called something like 'parent' or 'activator'. - store the PrintPreviewDialog(or other activator) object in it - test this object in the PrintPage event. I feel that this follows the Open-Closed Principle(OCP) better than a flag. Once the 'activator' object is defined, there need be no further changes in the class if, say, a PrintTo3DEngraverDialog came along later, and the programmer wanted a registered trade mark engraved bottom left rather than a copyright notice printed bottom right. If the flag was held in the app class, then it would be impossible to decide to how to print the PrintDocument object by just referring to that particular instance; you would need TWO objects to decide (difficult when just one object is passed in an event handler), and in danger of violating the Dependency Inversion Principle(DIP); why should the app know or

    C# question

  • How to create menuItems dynamic on Popup event?
    B Bryan White

    This is how I do it: - create a ContextMenuPopup in the application (I do this in the base form, but use it for multiple forms in the same application). I think that I used the GUI designer originally: this.contextMenuPopup = new System.Windows.Forms.ContextMenu(); - the GUI designer threw this code in; how much is actually used? dunno! this.contextMenuPopup.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItemTitle, this.menuItemSep1, this.menuItemOpt1, this.menuItemOpt2, this.menuItemOpt3}); this.contextMenuPopup.Popup += new System.EventHandler(this.contextMenuPopup_Popup); - In the form you want it to apply to, add: newWindowL.GraphicControl.ContextMenu = contextMenuPopup; - Write a menu builder This is tricky; you need to remember that: - each MenuItem has to be a clone, not an original, if you are "mix'n'match"ing a menu. Well, I found that it helped 'cos some items are duplicated. - each MenuItem needs an event handler. I use a recursive method to allow multi-level context menus -MenuItemCommand is derived from MenuItem & does a few fancy things like storing a command object (cf "Command Patterns") The code has just been copied & pasted. Use it more for ideas/principles than 'as is'; here goes: #region ContextMenuPopup stuff private void contextMenuPopup_Popup(object sender, System.EventArgs e) { ContextMenu ctxMenu = sender as ContextMenu; if(ctxMenu == null) return; Control ctl = ctxMenu.SourceControl; if(ctl == null) return; // blah blah contextMenuBuilder.SetContextOptionNames(GarageSystem.Garage, hitStruct4ContextMenu, mEditingMenus, contextMenuPopup); } public void SetContextOptionNames(SEComponentMaster topLevel, Structure hitStruct, Menu.MenuItemCollection theMenuCollection, ContextMenu theContextMenu)//, MenuClicker theEventHandler) { MenuClicker theEventHandler = new

    C# csharp tutorial question

  • How Do I transform 2d coordinates of the mouse into 3d?
    B Bryan White

    This code is for CsGL, a C# wrapper for OpenGL, but I'm sure that the concept applies to other graphical 3D stuff. In a 2D representation of a 3D scene (i.e. most pictures, TV, cinema, etc), a point on the 2D surface represents a line in 3D space. In openGL, this 3D space is bounded by clipping planes. The following code takes the mouse's X-Y coordinates and calculates a line (or ray) that passes through those clipping planes. Note that the OpenGL mouse Y coordinate is 'inverted' to Windows mouse Y Coordinate. Note that the following code won't quite work 'out of the box' (I've removed some stuff to condense things), but you should be able to construct working code with little effort. - You need the ModelView, ModelPort & Projection state, saved like the following code: public class OGLMatrixState { public void Save() { GL.glGetDoublev(GL.GL_PROJECTION_MATRIX, savedProjectionMatrix); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, savedModelviewMatrix); GL.glGetIntegerv(GL.GL_VIEWPORT, savedViewportArray); } private double[] savedProjectionMatrix = new double[16]; private double[] savedModelviewMatrix = new double[16]; private int[] savedViewportArray = new int[4]; } - You need the built-in conversion routines that OpenGL provides: public static SEG.Line ViewXYToRay(double vX, double mouseY, OGLMatrixState matrixState) { double vY = matrixState.Viewport[3] - mouseY; double pX,pY,pZ; SEG.Point nearPt = new SEG.Point(); SEG.Point farPt = new SEG.Point(); GL.gluUnProject(vX, vY, 0.0, matrixState.Modelview, matrixState.Projection, matrixState.Viewport, out pX, out pY, out pZ); nearPt.X = pX; nearPt.Y = pY; nearPt.Z = pZ; GL.gluUnProject(vX, vY, 1.0, matrixState.Modelview, matrixState.Projection, matrixState.Viewport, out pX, out pY, out pZ); farPt.X = pX; farPt.Y = pY; farPt.Z = pZ; SEG.Line rayFromNearToFar = new SEG.Line(nearPt, farPt); return rayFromNearToFar; } Hope this helps Regards Brewman

    C# question

  • How Do I transform 2d coordinates of the mouse into 3d?
    B Bryan White

    I'm uncertain whether this thread is supposed to be taken seriously or not (judging by other responses), but I have converted mouse coordinate X,Y into a ray from Point1(X,Y,Z) to Point2(X,Y,Z) in OpenGL. If that's any good to you, reply to me and I'll post the code. Regards Brewman

    C# question

  • PrintDocument PrintPage event
    B Bryan White

    Do not presume to know the mind of someone asking an apparently stupid question. There is a school of thought that says that there are no stupid questions, only stupid answers. I beg to differ about: - there being no good reason to act differently. - there being no good way to tell the difference. Now, why would I want Print Preview to be different? Because my graphics lines @ 1200 dpi are TOO THIN to show even at 500% Zoom ! So I want to use thicker lines in print preview (and it's also quicker generating a page of bitmapped graphics @ 200dpi rather than 1200dpi). I don't like flags. The idea of OO stuff is encapsulation. Good News: The PrintDocument passed as object sender to XX_PrintPage contains a member 'PrintController' which has a member 'underlyingController' which has a type of {System.Drawing.Printing.PreviewPrintController} or {System.Drawing.Printing.StandardPrintController}. Bad News: This is supposed to be hidden from you (thank you Bill and your people who can't think outside the square and mutter "Why would you do anything different"). Good News: Use Reflection! //using System.Reflection; PrintDocument PD = sender as PrintDocument; PrintControllerWithStatusDialog PC = PD.PrintController as PrintControllerWithStatusDialog; FieldInfo FI = PC.GetType().GetField("underlyingController", BindingFlags.NonPublic | BindingFlags.Instance); PreviewPrintController PPC = FI.GetValue(PC) as PreviewPrintController; Now, if PPC is not null, it's PrintPreview. If PPC is null, it's not PrintPreview. Bad News: It's ugly, brittle, hardly polymorphic, uses undocumented features of dotNet Framework and might stop working in a future release. Maybe it's not a good way, but it's better than no way. Good News: It works for me, and I hope it does for you, too. Regards Brewman

    C# question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups