From cd03e4301e8fa8bf23b45c8289c3b678a434d765 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 19 Apr 2007 19:29:34 +0000 Subject: [PATCH] add textAlign() with vertical param, also update constants for it --- build/shared/lib/keywords.txt | 3 ++ core/src/processing/core/PApplet.java | 6 ++++ core/src/processing/core/PConstants.java | 10 ++++++ core/src/processing/core/PGraphics.java | 44 ++++++++++++++++++++++-- core/todo.txt | 43 +++++++++++++---------- todo.txt | 38 +++++++++++++++----- 6 files changed, 115 insertions(+), 29 deletions(-) diff --git a/build/shared/lib/keywords.txt b/build/shared/lib/keywords.txt index 928da9741..7ae9c1dbf 100644 --- a/build/shared/lib/keywords.txt +++ b/build/shared/lib/keywords.txt @@ -11,10 +11,12 @@ AMBIENT LITERAL1 ARROW LITERAL1 ARGB LITERAL1 BACKSPACE LITERAL1 +BASELINE LITERAL1 BEVEL LITERAL1 BLEND LITERAL1 BLUE_MASK LITERAL1 BLUR LITERAL1 +BOTTOM LITERAL1 CENTER LITERAL1 CENTER_RADIUS LITERAL1 CHATTER LITERAL1 @@ -109,6 +111,7 @@ TIFF LITERAL1 TFF LITERAL1 THRESHOLD LITERAL1 THIRD_PI LITERAL1 +TOP LITERAL1 TRIANGLE_FAN LITERAL1 TRIANGLES LITERAL1 TRIANGLE_STRIP LITERAL1 diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 9123060ee..976564c8f 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -7418,6 +7418,12 @@ public class PApplet extends Applet } + public void textAlign(int alignX, int alignY) { + if (recorder != null) recorder.textAlign(alignX, alignY); + g.textAlign(alignX, alignY); + } + + public float textAscent() { return g.textAscent(); } diff --git a/core/src/processing/core/PConstants.java b/core/src/processing/core/PConstants.java index a191aac0b..5f6012f91 100644 --- a/core/src/processing/core/PConstants.java +++ b/core/src/processing/core/PConstants.java @@ -202,6 +202,16 @@ public interface PConstants { static final int CENTER = 3; + // vertically alignment modes for text + + /** Default vertical alignment for text placement */ + static final int BASELINE = 0; + /** Align text to the top */ + static final int TOP = 101; + /** Align text from the bottom, using the baseline. */ + static final int BOTTOM = 102; + + // uv texture orientation modes static final int NORMALIZED = 1; //_SPACE = 0; // 0..1 diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 9db165c55..5979f0e9b 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -314,6 +314,9 @@ public abstract class PGraphics extends PImage implements PConstants { /** The current text align (read-only) */ public int textAlign; + /** The current vertical text alignment (read-only) */ + public int textAlignY; + /** The current text mode (read-only) */ public int textMode; @@ -2105,9 +2108,21 @@ public abstract class PGraphics extends PImage implements PConstants { /** * Sets the alignment of the text to one of LEFT, CENTER, or RIGHT. + * This will also reset the vertical text alignment to BASELINE. */ public void textAlign(int align) { - textAlign = align; + textAlign(align, BASELINE); + } + + + /** + * Sets the horizontal and vertical alignment of the text. The horizontal + * alignment can be one of LEFT, CENTER, or RIGHT. The vertical alignment + * can be TOP, BOTTOM, CENTER, or the BASELINE (the default). + */ + public void textAlign(int alignX, int alignY) { + textAlign = alignX; + textAlignY = alignY; } @@ -2208,7 +2223,7 @@ public abstract class PGraphics extends PImage implements PConstants { "in Processing beta"); } if ((mode != SCREEN) && (mode != MODEL)) { - throw new RuntimeException("Only textMode(SCREEN) or textMode(MODEL) " + + throw new RuntimeException("Only textMode(SCREEN) and textMode(MODEL) " + "are available with this renderer."); } @@ -2380,6 +2395,30 @@ public abstract class PGraphics extends PImage implements PConstants { } str.getChars(0, length, textBuffer, 0); + // If multiple lines, sum the height of the additional lines + float high = 0; //-textAscent(); + for (int i = 0; i < length; i++) { + if (textBuffer[i] == '\n') { + high += textLeading; + } + } + if (textAlignY == CENTER) { + // for a single line, this adds half the textAscent to y + // for multiple lines, subtract half the additional height + //y += (textAscent() - textDescent() - high)/2; + y += (textAscent() - high)/2; + } else if (textAlignY == TOP) { + // for a single line, need to add textAscent to y + // for multiple lines, no different + y += textAscent(); + } else if (textAlignY == BOTTOM) { + // for a single line, this is just baseline (unchanged) + // for multiple lines, subtract leading for each line + y -= high; + //} else if (textAlignY == BASELINE) { + // do nothing + } + int start = 0; int index = 0; while (index < length) { @@ -2427,6 +2466,7 @@ public abstract class PGraphics extends PImage implements PConstants { } else if (textAlign == RIGHT) { x -= textWidthImpl(buffer, start, stop); } + textLinePlacedImpl(buffer, start, stop, x, y); } diff --git a/core/todo.txt b/core/todo.txt index 1c7a534ea..ec77550de 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -27,9 +27,11 @@ X http://dev.processing.org/bugs/show_bug.cgi?id=513 X constant CENTER_RADIUS will be changed to just RADIUS X CENTER_RADIUS is being deprecated, not removed _ remove CENTER_RADIUS from any p5 code -X splitTokens() added -_ need to add reference for splitTokens -_ need to edit reference for split (regexp?) +X split() inconsistency (emailed casey, will discuss later) +X make split(String, String) behave like String.split(String) +X and make current split(String) into splitTokens(String) +_ add splitTokens() documentation +_ document new version of split() and regexp _ should we mention String.split? X ironed out more of the preproc parseXxxx() functions _ update the reference to cover these decisions @@ -49,6 +51,22 @@ X updatePixels ref is wrong X has x/y/w/h version X the reference is also cut off X make ENTER, TAB, etc all into char values (instead of int) +X some way to vertically center text +X either by setting its middle vertical point +X or by setting a top/bottom for the rectangle in which it should be placed +o maybe textAlign(CENTER | VERTICAL_CENTER); +X or TOP, MIDDLE, and BOTTOM +o textAlign(CENTER | TOP); +o could even have textAlign(CENTER) and textAlign(TOP) not replace each other +X or textAlign(LEFT, MIDDLE); -> this one seems best +X add reference for new param, and update keywords.txt + + +_ look into capabilities stuff from mike creighton +_ also sets the aa mode on the pc so it no longer needs control panel bunk + +_ when using createFont("xxxx.ttf"), should use textMode(SHAPE) +_ because ttf files will not be installed on the system when opening pdf _ copy() should automatically call updatePixels() _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1173394373 @@ -56,12 +74,6 @@ _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=displ _ rect() after strokeWeight(1) gives wrong coords _ http://dev.processing.org/bugs/show_bug.cgi?id=535 -X split() inconsistency (emailed casey, will discuss later) -X make split(String, String) behave like String.split(String) -X and make current split(String) into splitTokens(String) -_ add splitTokens() documentation -_ document new version of split() and regexp - _ text(char c) with char 0 and undefined should print nothing _ perhaps also DEL or other nonprintables? _ book example 25-03 @@ -87,6 +99,8 @@ _ add to open() reference problems with mac _ need to use the 'open' command on osx _ or need to do this by hand _ prolly better to do it by default, since on windows we use cmd? +_ check to see if the user has 'open' in there already +_ they can call Runtime.getRuntime().exec() if they want more control should be fixed, but needs to be tested _ saveFrame() produces a black background because bg not set correctly: @@ -298,6 +312,8 @@ _ check with the a_Displaying example and tint(255, 0, 0, 100); _ http://dev.processing.org/bugs/show_bug.cgi?id=90 _ is fill() not coloring textures properly? _ don't need to apply tint() to textures, supposed to use fill color +Hope this helps: If you haven't tracked it down yet... it's in PTriangle, when a flat-shaded textured triangle is drawn, then the rgb of the tint isn't used. So, for example, if the triangle renderer branches to drawsegment_texture32() the tint rgb won't be used, whereas if it branches to drawsegment_gouraud_texture32() then the tint rgb WILL be used. Alpha gets used from tint, because all alpha has to do is be != 255, but for rgb to get used they values have to differ among vertices (which won't happen via the image() routine for example). The quick fix might be to insert an additional test in setIntensities() to check if parent.tint is true, and if so then force gouraud shading, INTERPOLATE_RGB=true. + add to reference _ also parseInt and parseFloat, how they can return another number or NaN @@ -315,15 +331,6 @@ _ even though the main() wants to keep going _ cameraXYZ doesn't seem to actually be used for anything _ since camera functions don't even look at it or set it -_ some way to vertically center text -_ either by setting its middle vertical point -_ or by setting a top/bottom for the rectangle in which it should be placed -_ maybe textAlign(CENTER | VERTICAL_CENTER); -_ or TOP, MIDDLE, and BOTTOM -_ textAlign(CENTER | TOP); -_ could even have textAlign(CENTER) and textAlign(TOP) not replace each other -_ or textAlign(LEFT, MIDDLE); -> this one seems best - _ AIOOBE on PLine 757.. halts renderer _ add notes about fixing serial on the mac to the faq (and link to bug) diff --git a/todo.txt b/todo.txt index 0cdbf50d5..b35208136 100644 --- a/todo.txt +++ b/todo.txt @@ -24,6 +24,33 @@ X re-architect svg to properly inherit fill/stroke/etc from parents X object can specify fill/stroke for everyone below X need to discern between having a fill specified and one not being present +_ disallow .java tabs with same name as the sketch +_ a .java tab with same name as the sketch is allowed (oog!) +_ particularly look at "save as" scenario +_ http://dev.processing.org/bugs/show_bug.cgi?id=543 +_ bug report: +_ create a new sketch, write something in it +_ create a new tab, name it "something.java", write something into it +_ rename main tab (sketch) to "something" (without ".java") +_ the contents in the files are not the same, but the main-tab is +_ showing the contents of the .java tab, so if you press save +_ you will overwrite your original code from the main-tab. + +_ show progress bar while rebuilding sketch menu +_ startup is very slow on g4 + + +LIBRARIES / Net + +_ move the useful serial buffering fxns into net library +_ make the Client list public +_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1116056805 +_ add an event to Server that notifies when a Client disconnects +_ proccessing.net.Client.write(int) terminates sketch when client disconnects. +_ http://dev.processing.org/bugs/show_bug.cgi?id=537 +_ Server.write(bytes[]) hangs sketch on client disconnect. +_ http://dev.processing.org/bugs/show_bug.cgi?id=538 + _ java.extension.dirs has the library/extn stuff _ can probably set this blank _ the jar from which a class file has been loaded @@ -1001,14 +1028,6 @@ _ could instead use texsubimage in opengl, etc _ only supports tint() (to set alpha or color) and drawing? just drawing? -LIBRARIES / Net - -_ add an event to Server that notifies when a Client disconnects -_ move the useful serial buffering fxns into net library -_ make the Client list public -_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1116056805 - - LIBRARIES / Serial _ port buffering not working properly @@ -1122,7 +1141,8 @@ _ mac standard key combinations for moving around in the editor _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1093116515 _ put stdout/stderr into ~/Library/Logs _ and have a .log extension so it can be browsed properly - +_ processing cancels shutdown on mac os x +_ http://dev.processing.org/bugs/show_bug.cgi?id=539 DIST / Linux