├── LICENSE
├── README.md
├── games
├── ScreenMouse2.pb
├── Screen_Mouse.pb
└── tuto2D.pb
├── images
├── Blendmode.pb
├── CircleBrush.pb
└── Palette.pb
└── windows_gadgets
└── WindowCreator.pb
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Purebasic
2 | Some purebasic applications & codes , under GPL.
3 |
4 | Apllications :
5 | - animatoon : a 2D bitmap application to paint and transform image (resize, color, layers, brush...)
6 | - Sprite animation : to create animation with sprite (with sprite and bones)
7 | - cartoon : a 2D vector drawing and animation application
8 |
9 | Other little codes :
10 | - images : blendmode, circle brush, palette
11 | - games : screen_mouse, tuto2D
12 | - windows_gadget : windows creator
13 |
14 | Cheers !
15 |
--------------------------------------------------------------------------------
/games/ScreenMouse2.pb:
--------------------------------------------------------------------------------
1 | ; PB : 5.22 / 5.31
2 | ; june 2015
3 | ; by Blendman
4 |
5 |
6 | InitSprite()
7 | InitMouse()
8 | InitKeyboard()
9 |
10 | screenwidth = 1024
11 | screenheight = 768
12 | ScreenX = 50
13 | ScreenY = 50
14 | If OpenWindow(0, 0, 0, screenwidth, screenheight, "Antialiased Line Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) : EndIf
15 |
16 | If OpenWindowedScreen(WindowID(0),ScreenX,ScreenY,screenwidth-100, screenheight-100)=0
17 | MessageRequester("Error", "Can't Open Screen!", 0)
18 | End
19 | EndIf
20 |
21 | ShowCursor_(1)
22 |
23 | Repeat
24 |
25 | mx = WindowMouseX(0) - ScreenX
26 | my = WindowMouseY(0) - ScreenY
27 |
28 | ; first, verify the events
29 |
30 | Repeat
31 | ; needed to not freeze the window !
32 | Event = WaitWindowEvent(1)
33 | EventMenu = EventMenu()
34 | EventGadget = EventGadget()
35 | EventType = EventType()
36 | EventWindow = EventWindow()
37 |
38 | If Event >0
39 |
40 | Select Event
41 |
42 | Case #PB_Event_Menu ; event menu
43 |
44 | Case #PB_Event_Gadget ; event gadgets to test
45 |
46 | Case #WM_LBUTTONDOWN
47 | MouseClic = 1
48 |
49 | Case #WM_LBUTTONUP
50 | MouseClic = 0
51 |
52 | Case #PB_Event_CloseWindow
53 | quit = 1
54 |
55 | EndSelect
56 |
57 | EndIf
58 |
59 | Until Event = 0 Or event = #WM_LBUTTONDOWN Or Event = #WM_LBUTTONUP
60 |
61 | ; we need to test what we are doing on the screen surface
62 | If Mx>0 And My>0 And Mx0
30 |
31 | Select Event
32 |
33 | Case #PB_Event_Menu ; menu to test / les events menus à tester
34 |
35 | Case #PB_Event_Gadget ; event gadgets to test // les event gadgets à tester
36 |
37 | Case #WM_LBUTTONDOWN
38 | MouseClic = 1
39 |
40 | Case #WM_LBUTTONUP
41 | MouseClic = 0
42 |
43 | Case #PB_Event_CloseWindow
44 | quit = 1
45 |
46 | EndSelect
47 |
48 | EndIf
49 |
50 | Until Event = 0 Or event = #WM_LBUTTONDOWN Or Event = #WM_LBUTTONUP
51 |
52 | ; puis je vérifie ce que je fais sur le screen
53 | If Mx>0 And My>0 And Mx val : x = val : EndIf ; pour empêcher d'être supérieur à une valeur, par exemple pour ne pas dépasser la taille de la map
125 | EndMacro
126 | ;}
127 |
128 | ;{ initialisation : on initialise les libs utilisées (directX sous windows, OpenGL sous linux, les sprites, sprite3D et clavier)
129 | ; il faut toujours tester toutes les fonctions, pour éviter les plantages..
130 | ; je mets un message d'erreurs si j'amais ça ne s'initialise pas, pour qu'on sache où est le soucis.
131 | If InitSprite() = 0
132 | MessageRequester("Info", "Erreur de chargement de directX (ou openGL)")
133 | End ; on ferme l'application
134 | EndIf
135 | If InitKeyboard()= 0
136 | MessageRequester("Info", "Erreur de chargement du clavier")
137 | End
138 | EndIf
139 | ;}
140 |
141 | ;{ ouverture de la fenêtre
142 | If OpenWindow(#window,0,0,800,600,"Base Jeu Scrolling",#PB_Window_ScreenCentered|#PB_Window_MaximizeGadget) = 0
143 | MessageRequester("Info", "Erreur d'ouverture de la fenêtre")
144 | End ; on ferme l'application
145 | EndIf
146 | If OpenWindowedScreen(WindowID(#window),0,0,800,600,0,0,0,#PB_Screen_SmartSynchronization)= 0
147 | MessageRequester("Info", "Erreur d'ouverture de la fenêtre")
148 | End
149 | EndIf
150 | UseJPEGImageDecoder() : UsePNGImageDecoder() ; pour charger des jpg ou des png (avec canal alpha)
151 | ;{ charger tes images/sprite
152 | If #loadsprite = 1
153 | ; si vous voulez charger des images , changer le chemin c:/images/ton_perso1.jpg , c:/images/ton_perso2.png et c:/images/ton_perso3.png
154 |
155 | LoadSprite(#perso1,"c:/images/ton_perso1.jpg", #PB_Sprite_AlphaBlending); si c'est un jpg, pas de canal alpha
156 | LoadSprite(#pnj1,"c:/images/ton_perso2.png", #PB_Sprite_AlphaBlending) ; c'est un png, on peut avoir un canal alpha
157 | LoadSprite(#pnj2,"c:/images/ton_perso3.png", #PB_Sprite_AlphaBlending) ; c'est un png, on peut avoir un canal alpha
158 | ;}
159 | ;{ créer un sprite (si besoin)
160 | Else ; on n'utilise pas d'image pour nos sprites, on peut les créer
161 | AddSprite(#perso1,32,RGBA(125,0,0,254)) ; le joueur
162 | AddSprite(#pnj1,32,RGBA(0,125,0,254)) ; les pnjs
163 | AddSprite(#pnj2,32,RGBA(0,0,125,254)) ; les pnjs
164 | EndIf
165 | ;}
166 | ;}
167 |
168 | ;{ boucle repeat
169 |
170 | Repeat
171 |
172 | Repeat
173 | event = WindowEvent() ; on attend un évènement dans la fenêtre et on stocke celui dans la variable event
174 | ; que je n'ai pas déclarée d'ailleurs, et que je déclare ici même=
175 | Select event ; on va vérifier quel évènement a lieu
176 | Case #PB_Event_CloseWindow; si on clique sur la croix
177 | quit = 1 ; on quitte
178 | EndSelect
179 |
180 | Until event = 0 Or quit = 1
181 |
182 | If ExamineKeyboard(); nécessaire pour voir si tu utilises le clavier
183 | ;{ déplacement du joueur
184 | If KeyboardPushed(#PB_Key_Right) And player\x < carte\width
185 | player\x + player\vitesse
186 | camera\x = player\x - 800/2 ; la résolution du jeu/2 ; mise à jour de la camera
187 | BorneValeurMini(camera\x,0)
188 | BorneValeurMaxi(camera\x,carte\width- 800/2)
189 | EndIf
190 | If KeyboardPushed(#PB_Key_Left) And player\x >-16
191 | player\x - player\vitesse
192 | camera\x = player\x - 800/2 ; la résolution du jeu/2 ; mise à jour de la camera
193 | BorneValeurMini(camera\x,0)
194 | BorneValeurMaxi(camera\x,carte\width- 800/2)
195 | EndIf
196 | If KeyboardPushed(#PB_Key_Up) And player\y > -16
197 | player\y - player\vitesse
198 | camera\y = player\y - 600/2 ; mise à jour de la camera
199 | BorneValeurMini(camera\y,0)
200 | BorneValeurMaxi(camera\y,carte\height- 600/2)
201 | EndIf
202 | If KeyboardPushed(#PB_Key_Down)And player\y < carte\height
203 | player\y + player\vitesse
204 | camera\y = player\y - 600/2 ; mise à jour de la camera
205 | BorneValeurMini(camera\y,0)
206 | BorneValeurMaxi(camera\y,carte\height- 600/2)
207 | EndIf
208 | EndIf
209 | ;}
210 |
211 | ;{ affichage du jeu
212 | ClearScreen(RGB(125,125,125)); on efface l'écran avec du gris
213 |
214 | ; d'abord je dessine tous les pnj. j'aurai pu aussi utiliser une list(), ou une map(), mais pour ce 1er exemple, j'ai utilisé un tableau
215 | For i = 0 To ArraySize(pnj())
216 | DisplayTransparentSprite(pnj(i)\sprite,pnj(i)\x-camera\x,pnj(i)\y-camera\y)
217 | Next i
218 | DisplayTransparentSprite(#perso1,player\x-camera\x,player\y-camera\y)
219 |
220 | If StartDrawing(ScreenOutput())
221 | DrawingMode(#PB_2DDrawing_Transparent); on met le mode transparent pour le texte
222 | DrawText(player\x-camera\x,player\y-camera\y,Str(player\x)+"/"+Str(player\y))
223 | StopDrawing()
224 | EndIf
225 |
226 | FlipBuffers(); on "flippe" le buffer, utile pour les jeux vidéos, histoire de ne pas avoir de flickering, tearing (écran déchiré)
227 | ;}
228 |
229 |
230 | Until KeyboardPushed(#PB_Key_Escape) Or quit = 1
231 |
232 | End ; pas obligé, mais ça indique qu'on a terminé
233 |
234 | ;}
235 |
236 | ;{ les procedures
237 | ; creation des sprites
238 | Procedure AddSprite(sprite,size,color)
239 |
240 | If CreateSprite(sprite,size,size,#PB_Sprite_AlphaBlending) : EndIf; j'utilise #PB_Sprite_Texture, car on va en faire un sprite3D juste après
241 | ; on dessine sur le sprite créé (ici, juste un cercle)
242 | If StartDrawing(SpriteOutput(sprite)) ; on lui indique sur quoi on va dessiner
243 |
244 | DrawingMode(#PB_2DDrawing_AllChannels)
245 | Box(0,0,OutputWidth(),OutputHeight(),RGBA(0,0,0,0))
246 | DrawingMode(#PB_2DDrawing_AlphaBlend)
247 | Circle(size/2,size/2,size/2,color)
248 | StopDrawing()
249 | EndIf
250 |
251 | EndProcedure
252 |
253 | ;}
254 |
255 | ;{ si besoin, les data sections
256 | DataSection
257 | image1:
258 | ; chemin de ton image
259 | ; pour l'utiliser, dans la section charger tes images :
260 | ; CatchSprite(sprite,?image1,#PB_Sprite_Texture|#PB_Sprite_Alpha)
261 | EndDataSection
262 | ;}
263 | ; IDE Options = PureBasic 5.42 LTS (Windows - x64)
264 | ; CursorPosition = 212
265 | ; FirstLine = 199
266 | ; Folding = ---------
267 | ; EnableUnicode
268 | ; EnableXP
--------------------------------------------------------------------------------
/images/Blendmode.pb:
--------------------------------------------------------------------------------
1 | ;{ infos
2 | ; test blendmode by blendman 07/2011
3 | ; pb : 4.60
4 | ; ok for 5.22 & 5.31
5 | ; june 2015
6 | ; for animatoon, my 2D painting and animation free software
7 | ;}
8 |
9 | ;{ variables & globales
10 | Enumeration
11 | #fond
12 | #layer1
13 | #alpha_layer1
14 | #tempo
15 | #result
16 | #imagefinal
17 | EndEnumeration
18 |
19 | Global mode.b = 1
20 | ;}
21 |
22 | ;{ init
23 | If UseJPEGImageDecoder() =0 Or UsePNGImageDecoder() =0
24 | End
25 | EndIf
26 | ;}
27 |
28 | ;{ declare
29 | Declare affiche_img()
30 | Declare bm_add(x, y, SourceColor, TargetColor)
31 | Declare bm_multiply(x, y, SourceColor, TargetColor)
32 | Declare bm_overlay(x, y, SourceColor, TargetColor)
33 | Declare bm_screen(x, y, SourceColor, TargetColor)
34 | Declare Changemode()
35 | ;}
36 |
37 | ;{ open window & create image
38 | file$ = OpenFileRequester("Image","","Image|*.jpg;*.png|*.bmp",0)
39 | If file$ = ""
40 | End
41 | EndIf
42 |
43 | LoadImage(#fond, file$)
44 | Global w,h
45 | w = ImageWidth(#fond)
46 | h = ImageHeight(#fond)
47 |
48 |
49 | If OpenWindow(0, 0, 0, w, h, "Blendmode test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
50 |
51 | ;{ menu
52 | If CreateMenu(0,WindowID(0))
53 | MenuTitle("BlendMode")
54 | MenuItem(1,"BlendMode suivant"+Chr(9)+"+")
55 | MenuItem(2,"BlendMode précédent"+Chr(9)+"-")
56 | EndIf
57 | ;}
58 |
59 | ;{ images
60 |
61 | ; image (layer1 : simple red circle
62 | CreateImage(#layer1,w,h,32)
63 | StartDrawing(ImageOutput(#layer1))
64 | DrawingMode(#PB_2DDrawing_AlphaChannel)
65 | Box(0,0,w,h,RGBA(0,0,0,0))
66 | DrawingMode(#PB_2DDrawing_AlphaBlend)
67 | Circle(300, 100, 100,RGBA(255,0,0,255))
68 | StopDrawing()
69 |
70 | CopyImage(#layer1,#alpha_layer1)
71 |
72 | ; copy for the image temporary for alpha chanel // copie pour le canal alpha
73 | CreateImage(#tempo,w,h,32)
74 | StartDrawing(ImageOutput(#tempo))
75 | DrawingMode(#PB_2DDrawing_AlphaChannel)
76 | Box(0,0,w,h,RGBA(0,0,0,0))
77 | StopDrawing()
78 |
79 | If CreateImage(#imagefinal, w, h,32)
80 | affiche_Img()
81 | EndIf
82 | ;}
83 |
84 | ;{ shortcut
85 | AddKeyboardShortcut(0,#PB_Shortcut_Add,1)
86 | AddKeyboardShortcut(0,#PB_Shortcut_Subtract,2)
87 | ;}
88 |
89 | Else
90 |
91 | MessageRequester("Erreur", "impossible d'ouvrir une fenêtre")
92 | End
93 |
94 | EndIf
95 | ;}
96 |
97 | Repeat
98 | Changemode()
99 | Until Event = #PB_Event_CloseWindow
100 |
101 | ;{ procedure
102 | Procedure affiche_img()
103 | ; on calcule le blendmode, uniquement sur l'alpha opaque lié au layer1
104 | If StartDrawing(ImageOutput(#tempo))
105 | ; image de fond, on peut utiliser une image avec transparence
106 | DrawingMode(#PB_2DDrawing_AlphaBlend)
107 | DrawImage(ImageID(#fond), 0, 0, w, h)
108 | ; puis on affiche l'image du dessus en fonction du mode de fusion choisi
109 | If mode =0 ; normal
110 | DrawingMode(#PB_2DDrawing_Default)
111 | ElseIf mode <>0
112 | DrawingMode(#PB_2DDrawing_CustomFilter)
113 | If mode = 1 ; add
114 | CustomFilterCallback(@bm_add())
115 | ElseIf mode = 2 ; multiply
116 | CustomFilterCallback(@bm_multiply())
117 | ElseIf mode = 3 ; overlay
118 | CustomFilterCallback(@bm_overlay())
119 | ElseIf mode = 4 ; screen
120 | CustomFilterCallback(@bm_screen())
121 | EndIf
122 | EndIf
123 | DrawAlphaImage(ImageID(#layer1),0,0)
124 | DrawingMode(#PB_2DDrawing_AlphaChannel)
125 | DrawAlphaImage(ImageID(#alpha_layer1),0,0)
126 | StopDrawing()
127 | EndIf
128 |
129 | ; on calcule le resultat, l'image finale
130 | If StartDrawing(ImageOutput(#imagefinal))
131 | DrawImage(ImageID(#fond), 0, 0, w, h) ; image de fond, on peut utiliser une image avec transparence
132 | DrawingMode(#PB_2DDrawing_AlphaBlend)
133 | DrawAlphaImage(ImageID(#tempo),0,0)
134 | StopDrawing()
135 | EndIf
136 | ImageGadget(0, 0, 0, w, h, ImageID(#imagefinal))
137 |
138 | Select mode
139 | Case 0
140 | SetWindowTitle(0,"Mode : Normal - cercle rouge")
141 | Case 1
142 | SetWindowTitle(0,"Mode : Add - cercle blanc")
143 | Case 2
144 | SetWindowTitle(0,"Mode : Multiply - cercle rouge")
145 | Case 3
146 | SetWindowTitle(0,"Mode : Overlay - cercle rouge")
147 | Case 4
148 | SetWindowTitle(0,"Mode : Screen - cercle blanc")
149 | EndSelect
150 |
151 | EndProcedure
152 |
153 | Procedure.l min(a.l,b.l)
154 | If a>b
155 | ProcedureReturn b
156 | EndIf
157 | ProcedureReturn a
158 | EndProcedure
159 |
160 | Procedure bm_screen(x, y, SourceColor, TargetColor)
161 | ; color = 255 - ( ( 255 - bottom ) * ( 255 - top ) ) / 255
162 | red = 255 -((255-Red(SourceColor))*(255-Red(TargetColor)))/255
163 | green = 255 -((255-Green(SourceColor))*(255-Green(TargetColor)))/255
164 | blue = 255 -((255-Blue(SourceColor))*(255-Blue(TargetColor)))/255
165 | ProcedureReturn RGBA(red,green,blue, Alpha(TargetColor))
166 | EndProcedure
167 |
168 | Procedure bm_add(x, y, SourceColor, TargetColor)
169 | ; color = top >= 255? 255 : min(bottom * 255 / (255 - top), 255)
170 | If Red(TargetColor) >= 255
171 | Red.l= 255
172 | Else
173 | result.l= 255 - Red(SourceColor)
174 | If result >0
175 | Red =min(Red(TargetColor) * 255 / (result), 255)
176 | ElseIf result =0
177 | red=min(Red(TargetColor) * 255, 255)
178 | EndIf
179 | EndIf
180 |
181 | If Blue(TargetColor) >= 255
182 | blue = 255
183 | Else
184 | result= 255 - Blue(SourceColor)
185 | If result >0
186 | blue=min(Blue(TargetColor) * 255 / (result), 255)
187 | ElseIf result =0
188 | blue = min(Blue(TargetColor) * 255, 255)
189 | EndIf
190 | EndIf
191 |
192 | If Green(TargetColor) >= 255
193 | Green = 255
194 | Else
195 | result= 255 - Green(SourceColor)
196 | If result >0
197 | Green =min(Green(TargetColor) * 255 / (result), 255)
198 | ElseIf result =0
199 | green =min(Green(TargetColor) * 255, 255)
200 | EndIf
201 | EndIf
202 |
203 | ProcedureReturn RGBA(red, green, blue, Alpha(TargetColor))
204 | EndProcedure
205 |
206 | Procedure bm_multiply(x, y, SourceColor, TargetColor)
207 | ProcedureReturn RGBA((Red(SourceColor)*Red(TargetColor))/255,(Green(SourceColor)*Green(TargetColor))/255,(Blue(SourceColor)*Blue(TargetColor))/255, Alpha(TargetColor)*Alpha(TargetColor)/255)
208 | EndProcedure
209 |
210 | Macro overlay(color_source,color_targ, colo)
211 | If color_source <128
212 | colo = ( 2 * color_source*color_targ ) / 255
213 | Else
214 | colo =255 - ( 2 * ( 255 - color_source ) * ( 255 - color_targ ) / 255 )
215 | EndIf
216 | EndMacro
217 |
218 | Procedure bm_overlay(x, y, SourceColor, TargetColor)
219 | ; color = bottom < 128 ? ( 2 * bottom * top ) / 255 : 255 - ( 2 * ( 255 - bottom ) * ( 255 - top ) / 255 )
220 | overlay(Red(TargetColor),Red(SourceColor), red)
221 | overlay(Blue(TargetColor),Blue(SourceColor), blue)
222 | overlay(Green(TargetColor),Green(SourceColor), green)
223 |
224 | ProcedureReturn RGBA(red, green, blue, Alpha(TargetColor))
225 | EndProcedure
226 |
227 | Procedure Changemode()
228 | Event = WaitWindowEvent()
229 | Select event
230 | Case #PB_Event_CloseWindow
231 | End
232 | Case #PB_Event_Menu
233 | Select EventMenu()
234 | Case 1
235 | If mode<4
236 | mode +1
237 | Else
238 | mode = 0
239 | EndIf
240 | affiche_img()
241 |
242 | Case 2
243 | If mode>0
244 | mode -1
245 | Else
246 | mode = 4
247 | EndIf
248 | affiche_img()
249 | EndSelect
250 | EndSelect
251 | EndProcedure
252 | ;}
253 |
--------------------------------------------------------------------------------
/images/CircleBrush.pb:
--------------------------------------------------------------------------------
1 | ; PB 5.11 - 5.22 - 5.31
2 | ; 2013 - june 2015
3 | ; by blendman
4 | ; for Animatoon (my 2D painting and animation software)
5 |
6 | Enumeration ; gadget
7 | #Gadget_image
8 | #Gadget_GradientX
9 | #Gadget_GradientX2
10 | #Gadget_GradientX3
11 | #Gadget_Radius
12 | EndEnumeration
13 |
14 | Global gradientX.d=0.1, gradientX2.d=0.1, radius.w = 800,gradientX3.d = 0.5
15 |
16 | Macro Update()
17 | If StartDrawing(ImageOutput(0))
18 | Box(0, 0, 400, 200, $FFFFFF)
19 | DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AlphaBlend)
20 | ;BackColor(RGBA(0,0,0,255))
21 | GradientColor(gradientX, 0)
22 | GradientColor(gradientX3, RGBA(0,0,0,125))
23 | GradientColor(gradientX2, RGBA(0,0,0,0))
24 | ;FrontColor(RGBA(0,0,0,0))
25 | CircularGradient(100, 100, radius)
26 | Box(0,0,200,200)
27 | StopDrawing()
28 | EndIf
29 | Debug gradientX2
30 | EndMacro
31 |
32 | If OpenWindow(0, 0, 0, 400, 200, "Brush Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
33 |
34 | If CreateImage(0, 200, 200)
35 | Update()
36 | ImageGadget(#Gadget_image, 0, 0, 400, 200, ImageID(0))
37 | EndIf
38 | x = 30
39 | TrackBarGadget(#Gadget_GradientX,220,x,150,20,1,100)
40 | SetGadgetState(#Gadget_GradientX,gradientX *100)
41 |
42 | TrackBarGadget(#Gadget_GradientX2,220,x*2,150,20,1,100)
43 | SetGadgetState(#Gadget_GradientX2,gradientX2 *100)
44 |
45 | TrackBarGadget(#Gadget_GradientX3,220,x*3,150,20,1,100)
46 | SetGadgetState(#Gadget_GradientX3,gradientX3 *100)
47 |
48 | TrackBarGadget(#Gadget_Radius,220,x*4,150,20,1,1000)
49 | SetGadgetState(#Gadget_Radius,radius)
50 |
51 | Repeat
52 | Event = WaitWindowEvent()
53 |
54 | Select event
55 |
56 | Case #PB_Event_Gadget
57 |
58 | Select EventGadget()
59 |
60 | Case #Gadget_GradientX
61 | gradientX= GetGadgetState(#Gadget_GradientX)/100
62 | update()
63 | SetGadgetState(#Gadget_image,ImageID(0))
64 |
65 | Case #Gadget_GradientX2
66 | gradientX2 = GetGadgetState(#Gadget_GradientX2)/100
67 | update()
68 | SetGadgetState(#Gadget_image,ImageID(0))
69 |
70 | Case #Gadget_GradientX3
71 | gradientX3 = GetGadgetState(#Gadget_GradientX3)/100
72 | update()
73 | SetGadgetState(#Gadget_image,ImageID(0))
74 |
75 | Case #Gadget_Radius
76 | radius = GetGadgetState(#Gadget_Radius)
77 | update()
78 | SetGadgetState(#Gadget_image,ImageID(0))
79 |
80 | EndSelect
81 |
82 | EndSelect
83 |
84 | Until Event = #PB_Event_CloseWindow
85 | EndIf
86 |
87 |
--------------------------------------------------------------------------------
/images/Palette.pb:
--------------------------------------------------------------------------------
1 | ; open a palette *.gpl (gimp, mypaint, krita, animatoon)
2 | ; pb 5.22 / 5.31
3 | ; date : 25/06/2015
4 | ; by blendman
5 | ; For animatoon, my 2D painting and animation free software
6 |
7 | #Win_Swatch = 0
8 |
9 | Enumeration
10 |
11 | #G_WinSwatchScroll
12 | #G_WinSwatchCanvas
13 | #G_WinSwatchNbCol
14 | #G_WinSwatchName
15 | #G_WinSwatchNameSwatch
16 |
17 | #G_WinSwatchSave
18 | #G_WinSwatchNew
19 | #G_WinSwatchOpen
20 | #G_WinSwatchMerge
21 | #G_WinSwatchFromImg
22 |
23 | #G_WinSwatchAdd
24 | #G_WinSwatchDel
25 | #G_WinSwatchInsert
26 |
27 |
28 | EndEnumeration
29 |
30 | UsePNGImageDecoder()
31 | UseJPEGImageDecoder()
32 |
33 |
34 | ;{ structures
35 | Structure sColor
36 | R.a
37 | G.a
38 | B.a
39 | EndStructure
40 | Structure sSwatch
41 | col.sColor
42 | Color.i
43 | x.w
44 | y.w
45 | name$
46 | EndStructure
47 | Structure sPalette
48 | name$
49 | column.w
50 | Array swatch.sSwatch(0)
51 |
52 | EndStructure
53 |
54 |
55 | Global Dim SwatchColor.sPalette(0)
56 | SwatchColor(0)\column = 7
57 | SwatchColor(0)\name$ = "Palette test"
58 |
59 | Global SwatchId = 0
60 | ;}
61 |
62 |
63 | Procedure AddSwatchColor(r,g,b, name$="")
64 |
65 | n = ArraySize(SwatchColor(SwatchId)\swatch())
66 |
67 | With SwatchColor(SwatchId)\swatch(n)
68 |
69 | \Color = RGB(r,g,b)
70 | \col\R = r
71 | \col\G = g
72 | \col\B = b
73 | \name$ = name$
74 |
75 | EndWith
76 |
77 | ReDim SwatchColor(SwatchId)\swatch(n+1)
78 |
79 | EndProcedure
80 | Procedure SwatchUpdatePropCanvas(x1=0,y1=0,Selected=0)
81 |
82 | column = SwatchColor(swatchId)\column
83 | u = Round((GadgetWidth(#G_WinSwatchCanvas)-25) / column, #PB_Round_Down)
84 | n = ArraySize(SwatchColor(swatchid)\swatch()) -1
85 |
86 | y = (1+n/column) *u
87 | If n> 0
88 | ;If GadgetHeight(#G_WinSwatchCanvas) <> y Or
89 | ResizeGadget(#G_WinSwatchCanvas,#PB_Ignore,#PB_Ignore,#PB_Ignore,y+25)
90 | SetGadgetAttribute(#G_WinSwatchScroll,#PB_ScrollArea_InnerHeight,y+50)
91 | ;EndIf
92 |
93 | EndIf
94 |
95 |
96 | If StartDrawing(CanvasOutput(#G_WinSwatchCanvas))
97 | Box(0,0,GadgetWidth(#G_WinSwatchCanvas),GadgetHeight(#G_WinSwatchCanvas),RGB(150,150,150))
98 | For i = 0 To ArraySize(SwatchColor(swatchId)\swatch())-1
99 |
100 | With SwatchColor(swatchId)\swatch(i)
101 | x = (i%column) * u
102 | y = (i/column) * u
103 | Box(x,y,u,u,RGB(\col\R,\col\G,\col\B))
104 |
105 | EndWith
106 |
107 | Next i
108 |
109 | If Selected = 1
110 | DrawingMode(#PB_2DDrawing_Outlined)
111 | Box(x1*u,y1*u,u,u,RGB(255,0,0))
112 | Box(x1*u+1,y1*u+1,u-2,u-2,RGB(0,0,0))
113 | EndIf
114 | StopDrawing()
115 |
116 | EndIf
117 |
118 | EndProcedure
119 | Procedure SwatchOpen(merge=0)
120 |
121 | If merge = 0
122 | ReDim SwatchColor(SwatchId)\swatch(0)
123 | EndIf
124 |
125 | file$ = OpenFileRequester("Open","","GPL (gimp, krita, mypaint, animatoon)|*.gpl",0)
126 | If file$ <> ""
127 | If ReadFile(0,file$)
128 |
129 | Editor$ = ReadString(0)
130 | SwatchColor(swatchId)\name$ = RemoveString(ReadString(0),"Name: ")
131 | line$ = ReadString(0)
132 | st$ = StringField(line$,2," ")
133 | SwatchColor(swatchId)\column = Val(st$)
134 |
135 | While Eof(0) = 0
136 | line$ = ReadString(0)
137 | char$ = Mid(line$,1,1)
138 |
139 | If char$ <> "#" And line$ <> ""
140 | line$ = ReplaceString(line$,Chr(9),Chr(32))
141 | While char$ = Chr(32)
142 | char$ = Mid(line$,1,1)
143 | line$ = Right(line$,Len(line$)-1)
144 | Wend
145 | While FindString(line$,Chr(32)+Chr(32)) >= 1
146 | line$ = ReplaceString(line$,Chr(32)+Chr(32),Chr(32))
147 | Wend
148 | RGB$ = line$
149 | count = CountString(line$,Chr(32))
150 | R = Val(StringField(RGB$, 1, " "))
151 | G = Val(StringField(RGB$, 2, " "))
152 | B = Val(StringField(RGB$, 3, " "))
153 | name$ =""
154 | For i = 0 To count
155 | Name$ + StringField(RGB$, 4+i, " ")
156 | Next i
157 | Name$ = ReplaceString(Name$,Chr(9),"")
158 | ;Debug Str(r)+"/"+Str(g)+"/"+Str(b)
159 | AddSwatchColor(r,g,b,name$)
160 | EndIf
161 |
162 | Wend
163 |
164 | CloseFile(0)
165 | EndIf
166 | EndIf
167 | SetGadgetState(#G_WinSwatchNbCol,SwatchColor(swatchId)\column)
168 | SetGadgetText(#G_WinSwatchName,SwatchColor(swatchId)\name$)
169 |
170 | SwatchUpdatePropCanvas()
171 |
172 |
173 | EndProcedure
174 | Procedure SwatchSave(export=0)
175 |
176 | Shared SwatchSaved$
177 | ; for save a swatch.
178 | ; format supported : GPL (gimp palette, krita...)
179 |
180 | If export = 1 ; save only
181 |
182 | File$ = SaveFileRequester("Save Swatch","","GPL (Gimp, Krita, Inkscape, Animatoon)|*.gpl",0)
183 |
184 | If File$ <> ""
185 |
186 | ext$ = LCase(GetExtensionPart(File$))
187 | If ext$ <> "gpl"
188 | file$ = RemoveString(file$,ext$)
189 | file$ + ".gpl"
190 | EndIf
191 | SwatchSaved$ = file$
192 | export = 0
193 | EndIf
194 |
195 | EndIf
196 |
197 | If export =0
198 |
199 | ;ext$ = GetExtensionPart(SwatchSaved$)
200 |
201 | ;If ext$ = "gpl"
202 |
203 | If OpenFile(0,SwatchSaved$)
204 |
205 | With SwatchColor(swatchid)
206 |
207 | WriteStringN(0, "Animatoon Palette")
208 | WriteStringN(0, "Name:"+ \name$)
209 | WriteStringN(0, "Columns: "+ Str(\column))
210 | WriteStringN(0, "# ")
211 |
212 | For i = 0 To ArraySize(SwatchColor(swatchid)\swatch())-1
213 |
214 | R$ = Str(\Swatch(i)\col\R)
215 | G$ = Str(\swatch(i)\col\G)
216 | B$ = Str(\swatch(i)\col\B)
217 | WriteStringN(0, R$+" "+G$+" "+B$+" "+\swatch(i)\name$)
218 |
219 | Next i
220 |
221 | EndWith
222 |
223 | CloseFile(0)
224 |
225 | EndIf
226 |
227 | ;EndIf
228 |
229 | EndIf
230 |
231 | EndProcedure
232 | Procedure SwatchCreateFromImage()
233 | File$ = OpenFileRequester("Open Image","","IMAGE|*.jpg;*.png;*.bmp",0)
234 | If file$ <> ""
235 | w = Val(InputRequester("Max colors", "Set the maximum number of colors (for the palette)",""))
236 | If w > 0
237 | If LoadImage(0,file$)
238 | ReDim SwatchColor(swatchId)\Swatch(0)
239 | width = Round(Sqr(w),#PB_Round_Down)
240 | Debug Sqr(w)
241 | ResizeImage(0,width,width,1)
242 | If StartDrawing(ImageOutput(0))
243 | For i= 0 To width-1
244 | For j = 0 To width-1
245 | color = Point(i,j)
246 | name$ = "color"+Str(a)
247 | ok = 1
248 | For aa = 0 To ArraySize(SwatchColor(swatchId)\Swatch())
249 | If color = SwatchColor(swatchId)\Swatch(aa)\Color
250 | ok = 0
251 | Break
252 | EndIf
253 | Next aa
254 | If ok = 1
255 | AddSwatchColor(Red(color),Green(color),Blue(color),Name$)
256 | a+1
257 | EndIf
258 | Next j
259 | Next i
260 | StopDrawing()
261 | EndIf
262 | SwatchUpdatePropCanvas()
263 | EndIf
264 | EndIf
265 | EndIf
266 | EndProcedure
267 |
268 | If OpenWindow(#Win_Swatch,0,0,550,460,"Palette creation (Gimp, Mypaint, Krita, Animatoon...)",
269 | #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
270 |
271 | SetWindowColor(0,RGB(120,120,120))
272 | i = 5
273 | column = SwatchColor(swatchId)\column
274 | ; butons
275 | w1 = 80 ; size
276 | xb = WindowWidth(#Win_Swatch) - w1 - 10 ; x
277 |
278 | If StringGadget(#G_WinSwatchName,10,i,150,20,SwatchColor(swatchId)\name$) : EndIf
279 | GadgetToolTip(#G_WinSwatchName, "Swatch global name")
280 | If SpinGadget(#G_WinSwatchNbCol,170,i,40,20,1,64,#PB_Spin_Numeric) : EndIf
281 | SetGadgetState(#G_WinSwatchNbCol,column)
282 | i +25
283 | GadgetToolTip(#G_WinSwatchNbCol, "Number of Columns for the swatch")
284 |
285 | If ScrollAreaGadget(#G_WinSwatchScroll, 10,i,xb-20,400,xb-20-25,400)
286 | SetGadgetColor(#G_WinSwatchScroll,#PB_Gadget_BackColor,RGB(150,150,150))
287 | If CanvasGadget(#G_WinSwatchCanvas,0,0,xb-20,400) : EndIf
288 | i + 405
289 | CloseGadgetList()
290 | EndIf
291 |
292 | If StringGadget(#G_WinSwatchNameSwatch,10,i,150,20,"Swatch name") : EndIf
293 |
294 | i = 5
295 | If ButtonGadget(#G_WinSwatchNew,xb,i,w1,20,"New") : i + 25 : EndIf
296 | If ButtonGadget(#G_WinSwatchOpen,xb,i,w1,20,"Open") : i + 25 : EndIf
297 | If ButtonGadget(#G_WinSwatchMerge,xb,i,w1,20,"Merge") : i + 25 : EndIf
298 | If ButtonGadget(#G_WinSwatchFromImg,xb,i,w1,20,"From Image") : i + 25 : EndIf
299 | If ButtonGadget(#G_WinSwatchSave,xb,i,w1,20,"Save") : i + 35 : EndIf
300 | If ButtonGadget(#G_WinSwatchInsert,xb,i,w1,20,"Insert") : i + 25 : EndIf
301 | If ButtonGadget(#G_WinSwatchAdd,xb,i,w1,20,"Add") : i + 25 : EndIf
302 | If ButtonGadget(#G_WinSwatchDel,xb,i,w1,20,"Delete") : i + 25 : EndIf
303 |
304 | SwatchUpdatePropCanvas()
305 |
306 | Repeat
307 |
308 | Event = WaitWindowEvent(1)
309 | EventType = EventType()
310 |
311 | Select event
312 |
313 | Case #PB_Event_Gadget
314 |
315 | Select EventGadget()
316 |
317 | Case #G_WinSwatchCanvas
318 | u = Round((GadgetWidth(#G_WinSwatchCanvas)-25) / SwatchColor(swatchId)\column , #PB_Round_Down)
319 | x = Round(GetGadgetAttribute(#G_WinSwatchCanvas, #PB_Canvas_MouseX)/u,#PB_Round_Down)
320 | y = Round(GetGadgetAttribute(#G_WinSwatchCanvas, #PB_Canvas_MouseY)/u,#PB_Round_Down)
321 | id = x +y* SwatchColor(swatchId)\column
322 |
323 | If EventType = #PB_EventType_LeftButtonDown
324 | If StartDrawing(CanvasOutput(#G_WinSwatchCanvas))
325 | If id <= ArraySize(SwatchColor(swatchId)\swatch())-1
326 | SetGadgetText(#G_WinSwatchNameSwatch,SwatchColor(swatchId)\swatch(id)\name$)
327 | EndIf
328 | StopDrawing()
329 | EndIf
330 | SwatchUpdatePropCanvas(x,y,1)
331 | ElseIf EventType = #PB_EventType_LeftDoubleClick
332 | Color = ColorRequester(SwatchColor(swatchId)\swatch(id)\Color)
333 | SwatchColor(swatchId)\swatch(id)\col\R = Red(color)
334 | SwatchColor(swatchId)\swatch(id)\col\G = Green(color)
335 | SwatchColor(swatchId)\swatch(id)\col\B = Blue(color)
336 | SwatchColor(swatchId)\swatch(id)\Color = color
337 | SwatchUpdatePropCanvas(x,y,1)
338 | EndIf
339 |
340 | Case #G_WinSwatchNbCol
341 | SwatchColor(swatchId)\column = GetGadgetState(#G_WinSwatchNbCol)
342 | SwatchUpdatePropCanvas()
343 |
344 | Case #G_WinSwatchName
345 | SwatchColor(swatchId)\Name$ = GetGadgetText(#G_WinSwatchName)
346 |
347 | Case #G_WinSwatchNameSwatch
348 | SwatchColor(swatchId)\Swatch(id)\name$ = GetGadgetText(#G_WinSwatchNameSwatch)
349 |
350 | Case #G_WinSwatchMerge
351 | SwatchOpen(1)
352 |
353 | Case #G_WinSwatchNew
354 | ReDim SwatchColor(swatchId)\Swatch(0)
355 | SwatchUpdatePropCanvas()
356 |
357 | Case #G_WinSwatchFromImg
358 | SwatchCreateFromImage()
359 |
360 | Case #G_WinSwatchSave
361 | SwatchSave(1)
362 |
363 | Case #G_WinSwatchAdd
364 | color = ColorRequester()
365 | Name$ = InputRequester("Name","Name of the new swatch : ","Untitled")
366 | AddSwatchColor(Red(color),Green(color),Blue(color),Name$)
367 | SwatchUpdatePropCanvas()
368 |
369 | Case #G_WinSwatchOpen
370 | SwatchOpen(1)
371 |
372 | Case #G_WinSwatchMerge
373 | SwatchOpen()
374 |
375 | EndSelect
376 |
377 | EndSelect
378 |
379 | Until event = #PB_Event_CloseWindow
380 |
381 | EndIf
382 |
--------------------------------------------------------------------------------
/windows_gadgets/WindowCreator.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blendman/Purebasic/611a0decccd066caf176697452e05767a4a9b976/windows_gadgets/WindowCreator.pb
--------------------------------------------------------------------------------