Skip to content

Commit a8d0718

Browse files
committedApr 9, 2015
Filling in some more javadoc.

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed
 

‎src/main/java/li/cil/oc/api/Manual.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public static void addProvider(ContentProvider provider) {
7171
* the image URL, i.e. <tt>![tooltip](prefix:data)</tt> will select the
7272
* image provider registered for the prefix <tt>prefix</tt>, and pass to
7373
* it the argument <tt>data</tt>, then use the returned renderer to draw
74-
* an element in the place of the tag.
74+
* an element in the place of the tag. The provided prefix is expected to
75+
* be <em>without</em> the colon (<tt>:</tt>).
7576
* <p/>
7677
* Custom providers are only selected if a prefix is matched, otherwise
7778
* it'll treat it as a relative path to an image to load via Minecraft's
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
package li.cil.oc.api.manual;
22

33
/**
4-
* Created by fnuecke on 4/9/2015.
4+
* This allows implementing custom image providers for rendering custom content
5+
* in manual pages. Each provider can be registered for one or more prefixes,
6+
* and will be selected based on the prefix it was registered with. It is
7+
* expected to return an image renderer, which essentially represents the
8+
* area it will render to.
59
*/
610
public interface ImageProvider {
7-
ImageRenderer getImage(String href);
11+
/**
12+
* Gets an image renderer for the specified data.
13+
* <p/>
14+
* The data passed here will be part of the image URL following the prefix
15+
* that the provider was registered with. So for example, if the provider
16+
* was registered for the prefix <tt>custom</tt>, and the image to be
17+
* rendered in the Markdown document was <tt>[blah](custom:the data]</tt>,
18+
* then the string passed where would be <tt>the data</tt>.
19+
* <p/>
20+
* If there is no appropriate image renderer (for example, for the built-in
21+
* item stack renderers: if the item definition is invalid), this should
22+
* return <tt>null</tt>, it should <em>never</em> throw an exception.
23+
*
24+
* @param data the data part of the image definition.
25+
* @return the image renderer for the data.
26+
*/
27+
ImageRenderer getImage(String data);
828
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
11
package li.cil.oc.api.manual;
22

33
/**
4-
* Created by fnuecke on 4/9/2015.
4+
* This allows implementing custom image renderers.
5+
* <p/>
6+
* Image renderers are used to draw custom areas in a manual page, defined as
7+
* an image with a special URL, matching the prefix of a registered image
8+
* provider. A renderer will then be used to draw something at the position
9+
* of the image tag.
10+
* <p/>
11+
* Built-in image renderers are <tt>item</tt>, <tt>block</tt>, <tt>oredict</tt>
12+
* and <tt>recipe</tt>.
513
*/
614
public interface ImageRenderer {
15+
/**
16+
* The width of the area this renderer uses.
17+
* <p/>
18+
* This is used to offset the OpenGL state properly before calling
19+
* {@link #render(int)}, as well as to know where to resume rendering
20+
* other content below the image.
Has a conversation. Original line has a conversation.
21+
*
22+
* @return the width of the rendered image.
23+
*/
724
int getWidth();
825

26+
/**
27+
* The height of the area this renderer uses.
28+
* <p/>
29+
* This is used to compute the
Has conversations. Original line has conversations.
30+
*
31+
* @return the height of the rendered image.
32+
*/
933
int getHeight();
1034

35+
/**
36+
* Render the image, with specified maximum width.
37+
* <p/>
38+
* This should render the image as is, the OpenGL state will be set up
39+
* such that you can start drawing at (0,0,*), and render up to
40+
* (getWidth,getHeight,*).
41+
*
42+
* @param maxWidth the maximum width usable for rendering.
43+
*/
1144
void render(int maxWidth);
1245
}

‎src/main/scala/li/cil/oc/util/PseudoMarkdown.scala

+8-8
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,9 @@ object PseudoMarkdown {
492492
}
493493

494494
object ItemRenderProvider extends ImageProvider {
495-
override def getImage(href: String): ImageRenderer = {
496-
val splitIndex = href.lastIndexOf('@')
497-
val (name, optMeta) = if (splitIndex > 0) href.splitAt(splitIndex) else (href, "")
495+
override def getImage(data: String): ImageRenderer = {
496+
val splitIndex = data.lastIndexOf('@')
497+
val (name, optMeta) = if (splitIndex > 0) data.splitAt(splitIndex) else (data, "")
498498
val meta = if (Strings.isNullOrEmpty(optMeta)) 0 else Integer.parseInt(optMeta.drop(1))
499499
Item.itemRegistry.getObject(name) match {
500500
case item: Item => new ItemStackRenderer(Array(new ItemStack(item, 1, meta)))
@@ -504,9 +504,9 @@ object PseudoMarkdown {
504504
}
505505

506506
object BlockRenderProvider extends ImageProvider {
507-
override def getImage(href: String): ImageRenderer = {
508-
val splitIndex = href.lastIndexOf('@')
509-
val (name, optMeta) = if (splitIndex > 0) href.splitAt(splitIndex) else (href, "")
507+
override def getImage(data: String): ImageRenderer = {
508+
val splitIndex = data.lastIndexOf('@')
509+
val (name, optMeta) = if (splitIndex > 0) data.splitAt(splitIndex) else (data, "")
510510
val meta = if (Strings.isNullOrEmpty(optMeta)) 0 else Integer.parseInt(optMeta.drop(1))
511511
Block.blockRegistry.getObject(name) match {
512512
case block: Block => new ItemStackRenderer(Array(new ItemStack(block, 1, meta)))
@@ -516,8 +516,8 @@ object PseudoMarkdown {
516516
}
517517

518518
object OreDictRenderProvider extends ImageProvider {
519-
override def getImage(desc: String): ImageRenderer = {
520-
val stacks = OreDictionary.getOres(desc)
519+
override def getImage(data: String): ImageRenderer = {
520+
val stacks = OreDictionary.getOres(data)
521521
if (stacks != null && stacks.nonEmpty) new ItemStackRenderer(stacks.toArray(new Array[ItemStack](stacks.size())))
522522
else null
523523
}

0 commit comments

Comments
 (0)
Please sign in to comment.